Class BackgroundMapAttachment
java.lang.Object
slash.navigation.mapview.mapsforge.BackgroundMapAttachment
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 TypeMethodDescriptionstatic intdisplayedMapLayerIndex(int backgroundLayerIndex) The displayed map layer has to sit directly above the world-map background.static booleanshouldAttachBackground(boolean layerReady, boolean hasDisplayedMap) static booleanshouldRedrawAfterStackRebuild(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.
-
Method Details
-
shouldAttachBackground
public static boolean shouldAttachBackground(boolean layerReady, boolean hasDisplayedMap) - Parameters:
layerReady- whether the background layer has been built successfullyhasDisplayedMap- 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'sTileRendererLayerdoes not survive (seeReattachableTileRendererLayer).- 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 letsTileLayer.draw()re-queue whatever job the rebuild dropped.- Parameters:
backgroundAttached- whether the background layer is attached as the base layer nowstackRebuilt- 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
-