Class ReattachableTileRendererLayer

java.lang.Object
org.mapsforge.map.layer.Layer
org.mapsforge.map.layer.TileLayer<org.mapsforge.map.layer.renderer.RendererJob>
org.mapsforge.map.layer.renderer.TileRendererLayer
slash.navigation.mapview.mapsforge.tiles.ReattachableTileRendererLayer
All Implemented Interfaces:
org.mapsforge.map.model.common.Observer

public class ReattachableTileRendererLayer extends org.mapsforge.map.layer.renderer.TileRendererLayer
A TileRendererLayer that keeps rendering after it has been removed from and re-added to the Layers of a map view.

Works around a mapsforge (0.30.0) bug, reported as mapsforge/mapsforge#1817: Layers.add(int, org.mapsforge.map.layer.Layer) calls setDisplayModel(org.mapsforge.map.model.DisplayModel) on every add, and TileLayer.setDisplayModel(org.mapsforge.map.model.DisplayModel) replaces the layer's JobQueue with a fresh instance each time, but TileRendererLayer.setDisplayModel(org.mapsforge.map.model.DisplayModel) creates its MapWorkerPool only once, bound to the queue that existed on the first add. After a re-add, TileLayer.draw() queues tile jobs into the new queue while the worker pool waits on the old one forever, so the layer never renders another tile. This is what left the world map background blank (issue #376).

Keeping the first queue for the whole lifetime of the layer keeps draw() and the worker pool on the same queue. The queue only captures the map view position and display model, which stay the same objects for a map view, so reusing it is safe.

  • Field Summary

    Fields inherited from class org.mapsforge.map.layer.TileLayer

    hasJobQueue, isTransparent, jobQueue, tileCache

    Fields inherited from class org.mapsforge.map.layer.Layer

    displayModel
  • Constructor Summary

    Constructors
    Constructor
    Description
    ReattachableTileRendererLayer(org.mapsforge.map.layer.cache.TileCache tileCache, org.mapsforge.map.datastore.MapDataStore mapDataStore, org.mapsforge.map.model.MapViewPosition mapViewPosition, boolean isTransparent, boolean renderLabels, boolean cacheLabels, org.mapsforge.core.graphics.GraphicFactory graphicFactory, org.mapsforge.map.layer.hills.HillsRenderConfig hillsRenderConfig)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    setDisplayModel(org.mapsforge.map.model.DisplayModel displayModel)
     

    Methods inherited from class org.mapsforge.map.layer.renderer.TileRendererLayer

    compileRenderTheme, createJob, getLabelStore, getMapDataStore, getRenderThemeFuture, getTextScale, isTileStale, onAdd, onChange, onDestroy, onRemove, retrieveLabelsOnly, setTextScale, setXmlRenderTheme

    Methods inherited from class org.mapsforge.map.layer.TileLayer

    draw, getAlpha, getCacheTileMargin, getCacheZoomMinus, getCacheZoomPlus, getTileCache, setAlpha, setCacheTileMargin, setCacheZoomMinus, setCacheZoomPlus, setParentTilesRendering

    Methods inherited from class org.mapsforge.map.layer.Layer

    getDisplayModel, getPosition, isVisible, onLongPress, onScroll, onTap, requestRedraw, setVisible, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ReattachableTileRendererLayer

      public ReattachableTileRendererLayer(org.mapsforge.map.layer.cache.TileCache tileCache, org.mapsforge.map.datastore.MapDataStore mapDataStore, org.mapsforge.map.model.MapViewPosition mapViewPosition, boolean isTransparent, boolean renderLabels, boolean cacheLabels, org.mapsforge.core.graphics.GraphicFactory graphicFactory, org.mapsforge.map.layer.hills.HillsRenderConfig hillsRenderConfig)
  • Method Details

    • setDisplayModel

      public void setDisplayModel(org.mapsforge.map.model.DisplayModel displayModel)
      Overrides:
      setDisplayModel in class org.mapsforge.map.layer.renderer.TileRendererLayer