OSMDroid, wie man externe Anbieter mit lokalen zusammenarbeiten lässt?
Also habe ich Osmdroid endlich dazu gebracht, mit einem lokalen Verzeichnis zu arbeiten, aber ich möchte Kacheln von Mapnik laden, wenn sie lokal fehlen. Ich bin mir nicht sicher, was ich vermisse.
Meine Implementierung ist wie folgt:
private MapView mapView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.osm_map);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
MapController mapController = mapView.getController();
mapController.setZoom(5);
GeoPoint point2 = new GeoPoint(55708545, 10006348);
mapController.setCenter(point2);
//TODO Save to SD
AssetManager assetManager = getAssets();
InputStream is;
String fileName = "test.zip";
String path = Environment.getExternalStorageDirectory() + File.separator + fileName; //TODO Path to save it to
try {
is = assetManager.open(fileName);
FileOutputStream fo = new FileOutputStream(path);
byte[] b = new byte[1024];
int length;
while((length = is.read(b)) != -1) {
fo.write(b, 0, length);
}
fo.flush();
fo.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
File tileFile = new File(path);
IArchiveFile[] archives = new IArchiveFile[1];
archives[0] = ArchiveFileFactory.getArchiveFile(tileFile);
CustomTileSource customTiles = new CustomTileSource("Mapnik", null, 0, 24, 256, ".png"); // the name should match the name of the folder that is zipped
MapTileModuleProviderBase[] providers = new MapTileModuleProviderBase[2];
providers[0] = new MapTileFileArchiveProvider(new SimpleRegisterReceiver(getApplicationContext()), customTiles, archives);
providers[1] = new MapTileDownloader(TileSourceFactory.MAPNIK);
mapView.setUseDataConnection(false);
mapView.setTileSource(TileSourceFactory.MAPNIK);
MapTileProviderArray tileProvider = new MapTileProviderArray(customTiles, null, providers);
TilesOverlay tilesOverlay = new TilesOverlay(tileProvider, getApplicationContext());
mapView.getOverlays().add(tilesOverlay);
mapView.invalidate();
}
UND
public class CustomTileSource extends BitmapTileSourceBase {
public CustomTileSource(String aName, string aResourceId,
int aZoomMinLevel, int aZoomMaxLevel, int aTileSizePixels,
String aImageFilenameEnding) {
super(aName, aResourceId, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels,
aImageFilenameEnding);
}
}