public class JMapViewer extends JPanel implements TileLoaderListener
Modifier and Type | Class and Description |
---|---|
static class |
JMapViewer.ZOOM_BUTTON_STYLE |
JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected AttributionSupport |
attribution |
protected Point |
center
x- and y-position of the center of this map-panel on the world map
denoted in screen pixel regarding the current zoom level.
|
protected EventListenerList |
listenerList |
protected List<MapMarker> |
mapMarkerList |
protected boolean |
mapMarkersVisible |
protected List<MapPolygon> |
mapPolygonList |
protected boolean |
mapPolygonsVisible |
protected List<MapRectangle> |
mapRectangleList |
protected boolean |
mapRectanglesVisible |
static int |
MAX_ZOOM |
static int |
MIN_ZOOM |
protected static Point[] |
move
Vectors for clock-wise tile painting
|
protected boolean |
scrollWrapEnabled |
private static long |
serialVersionUID |
protected TileController |
tileController |
protected boolean |
tileGridVisible |
private TileSource |
tileSource |
protected int |
zoom
Current zoom level
|
protected JMapViewer.ZOOM_BUTTON_STYLE |
zoomButtonStyle |
protected JButton |
zoomInButton |
protected JButton |
zoomOutButton |
protected JSlider |
zoomSlider |
TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JMapViewer()
Creates a standard
JMapViewer instance that can be controlled via
mouse: hold right mouse button for moving, double click left mouse button
or use mouse wheel for zooming. |
JMapViewer(TileCache tileCache,
int downloadThreadCount) |
Modifier and Type | Method and Description |
---|---|
void |
addJMVListener(JMapViewerEventListener listener) |
void |
addMapMarker(MapMarker marker) |
void |
addMapPolygon(MapPolygon polygon) |
void |
addMapRectangle(MapRectangle rectangle) |
(package private) void |
fireJMVEvent(JMVCommandEvent evt)
Send an update to all objects registered with viewer
|
AttributionSupport |
getAttribution() |
Point |
getCenter() |
Integer |
getLatOffset(double lat,
double offset,
boolean checkOutside)
Calculates the position on the map of a given coordinate
|
List<MapMarker> |
getMapMarkerList() |
boolean |
getMapMarkersVisible() |
List<MapPolygon> |
getMapPolygonList() |
Point |
getMapPosition(Coordinate coord)
Calculates the position on the map of a given coordinate
|
Point |
getMapPosition(double lat,
double lon)
Calculates the position on the map of a given coordinate
|
Point |
getMapPosition(double lat,
double lon,
boolean checkOutside)
Calculates the position on the map of a given coordinate
|
Point |
getMapPosition(ICoordinate coord,
boolean checkOutside)
Calculates the position on the map of a given coordinate
|
List<MapRectangle> |
getMapRectangleList() |
double |
getMeterPerPixel()
Gets the meter per pixel.
|
Coordinate |
getPosition()
Calculates the latitude/longitude coordinate of the center of the
currently displayed map area.
|
Coordinate |
getPosition(int mapPointX,
int mapPointY)
Converts the relative pixel coordinate (regarding the top left corner of
the displayed map) into a latitude / longitude coordinate
|
Coordinate |
getPosition(Point mapPoint)
Converts the relative pixel coordinate (regarding the top left corner of
the displayed map) into a latitude / longitude coordinate
|
Integer |
getRadius(MapMarker marker,
Point p)
Calculates the position on the map of a given coordinate
|
TileCache |
getTileCache()
Return tile information caching class
|
TileController |
getTileController() |
String |
getToolTipText(MouseEvent event) |
int |
getZoom() |
JMapViewer.ZOOM_BUTTON_STYLE |
getZoomButtonStyle() |
boolean |
getZoomContolsVisible() |
protected void |
initializeZoomSlider() |
boolean |
isMapPolygonsVisible() |
boolean |
isMapRectanglesVisible() |
boolean |
isScrollWrapEnabled() |
boolean |
isTileGridVisible() |
void |
moveMap(int x,
int y)
Moves the visible map pane.
|
protected void |
paintComponent(Graphics g) |
protected void |
paintMarker(Graphics g,
MapMarker marker)
Paint a single marker.
|
protected void |
paintPolygon(Graphics g,
MapPolygon polygon)
Paint a single polygon.
|
protected void |
paintRectangle(Graphics g,
MapRectangle rectangle)
Paint a single rectangle.
|
void |
removeAllMapMarkers() |
void |
removeAllMapPolygons() |
void |
removeAllMapRectangles() |
void |
removeJMVListener(JMapViewerEventListener listener) |
void |
removeMapMarker(MapMarker marker) |
void |
removeMapPolygon(MapPolygon polygon) |
void |
removeMapRectangle(MapRectangle rectangle) |
void |
setCenter(Point center) |
void |
setDisplayPosition(int x,
int y,
int zoom) |
void |
setDisplayPosition(Point mapPoint,
int x,
int y,
int zoom) |
void |
setDisplayPositionByLatLon(double lat,
double lon,
int zoom)
Changes the map pane so that it is centered on the specified coordinate
at the given zoom level.
|
void |
setDisplayPositionByLatLon(Point mapPoint,
double lat,
double lon,
int zoom)
Changes the map pane so that the specified coordinate at the given zoom
level is displayed on the map at the screen coordinate
mapPoint . |
void |
setDisplayToFitMapElements(boolean markers,
boolean rectangles,
boolean polygons)
Sets the displayed map pane and zoom level so that all chosen map elements are
visible.
|
void |
setDisplayToFitMapMarkers()
Sets the displayed map pane and zoom level so that all map markers are
visible.
|
void |
setDisplayToFitMapPolygons()
Sets the displayed map pane and zoom level so that all map polygons are
visible.
|
void |
setDisplayToFitMapRectangles()
Sets the displayed map pane and zoom level so that all map rectangles are
visible.
|
void |
setMapMarkerList(List<MapMarker> mapMarkerList) |
void |
setMapMarkerVisible(boolean mapMarkersVisible)
Enables or disables painting of the
MapMarker |
void |
setMapPolygonList(List<MapPolygon> mapPolygonList) |
void |
setMapPolygonsVisible(boolean mapPolygonsVisible)
Enables or disables painting of the
MapPolygon |
void |
setMapRectangleList(List<MapRectangle> mapRectangleList) |
void |
setMapRectanglesVisible(boolean mapRectanglesVisible)
Enables or disables painting of the
MapRectangle |
void |
setScrollWrapEnabled(boolean scrollWrapEnabled) |
void |
setTileGridVisible(boolean tileGridVisible) |
void |
setTileLoader(TileLoader loader) |
void |
setTileSource(TileSource tileSource) |
void |
setZoom(int zoom)
Set the zoom level
|
void |
setZoom(int zoom,
Point mapPoint)
Set the zoom level and center point for display
|
void |
setZoomButtonStyle(JMapViewer.ZOOM_BUTTON_STYLE style) |
void |
setZoomContolsVisible(boolean visible) |
void |
tileLoadingFinished(Tile tile,
boolean success)
Will be called if a new
Tile has been loaded successfully. |
protected void |
zoomChanged(int oldZoom)
Every time the zoom level changes this method is called.
|
void |
zoomIn()
Increases the current zoom level by one
|
void |
zoomIn(Point mapPoint)
Increases the current zoom level by one
|
void |
zoomOut()
Decreases the current zoom level by one
|
void |
zoomOut(Point mapPoint)
Decreases the current zoom level by one
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
private static final long serialVersionUID
public static final int MAX_ZOOM
public static final int MIN_ZOOM
protected List<MapMarker> mapMarkerList
protected List<MapRectangle> mapRectangleList
protected List<MapPolygon> mapPolygonList
protected boolean mapMarkersVisible
protected boolean mapRectanglesVisible
protected boolean mapPolygonsVisible
protected boolean tileGridVisible
protected boolean scrollWrapEnabled
protected TileController tileController
protected Point center
protected int zoom
protected JSlider zoomSlider
protected JButton zoomInButton
protected JButton zoomOutButton
protected JMapViewer.ZOOM_BUTTON_STYLE zoomButtonStyle
private TileSource tileSource
protected AttributionSupport attribution
protected EventListenerList listenerList
public JMapViewer()
JMapViewer
instance that can be controlled via
mouse: hold right mouse button for moving, double click left mouse button
or use mouse wheel for zooming. Loaded tiles are stored the
MemoryTileCache
and the tile loader uses 4 parallel threads for
retrieving the tiles.public JMapViewer(TileCache tileCache, int downloadThreadCount)
public String getToolTipText(MouseEvent event)
getToolTipText
in class JComponent
protected void initializeZoomSlider()
public void setDisplayPositionByLatLon(double lat, double lon, int zoom)
public void setDisplayPositionByLatLon(Point mapPoint, double lat, double lon, int zoom)
mapPoint
.mapPoint
- point on the map denoted in pixels where the coordinate should
be setlat
- latitude of the specified coordinatelon
- longitude of the specified coordinatezoom
- MIN_ZOOM
<= zoom level <=
TileSource.getMaxZoom()
public void setDisplayPosition(int x, int y, int zoom)
public void setDisplayPosition(Point mapPoint, int x, int y, int zoom)
public void setDisplayToFitMapElements(boolean markers, boolean rectangles, boolean polygons)
public void setDisplayToFitMapMarkers()
public void setDisplayToFitMapRectangles()
public void setDisplayToFitMapPolygons()
public Coordinate getPosition()
public Coordinate getPosition(Point mapPoint)
mapPoint
- relative pixel coordinate regarding the top left corner of the
displayed mappublic Coordinate getPosition(int mapPointX, int mapPointY)
mapPointX
- mapPointY
- public Point getMapPosition(double lat, double lon, boolean checkOutside)
lat
- lon
- checkOutside
- null
if the point is not visible
and checkOutside set to true
public Integer getLatOffset(double lat, double offset, boolean checkOutside)
lat
- Latitudeoffset
- Offset respect LatitudecheckOutside
- public Point getMapPosition(double lat, double lon)
lat
- lon
- null
if the point is not visiblepublic Integer getRadius(MapMarker marker, Point p)
marker
- MapMarker object that define the x,y coordinatepublic Point getMapPosition(Coordinate coord)
coord
- null
if the point is not visiblepublic Point getMapPosition(ICoordinate coord, boolean checkOutside)
coord
- null
if the point is not visible
and checkOutside set to true
public double getMeterPerPixel()
protected void paintComponent(Graphics g)
paintComponent
in class JComponent
protected void paintMarker(Graphics g, MapMarker marker)
protected void paintRectangle(Graphics g, MapRectangle rectangle)
protected void paintPolygon(Graphics g, MapPolygon polygon)
public void moveMap(int x, int y)
x
- horizontal movement in pixel.y
- vertical movement in pixelpublic int getZoom()
public void zoomIn()
public void zoomOut()
public void zoomOut(Point mapPoint)
mapPoint
- point to choose as center for new zoom levelpublic void setZoom(int zoom, Point mapPoint)
zoom
- new zoom levelmapPoint
- point to choose as center for new zoom levelpublic void setZoom(int zoom)
zoom
- new zoom levelprotected void zoomChanged(int oldZoom)
getZoom()
.oldZoom
- the previous zoom levelpublic boolean isTileGridVisible()
public void setTileGridVisible(boolean tileGridVisible)
public boolean getMapMarkersVisible()
public void setMapMarkerVisible(boolean mapMarkersVisible)
MapMarker
mapMarkersVisible
- addMapMarker(MapMarker)
,
getMapMarkerList()
public void setMapMarkerList(List<MapMarker> mapMarkerList)
public List<MapMarker> getMapMarkerList()
public void setMapRectangleList(List<MapRectangle> mapRectangleList)
public List<MapRectangle> getMapRectangleList()
public void setMapPolygonList(List<MapPolygon> mapPolygonList)
public List<MapPolygon> getMapPolygonList()
public void addMapMarker(MapMarker marker)
public void removeMapMarker(MapMarker marker)
public void removeAllMapMarkers()
public void addMapRectangle(MapRectangle rectangle)
public void removeMapRectangle(MapRectangle rectangle)
public void removeAllMapRectangles()
public void addMapPolygon(MapPolygon polygon)
public void removeMapPolygon(MapPolygon polygon)
public void removeAllMapPolygons()
public void setZoomContolsVisible(boolean visible)
public boolean getZoomContolsVisible()
public void setTileSource(TileSource tileSource)
public void tileLoadingFinished(Tile tile, boolean success)
TileLoaderListener
Tile
has been loaded successfully.
Loaded can mean downloaded or loaded from file cache.tileLoadingFinished
in interface TileLoaderListener
public boolean isMapRectanglesVisible()
public void setMapRectanglesVisible(boolean mapRectanglesVisible)
MapRectangle
mapRectanglesVisible
- addMapRectangle(MapRectangle)
,
getMapRectangleList()
public boolean isMapPolygonsVisible()
public void setMapPolygonsVisible(boolean mapPolygonsVisible)
MapPolygon
mapPolygonsVisible
- addMapPolygon(MapPolygon)
,
getMapPolygonList()
public boolean isScrollWrapEnabled()
public void setScrollWrapEnabled(boolean scrollWrapEnabled)
public JMapViewer.ZOOM_BUTTON_STYLE getZoomButtonStyle()
public void setZoomButtonStyle(JMapViewer.ZOOM_BUTTON_STYLE style)
public TileController getTileController()
public TileCache getTileCache()
getTileCache
in interface TileLoaderListener
TileLoaderListener.getTileCache()
public void setTileLoader(TileLoader loader)
public AttributionSupport getAttribution()
public void addJMVListener(JMapViewerEventListener listener)
listener
- listener to setpublic void removeJMVListener(JMapViewerEventListener listener)
listener
- listener to removevoid fireJMVEvent(JMVCommandEvent evt)
evt
- event to dispatch