Package org.mapsforge.map.layer
Class Layer
- java.lang.Object
-
- org.mapsforge.map.layer.Layer
-
- Direct Known Subclasses:
Circle
,Grid
,GroupLayer
,LabelLayer
,Marker
,Polygon
,Polyline
,TileCoordinatesLayer
,TileGridLayer
,TileLayer
public abstract class Layer extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected DisplayModel
displayModel
-
Constructor Summary
Constructors Constructor Description Layer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
draw(org.mapsforge.core.model.BoundingBox boundingBox, byte zoomLevel, org.mapsforge.core.graphics.Canvas canvas, org.mapsforge.core.model.Point topLeftPoint)
Draws thisLayer
on the given canvas.DisplayModel
getDisplayModel()
Getter for DisplayModel.org.mapsforge.core.model.LatLong
getPosition()
Gets the geographic position of this layer element, if it exists.boolean
isVisible()
protected void
onAdd()
Called each time thisLayer
is added to aLayers
list.void
onDestroy()
boolean
onLongPress(org.mapsforge.core.model.LatLong tapLatLong, org.mapsforge.core.model.Point layerXY, org.mapsforge.core.model.Point tapXY)
Handles a long press event.protected void
onRemove()
Called each time thisLayer
is removed from aLayers
list.boolean
onScroll(float scrollX1, float scrollY1, float scrollX2, float scrollY2)
Handles a scroll event.boolean
onTap(org.mapsforge.core.model.LatLong tapLatLong, org.mapsforge.core.model.Point layerXY, org.mapsforge.core.model.Point tapXY)
Handles a tap event.void
requestRedraw()
Requests an asynchronous redrawing of all layers.void
setDisplayModel(DisplayModel displayModel)
The DisplayModel comes from a MapView, so is generally not known when the layer itself is created.void
setVisible(boolean visible)
Sets the visibility flag of thisLayer
to the given value.void
setVisible(boolean visible, boolean redraw)
Sets the visibility flag of thisLayer
to the given value.
-
-
-
Field Detail
-
displayModel
protected DisplayModel displayModel
-
-
Method Detail
-
draw
public abstract void draw(org.mapsforge.core.model.BoundingBox boundingBox, byte zoomLevel, org.mapsforge.core.graphics.Canvas canvas, org.mapsforge.core.model.Point topLeftPoint)
Draws thisLayer
on the given canvas.- Parameters:
boundingBox
- the geographical area which should be drawn.zoomLevel
- the zoom level at which thisLayer
should draw itself.canvas
- the canvas on which thisLayer
should draw itself.topLeftPoint
- the top-left pixel position of the canvas relative to the top-left map position.
-
getPosition
public org.mapsforge.core.model.LatLong getPosition()
Gets the geographic position of this layer element, if it exists. The default implementation of this method returns null.- Returns:
- the geographic position of this layer element, null otherwise
-
isVisible
public final boolean isVisible()
- Returns:
- true if this
Layer
is currently visible, false otherwise. The default value is true.
-
onDestroy
public void onDestroy()
-
onLongPress
public boolean onLongPress(org.mapsforge.core.model.LatLong tapLatLong, org.mapsforge.core.model.Point layerXY, org.mapsforge.core.model.Point tapXY)
Handles a long press event. A long press event is only triggered if the map was not moved. A return value of true indicates that the long press event has been handled by this overlay and stops its propagation to other overlays. The default implementation of this method does nothing and returns false.- Parameters:
tapLatLong
- the geographic position of the long press.layerXY
- the xy position of the layer element (if available)tapXY
- the xy position of the tap- Returns:
- true if the long press event was handled, false otherwise.
-
onScroll
public boolean onScroll(float scrollX1, float scrollY1, float scrollX2, float scrollY2)
Handles a scroll event. A return value of true indicates that the scroll event has been handled by this overlay and stops its propagation to other overlays.- Parameters:
scrollX1
- the x position of the first down motion event that started the scrolling.scrollY1
- the y position of the first down motion event that started the scrolling.scrollX2
- the x position of the move motion event that triggered the current onScroll.scrollY2
- the y position of the move motion event that triggered the current onScroll.- Returns:
- true if the scroll event was handled, false otherwise.
-
onTap
public boolean onTap(org.mapsforge.core.model.LatLong tapLatLong, org.mapsforge.core.model.Point layerXY, org.mapsforge.core.model.Point tapXY)
Handles a tap event. A return value of true indicates that the tap event has been handled by this overlay and stops its propagation to other overlays. The default implementation of this method does nothing and returns false.- Parameters:
tapLatLong
- the the geographic position of the tap.layerXY
- the xy position of the layer element (if available)tapXY
- the xy position of the tap- Returns:
- true if the tap event was handled, false otherwise.
-
requestRedraw
public final void requestRedraw()
Requests an asynchronous redrawing of all layers.
-
getDisplayModel
public DisplayModel getDisplayModel()
Getter for DisplayModel.- Returns:
- the display model.
-
setDisplayModel
public void setDisplayModel(DisplayModel displayModel)
The DisplayModel comes from a MapView, so is generally not known when the layer itself is created. Maybe a better way would be to have a MapView as a parameter when creating a layer.- Parameters:
displayModel
- the displayModel to use.
-
setVisible
public final void setVisible(boolean visible)
Sets the visibility flag of thisLayer
to the given value. Note: By default a redraw will take place afterwards.
-
setVisible
public void setVisible(boolean visible, boolean redraw)
Sets the visibility flag of thisLayer
to the given value.
-
onAdd
protected void onAdd()
Called each time thisLayer
is added to aLayers
list.
-
onRemove
protected void onRemove()
Called each time thisLayer
is removed from aLayers
list.
-
-