Package org.mapsforge.map.model
Class MapViewPosition
- java.lang.Object
-
- org.mapsforge.map.model.common.Observable
-
- org.mapsforge.map.model.MapViewPosition
-
- All Implemented Interfaces:
ObservableInterface
,Persistable
,IMapViewPosition
public class MapViewPosition extends Observable implements IMapViewPosition, Persistable
-
-
Constructor Summary
Constructors Constructor Description MapViewPosition(DisplayModel displayModel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
animateTo(org.mapsforge.core.model.LatLong latLong)
Animate the map towards the given position.boolean
animationInProgress()
void
destroy()
Destroys the class.org.mapsforge.core.model.LatLong
getCenter()
Returns the current center position of the map.org.mapsforge.core.model.BoundingBox
getMapLimit()
org.mapsforge.core.model.MapPosition
getMapPosition()
Returns a newly instantiated object representing the current position and zoomlevel.org.mapsforge.core.model.LatLong
getPivot()
The pivot point is the point the map zooms around.org.mapsforge.core.model.Point
getPivotXY(byte zoomLevel)
The pivot point is the point the map zooms around.double
getScaleFactor()
Gets the current scale factor.byte
getZoomLevel()
byte
getZoomLevelMax()
byte
getZoomLevelMin()
void
init(PreferencesFacade preferencesFacade)
Initializes the class.void
moveCenter(double moveHorizontal, double moveVertical)
Animates the center position of the map by the given amount of pixels.void
moveCenter(double moveHorizontal, double moveVertical, boolean animated)
Moves the center position of the map by the given amount of pixels.void
moveCenterAndZoom(double moveHorizontal, double moveVertical, byte zoomLevelDiff)
Animates the center position of the map by the given amount of pixels.void
moveCenterAndZoom(double moveHorizontal, double moveVertical, byte zoomLevelDiff, boolean animated)
Moves the center position of the map by the given amount of pixels.void
save(PreferencesFacade preferencesFacade)
Saves the current state.void
setCenter(org.mapsforge.core.model.LatLong latLong)
Sets the new center position of the map.void
setMapLimit(org.mapsforge.core.model.BoundingBox mapLimit)
Sets the new limit of the map (might be null).void
setMapPosition(org.mapsforge.core.model.MapPosition mapPosition)
Sets the new center position and zoom level of the map.void
setMapPosition(org.mapsforge.core.model.MapPosition mapPosition, boolean animated)
Sets the new center position and zoom level of the map.void
setPivot(org.mapsforge.core.model.LatLong pivot)
The pivot point is the point the map is scaled around when zooming.void
setScaleFactor(double scaleFactor)
Sets the new scale factor to be applied.void
setScaleFactorAdjustment(double adjustment)
void
setZoomLevel(byte zoomLevel)
Sets the new zoom level of the map.void
setZoomLevel(byte zoomLevel, boolean animated)
Sets the new zoom level of the mapvoid
setZoomLevelMax(byte zoomLevelMax)
void
setZoomLevelMin(byte zoomLevelMin)
void
zoom(byte zoomLevelDiff)
Changes the current zoom level by the given value if possible.void
zoom(byte zoomLevelDiff, boolean animated)
Changes the current zoom level by the given value if possible.void
zoomIn()
Increases the current zoom level by one if possible.void
zoomIn(boolean animated)
Increases the current zoom level by one if possible.void
zoomOut()
Decreases the current zoom level by one if possible.void
zoomOut(boolean animated)
Decreases the current zoom level by one if possible.-
Methods inherited from class org.mapsforge.map.model.common.Observable
addObserver, notifyObservers, removeObserver
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.mapsforge.map.model.IMapViewPosition
addObserver, removeObserver
-
-
-
-
Constructor Detail
-
MapViewPosition
public MapViewPosition(DisplayModel displayModel)
-
-
Method Detail
-
animateTo
public void animateTo(org.mapsforge.core.model.LatLong latLong)
Animate the map towards the given position.- Specified by:
animateTo
in interfaceIMapViewPosition
-
animationInProgress
public boolean animationInProgress()
- Specified by:
animationInProgress
in interfaceIMapViewPosition
- Returns:
- true if animation is in progress or animation is in the queue for being processed.
-
destroy
public void destroy()
Description copied from interface:IMapViewPosition
Destroys the class.- Specified by:
destroy
in interfaceIMapViewPosition
-
getCenter
public org.mapsforge.core.model.LatLong getCenter()
Description copied from interface:IMapViewPosition
Returns the current center position of the map. The position may change rapidly if an animation is in progress. If you are using animation consider keeping the positions and zoom factors in your code and not using this getter.- Specified by:
getCenter
in interfaceIMapViewPosition
- Returns:
- the current center position of the map.
-
getMapLimit
public org.mapsforge.core.model.BoundingBox getMapLimit()
- Specified by:
getMapLimit
in interfaceIMapViewPosition
- Returns:
- the current limit of the map (might be null).
-
getMapPosition
public org.mapsforge.core.model.MapPosition getMapPosition()
Description copied from interface:IMapViewPosition
Returns a newly instantiated object representing the current position and zoomlevel. Note that the position or zoomlevel may change rapidly if an animation is in progress.- Specified by:
getMapPosition
in interfaceIMapViewPosition
- Returns:
- the current center position and zoom level of the map.
-
getPivot
public org.mapsforge.core.model.LatLong getPivot()
The pivot point is the point the map zooms around.- Specified by:
getPivot
in interfaceIMapViewPosition
- Returns:
- the lat/long coordinates of the map pivot point if set or null otherwise.
-
getPivotXY
public org.mapsforge.core.model.Point getPivotXY(byte zoomLevel)
The pivot point is the point the map zooms around. If the map zooms around its center null is returned, otherwise the zoom-specific x/y pixel coordinates for the MercatorProjection (note: not the x/y coordinates for the map view or the frame buffer, the MapViewPosition knows nothing about them).- Parameters:
zoomLevel
- the zoomlevel to compute the x/y coordinates for- Returns:
- the x/y coordinates of the map pivot point if set or null otherwise.
-
getScaleFactor
public double getScaleFactor()
Description copied from interface:IMapViewPosition
Gets the current scale factor. The scale factor is normally 2^zoomLevel but it may differ if in between a zoom-animation or in between a pinch-to-zoom process.Needed by mapsforge core classes.
- Specified by:
getScaleFactor
in interfaceIMapViewPosition
-
getZoomLevel
public byte getZoomLevel()
- Specified by:
getZoomLevel
in interfaceIMapViewPosition
- Returns:
- the current zoom level of the map.
-
getZoomLevelMax
public byte getZoomLevelMax()
- Specified by:
getZoomLevelMax
in interfaceIMapViewPosition
-
getZoomLevelMin
public byte getZoomLevelMin()
- Specified by:
getZoomLevelMin
in interfaceIMapViewPosition
-
init
public void init(PreferencesFacade preferencesFacade)
Description copied from interface:IMapViewPosition
Initializes the class.Needed by mapsforge core classes.
- Specified by:
init
in interfaceIMapViewPosition
- Specified by:
init
in interfacePersistable
-
moveCenter
public void moveCenter(double moveHorizontal, double moveVertical)
Animates the center position of the map by the given amount of pixels.- Specified by:
moveCenter
in interfaceIMapViewPosition
- Parameters:
moveHorizontal
- the amount of pixels to move this MapViewPosition horizontally.moveVertical
- the amount of pixels to move this MapViewPosition vertically.
-
moveCenter
public void moveCenter(double moveHorizontal, double moveVertical, boolean animated)
Moves the center position of the map by the given amount of pixels.- Specified by:
moveCenter
in interfaceIMapViewPosition
- Parameters:
moveHorizontal
- the amount of pixels to move this MapViewPosition horizontally.moveVertical
- the amount of pixels to move this MapViewPosition vertically.animated
- whether the move should be animated.
-
moveCenterAndZoom
public void moveCenterAndZoom(double moveHorizontal, double moveVertical, byte zoomLevelDiff)
Animates the center position of the map by the given amount of pixels.- Specified by:
moveCenterAndZoom
in interfaceIMapViewPosition
- Parameters:
moveHorizontal
- the amount of pixels to move this MapViewPosition horizontally.moveVertical
- the amount of pixels to move this MapViewPosition vertically.zoomLevelDiff
- the difference in desired zoom level.
-
moveCenterAndZoom
public void moveCenterAndZoom(double moveHorizontal, double moveVertical, byte zoomLevelDiff, boolean animated)
Moves the center position of the map by the given amount of pixels.- Parameters:
moveHorizontal
- the amount of pixels to move this MapViewPosition horizontally.moveVertical
- the amount of pixels to move this MapViewPosition vertically.zoomLevelDiff
- the difference in desired zoom level.animated
- whether the move should be animated.
-
save
public void save(PreferencesFacade preferencesFacade)
Description copied from interface:IMapViewPosition
Saves the current state.Needed by mapsforge core classes.
- Specified by:
save
in interfaceIMapViewPosition
- Specified by:
save
in interfacePersistable
-
setCenter
public void setCenter(org.mapsforge.core.model.LatLong latLong)
Sets the new center position of the map.- Specified by:
setCenter
in interfaceIMapViewPosition
-
setMapLimit
public void setMapLimit(org.mapsforge.core.model.BoundingBox mapLimit)
Sets the new limit of the map (might be null).- Specified by:
setMapLimit
in interfaceIMapViewPosition
-
setMapPosition
public void setMapPosition(org.mapsforge.core.model.MapPosition mapPosition)
Sets the new center position and zoom level of the map. Note: The default zoom level changes are animated.- Specified by:
setMapPosition
in interfaceIMapViewPosition
-
setMapPosition
public void setMapPosition(org.mapsforge.core.model.MapPosition mapPosition, boolean animated)
Sets the new center position and zoom level of the map.- Specified by:
setMapPosition
in interfaceIMapViewPosition
-
setPivot
public void setPivot(org.mapsforge.core.model.LatLong pivot)
The pivot point is the point the map is scaled around when zooming. In normal mode the pivot point is whatever the view center is (this is indicated by setting the pivot to null), but when hand-zooming the pivot point can be any point on the map. It is stored as lat/long and retrieved as an x/y coordinate depending on the current zoom level.- Specified by:
setPivot
in interfaceIMapViewPosition
- Parameters:
pivot
- lat/long of pivot point, null for map center
-
setScaleFactor
public void setScaleFactor(double scaleFactor)
Sets the new scale factor to be applied.
-
setScaleFactorAdjustment
public void setScaleFactorAdjustment(double adjustment)
- Specified by:
setScaleFactorAdjustment
in interfaceIMapViewPosition
-
setZoomLevel
public void setZoomLevel(byte zoomLevel)
Sets the new zoom level of the map. Note: The default zoom level changes are animated.- Specified by:
setZoomLevel
in interfaceIMapViewPosition
- Parameters:
zoomLevel
- new zoom level.- Throws:
java.lang.IllegalArgumentException
- if the zoom level is negative.
-
setZoomLevel
public void setZoomLevel(byte zoomLevel, boolean animated)
Sets the new zoom level of the map- Specified by:
setZoomLevel
in interfaceIMapViewPosition
- Parameters:
zoomLevel
- desired zoom levelanimated
- true if the transition should be animated, false otherwise- Throws:
java.lang.IllegalArgumentException
- if the zoom level is negative.
-
setZoomLevelMax
public void setZoomLevelMax(byte zoomLevelMax)
- Specified by:
setZoomLevelMax
in interfaceIMapViewPosition
-
setZoomLevelMin
public void setZoomLevelMin(byte zoomLevelMin)
- Specified by:
setZoomLevelMin
in interfaceIMapViewPosition
-
zoom
public void zoom(byte zoomLevelDiff)
Changes the current zoom level by the given value if possible. Note: The default zoom level changes are animated.- Specified by:
zoom
in interfaceIMapViewPosition
-
zoom
public void zoom(byte zoomLevelDiff, boolean animated)
Changes the current zoom level by the given value if possible.
-
zoomIn
public void zoomIn()
Increases the current zoom level by one if possible. Note: The default zoom level changes are animated.- Specified by:
zoomIn
in interfaceIMapViewPosition
-
zoomIn
public void zoomIn(boolean animated)
Increases the current zoom level by one if possible.- Specified by:
zoomIn
in interfaceIMapViewPosition
-
zoomOut
public void zoomOut()
Decreases the current zoom level by one if possible. Note: The default zoom level changes are animated.- Specified by:
zoomOut
in interfaceIMapViewPosition
-
zoomOut
public void zoomOut(boolean animated)
Decreases the current zoom level by one if possible.- Specified by:
zoomOut
in interfaceIMapViewPosition
-
-