Package org.mapsforge.map.layer.download
Class TileDownloadLayer
- java.lang.Object
-
- org.mapsforge.map.layer.Layer
-
- org.mapsforge.map.layer.TileLayer<DownloadJob>
-
- org.mapsforge.map.layer.download.TileDownloadLayer
-
- All Implemented Interfaces:
Observer
public class TileDownloadLayer extends TileLayer<DownloadJob> implements Observer
-
-
Field Summary
-
Fields inherited from class org.mapsforge.map.layer.TileLayer
hasJobQueue, isTransparent, jobQueue
-
Fields inherited from class org.mapsforge.map.layer.Layer
displayModel
-
-
Constructor Summary
Constructors Constructor Description TileDownloadLayer(TileCache tileCache, IMapViewPosition mapViewPosition, TileSource tileSource, org.mapsforge.core.graphics.GraphicFactory graphicFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DownloadJob
createJob(org.mapsforge.core.model.Tile tile)
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.long
getCacheTimeToLive()
Returns the time-to-live (TTL) for tiles in the cache, or 0 if not set.protected boolean
isTileStale(org.mapsforge.core.model.Tile tile, org.mapsforge.core.graphics.TileBitmap bitmap)
Whether the tile is stale and should be refreshed.protected void
onAdd()
Called each time thisLayer
is added to aLayers
list.void
onChange()
Called whenever the observed object has been changed.void
onDestroy()
void
onPause()
protected void
onRemove()
Called each time thisLayer
is removed from aLayers
list.void
onResume()
void
setCacheTimeToLive(long ttl)
Sets the time-to-live (TTL) for tiles in the cache.void
setDisplayModel(DisplayModel displayModel)
The DisplayModel comes from a MapView, so is generally not known when the layer itself is created.void
start()
-
Methods inherited from class org.mapsforge.map.layer.TileLayer
getAlpha, getTileCache, retrieveLabelsOnly, setAlpha, setParentTilesRendering
-
Methods inherited from class org.mapsforge.map.layer.Layer
getDisplayModel, getPosition, isVisible, onLongPress, onScroll, onTap, requestRedraw, setVisible, setVisible
-
-
-
-
Constructor Detail
-
TileDownloadLayer
public TileDownloadLayer(TileCache tileCache, IMapViewPosition mapViewPosition, TileSource tileSource, org.mapsforge.core.graphics.GraphicFactory graphicFactory)
-
-
Method Detail
-
draw
public void draw(org.mapsforge.core.model.BoundingBox boundingBox, byte zoomLevel, org.mapsforge.core.graphics.Canvas canvas, org.mapsforge.core.model.Point topLeftPoint)
Description copied from class:Layer
Draws thisLayer
on the given canvas.- Overrides:
draw
in classTileLayer<DownloadJob>
- 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.
-
getCacheTimeToLive
public long getCacheTimeToLive()
Returns the time-to-live (TTL) for tiles in the cache, or 0 if not set. Refer toisTileStale(Tile, TileBitmap)
for information on how the TTL is enforced.
-
onPause
public void onPause()
-
onResume
public void onResume()
-
setCacheTimeToLive
public void setCacheTimeToLive(long ttl)
Sets the time-to-live (TTL) for tiles in the cache. The initial TTL is obtained by calling theTileSource
'sTileSource.getDefaultTimeToLive()
()} method. Refer toisTileStale(Tile, TileBitmap)
for information on how the TTL is enforced.- Parameters:
ttl
- The TTL. If set to 0, no TTL will be enforced.
-
setDisplayModel
public void setDisplayModel(DisplayModel displayModel)
Description copied from class:Layer
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.- Overrides:
setDisplayModel
in classTileLayer<DownloadJob>
- Parameters:
displayModel
- the displayModel to use.
-
start
public void start()
-
createJob
protected DownloadJob createJob(org.mapsforge.core.model.Tile tile)
- Specified by:
createJob
in classTileLayer<DownloadJob>
-
isTileStale
protected boolean isTileStale(org.mapsforge.core.model.Tile tile, org.mapsforge.core.graphics.TileBitmap bitmap)
Whether the tile is stale and should be refreshed. This method is called fromdraw(BoundingBox, byte, Canvas, Point)
to determine whether the tile needs to be refreshed. A tile is considered stale if one or more of the following two conditions apply:- The
bitmap
'sTileBitmap.isExpired()
method returnsTrue
. - The layer has a time-to-live (TTL) set (
getCacheTimeToLive()
returns a nonzero value) and the sum of thebitmap
'sTileBitmap.getTimestamp()
and TTL is less than current time (as returned bySystem.currentTimeMillis()
).
bitmap
and attempt to obtain a fresh copy in the background. When a fresh copy becomes available, the layer will replace it and update the cache. If a fresh copy cannot be obtained (e.g. because the tile is obtained from an online source which cannot be reached), the stale tile will continue to be used until another#draw(BoundingBox, byte, Canvas, Point)
operation requests it again.- Specified by:
isTileStale
in classTileLayer<DownloadJob>
- Parameters:
tile
- A tile. This parameter is not used for aTileDownloadLayer
and can be null.bitmap
- The bitmap fortile
currently held in the layer's cache.
- The
-
onAdd
protected void onAdd()
Description copied from class:Layer
Called each time thisLayer
is added to aLayers
list.
-
onRemove
protected void onRemove()
Description copied from class:Layer
Called each time thisLayer
is removed from aLayers
list.
-
-