Hello,
Sorry if this seems a bit elementary, but I'd like to understand some of the design decisions and assumptions that were made for mapsforge. The background is that I have an Android app (imagine something similar to a Garmin or Magellan handheld GPS) that provides multiple screens with navigation info, and some of these pages have a MapView somewhere among other Views. Potentially a single screen can even have more than one MapView, although that's not particularly useful, since every instance will always show the same map location, zoom, and style. The user can quickly switch between the various screens, and MapView instances are destroyed and created to implement this. Thus, creating and destroying MapView instances will be a regular occurrence.
Now, what should the lifecycle of the various mapsforge components be? I'll list the components, and what I think makes sense, but I'd love to be corrected if I'm for some reason wrong.
* Map data
I'm assuming that the user has a folder somewhere with vector maps, and I'll build a MultiMapDataStore from all the maps I can find in that folder. I imagine it makes most sense to build a MultiMapDataStore in the onCreate() of the app that covers all the map files I have available. As far as I can tell I only have to call close() on the instance to destroy it, and I only have to do that in onDestroy(). I'm guessing that the data of the MultiMapDataStore is not large enough that it is worth calling close() on it in an onPause(), and then build it again in onResume(). As far as I can tell, there is no reason to create a new MultiMapDataStore every time I create a new MapView.
If I need to store the maps on an external SD card, the lifecycle of the MultiMapDataStore should be coupled to the availability of the SD card.
* LayerManager, Layers, individual layers
Since all MapView instances will always show the same info, conceptually it would be possible to have only a single LayerManager with the same lifecycle as the map data or the render theme (see below), but as far as I can tell, it is not possible to let multiple MapViews share a single LayerManager, or to `transplant' a LayerManager from one MapView to the next one. The same applies for instances of the Layers class, or instances of individual layers.
* In-memory tile cache
The most obvious lifetime of the in-memory tile cache is from onResume() to onPause(), but it seems to me that caches are directly coupled to a particular map view instance/Layer, and then I'll have to destroy the cache every time a view is destroyed, even if the user switches from one page with a map view to another page with a map view.
* External tile cache
The most obvious lifetime of the external tile cache is `as long as the app is installed, or until a map file is replaced', but again I'm not sure that is really possible.
* Render themes
Another complication is that I'd like to let the user switch between different render themes. At the very least I'll need to use different caches for the different render themes, although again I'm afraid I'll have to destroy all caches on every switch.
Am I missing a component?
Thanks for clarification on all these issues!
--
Kees van Reeuwijk