|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
schmitzm.swing.JPanel
skrueger.geotools.XMapPane
public class XMapPane
The XMapPane
class uses a Geotools GTRenderer
to paint up to
two MapContext
s: a "local" MapContext
and a "background"
MapContext
. The idea is, that rendering a background layer made up of
e.g. OSM data, may take much longer than rendering local data.
Every MapContext
is rendered on a Thread
of it's own.
Starting/ cancelling these threads is done by the RenderingExecutor
.
While the renderers are rending the map, a
The XMapPane
is based on schmitzm JPanel
, so
JPanel.print(Graphics)
will automatically set the background of components
to pure white.
The XMapPane has a MouseListener
that manages zooming.
A logo/icon to float in the lower left corner may be set with
setMapImage(BufferedImage)
- an extension of {@link XMapPane} that supports
selecting features.
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JPanel |
---|
JPanel.AccessibleJPanel |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected skrueger.geotools.RenderingExecutor |
bgExecuter
This RenderingExecutor manages the creation and cancellation of
up to one Thread for rendering the bgContext . |
protected MapLayerListener |
bgMapLayerListener
Listens to each layer in the local MapContext for changes and
triggers repaints. |
static int |
DEFAULT_RESIZING_PAINT_DELAY
Default delay (milliseconds) before the map will be redrawn when resizing the pane. |
static int |
INITIAL_REPAINT_DELAY
The initial delay in milliseconds until the finalImage is
updated the first time. |
protected LabelCache |
labelCache
|
protected MapLayerListener |
localMapLayerListener
Listens to each layer in the local MapContext for changes and
triggers repaints. |
protected Envelope |
mapArea
the area of the map to draw |
protected boolean |
mapImageInvalid
A flag indicating that the shown image is invalid and needs to be re-rendered. |
protected HashMap<MapLayer,Boolean> |
mapLayerSelectable
Holds a flag for each layer, whether it is regarded or ignored on #SELECT_TOP , #SELECT_ALL and #SELECT_ONE_FROM_TOP
actions. |
protected Vector<JMapPaneListener> |
mapPaneListeners
List of listeners of this XMapPane |
static int |
NONE
Flag for no-tool. |
protected Envelope |
oldMapArea
We store the old mapArea for a moment to use it for the "quick scaled preview" in case of ZoomOut |
protected AffineTransform |
oldScreenToWorld
We store the old transform for a moment to use it for the "quick scaled preview" in case of ZoomIn |
protected boolean |
paneResized
A flag indicating, that the image size has changed and the buffered images are not big enough any more |
protected ArrayList<Exception> |
renderingErrors
Is set if a renderer has an error |
static int |
REPEATING_REPAINT_DELAY
While the bgExecuter and localExecuter are rendering,
the repaintTimer is regularly updating the finalImage
with previews. |
protected AffineTransform |
screenToWorld
Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten (lat/lon) |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
XMapPane()
|
|
XMapPane(MapContext localContext_,
Map<Object,Object> rendererHints)
full constructor extending JPanel |
Method Summary | |
---|---|
void |
addMapPaneListener(JMapPaneListener l)
Fuegt der Map einen Listener hinzu. |
ReferencedEnvelope |
bestAllowedMapArea(ReferencedEnvelope env)
Korrigiert den Envelope aka mapArea auf die beste
erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten
werden, FALLS der uebergeben Envelope nicht schon gueltig sein sollte. |
void |
blink(
Makes the given FeatureCollection bink in the map for a moment |
void |
configureMouse(MouseInputType type,
XMapPaneAction action)
|
void |
dispose()
Should be called when the JMapPane is not needed no more to help
the GarbageCollector
Removes all JMapPaneListener s that are registered |
protected void |
drawRectangle(Graphics graphics,
Point startPos,
Point e)
Draws a rectangle in XOR mode from the origin at #startPos to the
given point. |
protected void |
drawRectangle(Graphics graphics,
Point startPos,
Point e,
Color color,
boolean fill)
Draws a rectangle in XOR mode from the origin at #startPos to the
given point. |
protected boolean |
drawScaledPreviewImage_Zoom(Graphics2D graphics)
Diretly paints scaled preview into the SelectableXMapPane . |
MapContext |
getBgContext()
|
double |
getDefaultMaxMapExtendMode()
If maxExtend is null the following rules are used
to create a default maximum. |
Point |
getImageOrigin()
|
GTRenderer |
getLocalRenderer()
|
ReferencedEnvelope |
getMapArea()
Returns a copy of the mapArea |
Color |
getMapBackgroundColor()
Returns the background Color of the map pane. |
MapContext |
getMapContext()
|
static DirectPosition2D |
getMapCoordinatesFromEvent(MouseEvent e)
Konvertiert die Maus-Koordinaten (relativ zum JMapPane ) in
Karten-Koordinaten. |
BufferedImage |
getMapImage()
Get the BufferedImage to use as a flaoting icon in the lower right corner. |
Envelope |
getMaxExtend()
Returns the evelope of the viewable area. |
Double |
getMaxZoomScale()
Retuns the maximum allowed zoom scale. |
Double |
getMinZoomScale()
Retuns the minimum allowed zoom scale. |
Map<Object,Object> |
getRendererHints()
|
AffineTransform |
getScreenToWorld()
Liefert eine affine Transformation, um von den Fenster-Koordinaten in die Karten-Koordinaten (Lat/Lon) umzurechnen. |
XMapPaneTool |
getTool()
|
AffineTransform |
getWorldToScreenTransform()
|
boolean |
isMapLayerSelectable(MapLayer layer)
Returns whether a layer is regarded or ignored on #SELECT_TOP ,
#SELECT_ALL and #SELECT_ONE_FROM_TOP actions. |
boolean |
isShowExceptions()
Shall exceptions be reported in the mappane? |
boolean |
isWellDefined()
Return true if a CRS and a mapArea are set and the
XMapPane is visible and has bounds set. |
void |
onRenderingCancelled()
Called by the RenderingExecutor when rendering was cancelled. |
void |
onRenderingCompleted(long l)
Called by the RenderingExecutor when rendering has been
completed. |
void |
onRenderingFailed(Exception renderingError)
Called by the XMapPane.RenderingTask when rendering failed. |
protected void |
paintComponent(Graphics g)
|
void |
pan(int dX,
int dY)
Usually called from XMapPaneAction_Pan to pan the image. |
void |
refresh()
Triggers to repaint (fast) and re-render (slow) the JMapPane. |
void |
removeMapPaneListener(JMapPaneListener l)
Entfernt einen Listener von der Map. |
void |
setAntiAliasing(boolean aa)
Aktiviert oder deaktiviert das AntiAliasing for diese SelectableXMapPane . |
void |
setBgContext(MapContext context)
|
void |
setBorder(Border b)
|
void |
setDefaultMaxMapExtendMode(double defaultMaxMapExtendMode)
If maxExtend is null the following rules are used
to create a default maximum. |
void |
setJava2dHints(RenderingHints java2dHints)
|
void |
setLocalContext(MapContext context)
|
boolean |
setMapArea(Envelope newMapArea)
Set the new map area. |
boolean |
setMapArea(ReferencedEnvelope newMapArea)
Set the new map area. |
void |
setMapBackgroundColor(Color bgColor)
Set the background color of the map. |
void |
setMapImage(BufferedImage mapImage)
Set the BufferedImage to use as a flaoting icon in the lower right corner |
void |
setMapLayerSelectable(MapLayer layer,
Boolean selectable)
Sets whether a layer is regarded or ignored on #SELECT_TOP ,
#SELECT_ALL and #SELECT_ONE_FROM_TOP actions. |
void |
setMaxExtend(Envelope maxExtend)
Defines an evelope of the viwable area. |
void |
setMaxZoomScale(Double maxZoomScale)
Set the maximum allowed zoom scale. |
void |
setMinZoomScale(Double minZoomScale)
Set the minimum (nearest) allowed zoom scale. |
void |
setPainting(boolean b)
If true , allow the XMapPane to process #repaint()
requests. |
void |
setShowExceptions(boolean showExceptions)
Shall non-fatal rendering exceptions be reported in the mappane or be dropped quitely. |
void |
setTool(XMapPaneTool tool)
Configure the XMapPaneTool that active on the map. |
Point2D |
tranformGeoToWindow(double x,
double y)
Transformiert einen Geo-Koordinate in eine Fenster-Koordinaten. |
Envelope |
tranformGeoToWindow(double ox,
double oy,
double px,
double py)
Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten. |
Envelope |
tranformWindowToGeo(int ox,
int oy,
int px,
int py)
Transformiert einen Fenster-Koordinaten-Bereich in Geo-Koordinaten. |
void |
updateCursor()
Will update the cursor. |
protected Image |
updateFinalImage()
The renderers are all rendering into their own Image s. |
void |
zoomTo(
Sets the mapArea to best possibly present the given features. |
void |
zoomTo(Point center,
Double zoomFaktor)
Zooms towards a point. |
void |
zoomToLayer(MapLayer layer)
Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
void |
zoomToLayerIdxReverse(int index)
Zooms the SelectableXMapPane to the Envelope of the
selected layer. |
Methods inherited from class schmitzm.swing.JPanel |
---|
print, setBackground, setEnabled |
Methods inherited from class javax.swing.JPanel |
---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int INITIAL_REPAINT_DELAY
finalImage
is
updated the first time.
public static final int REPEATING_REPAINT_DELAY
bgExecuter
and localExecuter
are rendering,
the repaintTimer
is regularly updating the finalImage
with previews.
public static final int DEFAULT_RESIZING_PAINT_DELAY
resizeTimer
,
Constant Field Valuespublic static final int NONE
protected skrueger.geotools.RenderingExecutor bgExecuter
RenderingExecutor
manages the creation and cancellation of
up to one Thread
for rendering the bgContext
.
protected MapLayerListener bgMapLayerListener
MapContext
for changes and
triggers repaints.
protected LabelCache labelCache
protected MapLayerListener localMapLayerListener
MapContext
for changes and
triggers repaints. We don't have to listen layerChanged, because that is
already done in localContextListener
protected Envelope mapArea
protected boolean mapImageInvalid
protected final HashMap<MapLayer,Boolean> mapLayerSelectable
#SELECT_TOP
, #SELECT_ALL
and #SELECT_ONE_FROM_TOP
actions.
protected Vector<JMapPaneListener> mapPaneListeners
XMapPane
protected Envelope oldMapArea
protected AffineTransform oldScreenToWorld
protected boolean paneResized
protected AffineTransform screenToWorld
protected ArrayList<Exception> renderingErrors
Constructor Detail |
---|
public XMapPane()
public XMapPane(MapContext localContext_, Map<Object,Object> rendererHints)
rendererHints
- may be null
. Otherwise a Map
of RenderingHints
to override the default
from GTUtil.getDefaultGTRendererHints(GTRenderer)
localContext
- The main MapContext
to use. If null
, an
empty DefaultMapContext
will be created.Method Detail |
---|
public XMapPaneTool getTool()
public static DirectPosition2D getMapCoordinatesFromEvent(MouseEvent e)
JMapPane
) in
Karten-Koordinaten.
e
- Maus-Ereignispublic void addMapPaneListener(JMapPaneListener l)
l
- neuer Listenerpublic ReferencedEnvelope bestAllowedMapArea(ReferencedEnvelope env)
Envelope
aka mapArea
auf die beste
erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten
werden, FALLS der uebergeben Envelope nicht schon gueltig sein sollte.
public void dispose()
JMapPane
is not needed no more to help
the GarbageCollector
Removes all JMapPaneListener
s that are registered
protected void drawRectangle(Graphics graphics, Point startPos, Point e)
#startPos
to the
given point. All in screen coordinates.
protected void drawRectangle(Graphics graphics, Point startPos, Point e, Color color, boolean fill)
#startPos
to the
given point. All in screen coordinates.
protected boolean drawScaledPreviewImage_Zoom(Graphics2D graphics)
SelectableXMapPane
. Used
to give the user something to look at while we are rendering. Method
should be called after setMapArea(Envelope)
has been set to the
new mapArea and transform has been reset.
g
- Graphics2D to paint the preview intopublic MapContext getBgContext()
public MapContext getMapContext()
public ReferencedEnvelope getMapArea()
public Color getMapBackgroundColor()
Color
of the map pane. If not set, the
methods looks for a parent component and will use its background color.
If no parent component is available, WHITE is returned.
public BufferedImage getMapImage()
null
if the feature is deactivated.public Envelope getMaxExtend()
null
via setMaxExtend(Envelope)
, it tries to return
quickly the context's bounds. It it takes to long to determine the
context bounds, null
is returned.
maxExtend
- null
to not have this restriction.public Double getMaxZoomScale()
Double
.MIN_VALUE
public Double getMinZoomScale()
Double
.MAX_VALUE
public Map<Object,Object> getRendererHints()
public AffineTransform getScreenToWorld()
null
wenn
noch keine Karte angezeigt wirdpublic AffineTransform getWorldToScreenTransform()
public boolean isMapLayerSelectable(MapLayer layer)
#SELECT_TOP
,
#SELECT_ALL
and #SELECT_ONE_FROM_TOP
actions. Returns
true
if the selectability has not been defined.
layer
- a layerpublic boolean isWellDefined()
true
if a CRS and a mapArea
are set and the
XMapPane
is visible and has bounds set.
public void pan(int dX, int dY)
XMapPaneAction_Pan
to pan the image.
startPos
- in screen coordinateslastPos
- in screen coordinatespublic void onRenderingCancelled()
RenderingExecutor
when rendering was cancelled.
public void onRenderingCompleted(long l)
RenderingExecutor
when rendering has been
completed.
l
- long ms the rendering tookpublic void onRenderingFailed(Exception renderingError)
MapPaneEvent.Type.RENDERING_STOPPED
to listeners.
renderingError
- The error that occured during renderingMapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
protected void paintComponent(Graphics g)
paintComponent
in class JComponent
public void removeMapPaneListener(JMapPaneListener l)
l
- zu entfernender Listenerpublic void setBgContext(MapContext context)
public void setJava2dHints(RenderingHints java2dHints)
public void setLocalContext(MapContext context)
public void setBorder(Border b)
setBorder
in class JComponent
public void refresh()
public boolean setMapArea(Envelope newMapArea)
newMapArea
-
true
if the mapArea has been changed and a repaint
has been triggered.public boolean setMapArea(ReferencedEnvelope newMapArea)
newMapArea
-
true
if the mapArea has been changed and a repaint
has been triggered.public void setMapBackgroundColor(Color bgColor)
if
- null
, white is used.public void setMapImage(BufferedImage mapImage)
mapImageIcon
- null
is allowed and deactivates this icon.public void setMapLayerSelectable(MapLayer layer, Boolean selectable)
#SELECT_TOP
,
#SELECT_ALL
and #SELECT_ONE_FROM_TOP
actions.
layer
- a layerselectable
- if false
the layer is ignored during the upper
mentioned actions. If null
, the default (true)
will be used.public void setMaxExtend(Envelope maxExtend)
maxExtend
- null
to not have this restriction.public void setMaxZoomScale(Double maxZoomScale)
null
is passed, Double.MINVALUE are used which
mean there is no restriction.
public void setMinZoomScale(Double minZoomScale)
null
is passed, Double.MAXVALUE are
used which mean there is no restriction.
public void setPainting(boolean b)
true
, allow the XMapPane
to process #repaint()
requests. Otherwise the map will not paint anything and not start any
rendering Thread
s.
public void configureMouse(MouseInputType type, XMapPaneAction action)
public void setTool(XMapPaneTool tool)
XMapPaneTool
that active on the map. Passing
null
will set the NO_ACTION tool.
public Envelope tranformGeoToWindow(double ox, double oy, double px, double py)
ox
- X-Koordinate der VON-Positionoy
- Y-Koordinate der VON-Positionpx
- X-Koordinate der BIS-Positionpy
- Y-Koordinate der BIS-Positionpublic Point2D tranformGeoToWindow(double x, double y)
x
- X-Koordinate der VON-Positiony
- Y-Koordinate der VON-Positionpublic Envelope tranformWindowToGeo(int ox, int oy, int px, int py)
ox
- X-Koordinate der VON-Positionoy
- Y-Koordinate der VON-Positionpx
- X-Koordinate der BIS-Positionpy
- Y-Koordinate der BIS-Positionpublic void updateCursor()
repaintTimer
protected Image updateFinalImage()
Image
s. This
method combines all images to one finalImage
. The
repaintTimer
is calling this method regularely to update the
finalImage
even if the renderers are still working.
public void zoomTo(features)
mapArea
to best possibly present the given features. If
only one single point is given, the window is moved over the point.
features
- if null
or size==0, the function doesn nothing.public void zoomTo(Point center, Double zoomFaktor)
center
- position in window coordinateszoomFaktor
- > 1 for zoom out, < 1 for zoom in. Default is .5public void setShowExceptions(boolean showExceptions)
public boolean isShowExceptions()
public GTRenderer getLocalRenderer()
public void zoomToLayer(MapLayer layer)
null
uebergeben wird.
layer
- ein Layerpublic void zoomToLayerIdxReverse(int index)
SelectableXMapPane
to the Envelope
of the
selected layer. The layer is selected by the idx, counting from front to
back, like humans would expect in a JList
index
- Reverse index of the MapLayer
in the
MapContext
public void setAntiAliasing(boolean aa)
SelectableXMapPane
. AntiALiasing ist besonders fuer
Textbeschriftung sehr schoen, verbraucht aber auch mehr Performance.
public Point getImageOrigin()
public void setDefaultMaxMapExtendMode(double defaultMaxMapExtendMode)
maxExtend
is null
the following rules are used
to create a default maximum.
public double getDefaultMaxMapExtendMode()
maxExtend
is null
the following rules are used
to create a default maximum.
public void blink(features)
FeatureCollection
bink in the map for a moment
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |