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 DownloadJobcreateJob(org.mapsforge.core.model.Tile tile)voiddraw(org.mapsforge.core.model.BoundingBox boundingBox, byte zoomLevel, org.mapsforge.core.graphics.Canvas canvas, org.mapsforge.core.model.Point topLeftPoint)Draws thisLayeron the given canvas.longgetCacheTimeToLive()Returns the time-to-live (TTL) for tiles in the cache, or 0 if not set.protected booleanisTileStale(org.mapsforge.core.model.Tile tile, org.mapsforge.core.graphics.TileBitmap bitmap)Whether the tile is stale and should be refreshed.protected voidonAdd()Called each time thisLayeris added to aLayerslist.voidonChange()Called whenever the observed object has been changed.voidonDestroy()voidonPause()protected voidonRemove()Called each time thisLayeris removed from aLayerslist.voidonResume()voidsetCacheTimeToLive(long ttl)Sets the time-to-live (TTL) for tiles in the cache.voidsetDisplayModel(DisplayModel displayModel)The DisplayModel comes from a MapView, so is generally not known when the layer itself is created.voidstart()-
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:LayerDraws thisLayeron the given canvas.- Overrides:
drawin classTileLayer<DownloadJob>- Parameters:
boundingBox- the geographical area which should be drawn.zoomLevel- the zoom level at which thisLayershould draw itself.canvas- the canvas on which thisLayershould 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:LayerThe 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:
setDisplayModelin classTileLayer<DownloadJob>- Parameters:
displayModel- the displayModel to use.
-
start
public void start()
-
createJob
protected DownloadJob createJob(org.mapsforge.core.model.Tile tile)
- Specified by:
createJobin 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()).
bitmapand 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:
isTileStalein classTileLayer<DownloadJob>- Parameters:
tile- A tile. This parameter is not used for aTileDownloadLayerand can be null.bitmap- The bitmap fortilecurrently held in the layer's cache.
- The
-
onAdd
protected void onAdd()
Description copied from class:LayerCalled each time thisLayeris added to aLayerslist.
-
onRemove
protected void onRemove()
Description copied from class:LayerCalled each time thisLayeris removed from aLayerslist.
-
-