1//super important to configure some of the mapsforge settings first in your activity onCreate:
2MapsForgeTileSource.createInstance(this.getApplication());
3
4//
5File[] maps = null; //TODO scan/prompt for map files (.map)
6
7XmlRenderTheme theme = null; //null is ok here, uses the default rendering theme if it's not set
8try {
9//this file should be picked up by the mapsforge dependencies
10 theme = new AssetsRenderTheme(getContext().getApplicationContext(), "renderthemes/", "rendertheme-v4.xml");
11 //alternative: theme = new ExternalRenderTheme(userDefinedRenderingFile);
12} catch (Exception ex) {
13 ex.printStackTrace();
14}
15
16MapsForgeTileSource fromFiles = MapsForgeTileSource.createFromFiles(maps, theme, "rendertheme-v4");
17MapsForgeTileProvider forge = new MapsForgeTileProvider(
18 new SimpleRegisterReceiver(getContext()),
19 fromFiles, null);
20
21mMapView.setTileProvider(forge);
22
23//now for a magic trick
24//since we have no idea what will be on the
25//user's device and what geographic area it is, this will attempt to center the map
26//on whatever the map data provides
27mMapView.post(
28 new Runnable() {
29 @Override
30 public void run() {
31 mMapView.zoomToBoundingBox(fromFiles.getBoundsOsmdroid(), false);
32 }
33 });