我想在osmdroid中使用在线和离线地图图块提供程序。所以我创建了一个扩展MyTileProvider
的课程MapTileProviderArray
;然后我将我的离线和在线提供商添加到提供者列表中。戏剧性地基于文档,它应该在第一个提供者上查看,如果它不提供瓦片并返回null,则转到另一个提供者查找瓦片。
但是,联机提供程序不适用于脱机返回null的位置。这是我的代码:
class MyTileProvider extends MapTileProviderArray
{
private static ITileSource tileSource;
protected MyTileProvider(Context context)
{
super(tileSource = TileSourceFactory.MAPNIK, new SimpleRegisterReceiver(context));
// offline tile providing:
mTileProviderList.add(new OfflineMapTileProvider(context, tileSource));
// online tile providing:
mTileProviderList.add(new MapTileDownloader(TileSourceFactory.MAPNIK));
setTileSource(tileSource);
}
}
任何建议将不胜感激。感谢。
答案 0 :(得分:2)
试试这个:
//create the first tilesOverlay
final MapTileProviderBasic tileProvider = new MapTileProviderBasic(getApplicationContext());
final ITileSource tileSource = new XYTileSource("MyCustomTiles", null, 1, 16, 256, ".png",
"http://a.url.to/custom-tiles/");
tileProvider.setTileSource(tileSource);
final TilesOverlay tilesOverlay = new TilesOverlay(tileProvider, this.getBaseContext());
tilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
//create the second one
final MapTileProviderBasic anotherTileProvider = new MapTileProviderBasic(getApplicationContext());
final ITileSource anotherTileSource = new XYTileSource("MyCustomTiles", null, 1, 16, 256, ".png",
"http://a.secondurl.to/custom-tiles/");
anotherTileProvider.setTileSource(anotherTileSource);
final TilesOverlay secondTilesOverlay = new TilesOverlay(anotherTileProvider, this.getBaseContext());
secondTilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
// add the first tilesOverlay to the list
osmv.getOverlays().add(tilesOverlay);
// add the second tilesOverlay to the list
osmv.getOverlays().add(secondTilesOverlay);