Package nl.bebr.mapviewer.data
Class AbstractMapViewer<T,U extends Tile<T>>
- java.lang.Object
-
- nl.bebr.mapviewer.data.AbstractMapViewer<T,U>
-
-
Field Summary
Fields Modifier and Type Field Description protected floatpixelToMeterprotected longscaleValue
-
Constructor Summary
Constructors Constructor Description AbstractMapViewer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddRepaintCallback(RepaintCallback repaintCallback)AddRepaintCallbackto a list of callbacks, fired when repaint of a component and its subcomponents is neededintcalculateZoom(double x, double y)Calculates zoom level from selected areain the mapvoidcalculateZoomFrom(Set<GeoPosition> positions)Calculates a zoom level so that all points in the specified set will be visible on screen.Point2DconvertGeoPositionToPoint(GeoPosition pos)Converts the specified GeoPosition to a point in the JXMapViewer's local coordinate space.GeoPositionconvertPointToGeoPosition(Point2D pt)Converts the specified Point2D in the JXMapViewer's local coordinate space to a GeoPosition on the map.protected abstract voidfirePropertyChange(String name, Object oldValue, Object newValue)voidfireRepaintCallbacks()Method to fire allRepaintCallbacks.GeoPositiongetAddressLocation()Gets the current address location of the map.Point2DgetCenter()Gets center of the map in pixel coordinatesGeoPositiongetCenterPosition()A property indicating the center position of the mapprotected abstract intgetHeight()Gets height of mapViewer componentprotected abstract InsetsgetInsets()Gets insets of mapViewer componentfloatgetPixelToMeter()longgetScaleValue()TileFactory<T,U>getTileFactory()GetsTileFactoryRectanglegetViewportBounds()Gets bounds of componentprotected abstract intgetWidth()Gets width of mapViewer componentintgetZoom()Gets the current zoom levelbooleanisHorizontalWrapped()booleanisPanEnabled()A property indicating if the map should be pannable by the user using the mouse.booleanisRestrictOutsidePanning()booleanisZoomEnabled()A property indicating if the map should be zoomable by the user using the mouse wheel.voidrecenterToAddressLocation()Re-centers the map to have the current address location be at the center of the map, accounting for the map's width and height.voidremoveRepaintCallback(RepaintCallback repaintCallback)RemoveRepaintCallbackfrom a list of callbacksprotected abstract voidrepaint()Callback method to repaint mapViewer componentvoidsetAddressLocation(GeoPosition addressLocation)Gets the current address location of the mapvoidsetCenter(Point2D center)Sets the new center of the map in pixel coordinates.voidsetCenterPosition(GeoPosition geoPosition)Sets center position of the mapvoidsetHorizontalWrapped(boolean horizontalWrapped)voidsetPanEnabled(boolean panEnabled)A property indicating if the map should be pannable by the user using the mouse.voidsetRestrictOutsidePanning(boolean restrictOutsidePanning)voidsetTileFactory(TileFactory<T,U> factory)Set the current tile factoryvoidsetZoom(int zoom)Set zoom levelvoidsetZoomEnabled(boolean zoomEnabled)A property indicating if the map should be zoomable by the user using the mouse wheel.voidsetZoomFromGeoPosition(GeoPosition startPosition, GeoPosition endPosition)voidzoomToCoordinates(double startX, double startY, double endX, double endY)Zoom the map to show selected area in the map
-
-
-
Method Detail
-
getTileFactory
public TileFactory<T,U> getTileFactory()
GetsTileFactory- Returns:
-
setZoom
public void setZoom(int zoom)
Set zoom level- Parameters:
zoom-
-
getZoom
public int getZoom()
Gets the current zoom level- Returns:
- the current zoom level
-
getCenter
public Point2D getCenter()
Gets center of the map in pixel coordinates- Returns:
- center of the map in pixel coordinates
-
setCenter
public void setCenter(Point2D center)
Sets the new center of the map in pixel coordinates.- Parameters:
center- the new center of the map in pixel coordinates
-
getViewportBounds
public Rectangle getViewportBounds()
Gets bounds of component- Returns:
- bounds of component
-
setCenterPosition
public void setCenterPosition(GeoPosition geoPosition)
Sets center position of the map- Parameters:
geoPosition- center position of the map
-
getCenterPosition
public GeoPosition getCenterPosition()
A property indicating the center position of the map- Returns:
- the current center position
-
setTileFactory
public void setTileFactory(TileFactory<T,U> factory)
Set the current tile factory- Parameters:
factory- the new property value
-
getAddressLocation
public GeoPosition getAddressLocation()
Gets the current address location of the map. This property does not change when the user pans the map. This property is bound.- Returns:
- the current map location (address)
-
setAddressLocation
public void setAddressLocation(GeoPosition addressLocation)
Gets the current address location of the map- Parameters:
addressLocation- the new address location- See Also:
getAddressLocation()
-
recenterToAddressLocation
public void recenterToAddressLocation()
Re-centers the map to have the current address location be at the center of the map, accounting for the map's width and height.- See Also:
getAddressLocation()
-
calculateZoomFrom
public void calculateZoomFrom(Set<GeoPosition> positions)
Calculates a zoom level so that all points in the specified set will be visible on screen. This is useful if you have a bunch of points in an area like a city and you want to zoom out so that the entire city and it's points are visible without panning.- Parameters:
positions- A set of GeoPositions to calculate the new zoom from
-
isPanEnabled
public boolean isPanEnabled()
A property indicating if the map should be pannable by the user using the mouse.- Returns:
- property value
-
setPanEnabled
public void setPanEnabled(boolean panEnabled)
A property indicating if the map should be pannable by the user using the mouse.- Parameters:
panEnabled- new property value
-
isZoomEnabled
public boolean isZoomEnabled()
A property indicating if the map should be zoomable by the user using the mouse wheel.- Returns:
- the current property value
-
setZoomEnabled
public void setZoomEnabled(boolean zoomEnabled)
A property indicating if the map should be zoomable by the user using the mouse wheel.- Parameters:
zoomEnabled- the new value of the property
-
isRestrictOutsidePanning
public boolean isRestrictOutsidePanning()
-
setRestrictOutsidePanning
public void setRestrictOutsidePanning(boolean restrictOutsidePanning)
-
isHorizontalWrapped
public boolean isHorizontalWrapped()
-
setHorizontalWrapped
public void setHorizontalWrapped(boolean horizontalWrapped)
-
convertGeoPositionToPoint
public Point2D convertGeoPositionToPoint(GeoPosition pos)
Converts the specified GeoPosition to a point in the JXMapViewer's local coordinate space. This method is especially useful when drawing lat/long positions on the map.- Parameters:
pos- a GeoPosition on the map- Returns:
- the point in the local coordinate space of the map
-
convertPointToGeoPosition
public GeoPosition convertPointToGeoPosition(Point2D pt)
Converts the specified Point2D in the JXMapViewer's local coordinate space to a GeoPosition on the map. This method is especially useful for determining the GeoPosition under the mouse cursor.- Parameters:
pt- a point in the local coordinate space of the map- Returns:
- the point converted to a GeoPosition
-
calculateZoom
public int calculateZoom(double x, double y)Calculates zoom level from selected areain the map- Parameters:
x- width of the selected areay- height of the selected area- Returns:
- zoom level
-
zoomToCoordinates
public void zoomToCoordinates(double startX, double startY, double endX, double endY)Zoom the map to show selected area in the map- Parameters:
startX- x coordinate of area startstartY- y coordinate of area startendX- x coordinate of area endendY- x coordinate of area end
-
firePropertyChange
protected abstract void firePropertyChange(String name, Object oldValue, Object newValue)
-
getWidth
protected abstract int getWidth()
Gets width of mapViewer component- Returns:
-
getHeight
protected abstract int getHeight()
Gets height of mapViewer component- Returns:
-
getInsets
protected abstract Insets getInsets()
Gets insets of mapViewer component- Returns:
-
repaint
protected abstract void repaint()
Callback method to repaint mapViewer component
-
fireRepaintCallbacks
public void fireRepaintCallbacks()
Method to fire allRepaintCallbacks.
-
addRepaintCallback
public void addRepaintCallback(RepaintCallback repaintCallback)
AddRepaintCallbackto a list of callbacks, fired when repaint of a component and its subcomponents is needed- Parameters:
repaintCallback-
-
removeRepaintCallback
public void removeRepaintCallback(RepaintCallback repaintCallback)
RemoveRepaintCallbackfrom a list of callbacks- Parameters:
repaintCallback-
-
setZoomFromGeoPosition
public void setZoomFromGeoPosition(GeoPosition startPosition, GeoPosition endPosition)
-
getScaleValue
public long getScaleValue()
-
getPixelToMeter
public float getPixelToMeter()
-
-