Class BackgroundMapAttachment

java.lang.Object
slash.navigation.mapview.mapsforge.BackgroundMapAttachment

public class BackgroundMapAttachment extends Object
Decides whether the world-map background layer should be attached as the base layer, independent of the order in which the async background map download (Path B) and the EDT map/theme layer-stack build (Path A) run. The world map is a global, low-detail base layer: it belongs underneath every displayed map regardless of type, not just Mapsforge maps. It fills the area a partial offline map (Mapsforge/MBTiles) does not cover, and it keeps the offline edition usable when its only selectable map is the online OpenStreetMap default and those tiles cannot be reached - without it the map stays gray. The background sits at layer index 0, so an opaque map on top hides it and there is no visible cost when the displayed map does render.
Author:
Christian Pesch
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    displayedMapLayerIndex(int backgroundLayerIndex)
    The displayed map layer has to sit directly above the world-map background.
    static boolean
    shouldAttachBackground(boolean layerReady, boolean hasDisplayedMap)
     
    static boolean
    shouldRedrawAfterStackRebuild(boolean backgroundAttached, boolean stackRebuilt)
    A layer-stack rebuild (map/theme change) can kill in-flight tile jobs of an already attached background layer without re-issuing them, leaving unpainted tiles behind until the user pans or zooms.

    Methods inherited from class java.lang.Object

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

    • shouldAttachBackground

      public static boolean shouldAttachBackground(boolean layerReady, boolean hasDisplayedMap)
      Parameters:
      layerReady - whether the background layer has been built successfully
      hasDisplayedMap - whether a map is currently displayed
      Returns:
      true iff the world-map background layer should be attached as the base layer now
    • displayedMapLayerIndex

      public static int displayedMapLayerIndex(int backgroundLayerIndex)
      The displayed map layer has to sit directly above the world-map background. Inserting it there instead of always at index 0 and then moving the background back below it avoids removing and re-adding the background layer, which mapsforge's TileRendererLayer does not survive (see ReattachableTileRendererLayer).
      Parameters:
      backgroundLayerIndex - index of the attached background layer in the layer list, or -1 if none is attached
      Returns:
      the index at which the displayed map layer has to be inserted
    • shouldRedrawAfterStackRebuild

      public static boolean shouldRedrawAfterStackRebuild(boolean backgroundAttached, boolean stackRebuilt)
      A layer-stack rebuild (map/theme change) can kill in-flight tile jobs of an already attached background layer without re-issuing them, leaving unpainted tiles behind until the user pans or zooms. Forcing one redraw afterwards lets TileLayer.draw() re-queue whatever job the rebuild dropped.
      Parameters:
      backgroundAttached - whether the background layer is attached as the base layer now
      stackRebuilt - whether the displayed map/theme layer stack was just torn down and rebuilt
      Returns:
      true iff one redraw of the layer stack should be forced to repair a job dropped during the rebuild