在osmdroid上使用多个图层瓦片。

6

目前,我正在使用OSMdroid地图作为底图,加载一个瓦片数据层。

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);
osmv.getOverlays().add(tilesOverlay);

在BaseMap上面是否可以叠加多个数据层,或者我只能同时显示一个数据层?我找到了这个GoogleMaps的例子,但是还没有找到一些处理多个tileSources的OSMdroid代码示例。

1个回答

7

当然可以。您只需向地图添加另一个TilesOverlay即可。覆盖层(也称为tilesOverlays)按顺序绘制,从列表的最低索引(=0)开始。 以下是一个示例:

//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);

4
根据我的经验,osmdroid库中的图层会占用较多内存,这意味着如果你添加了超过2或3个图层,你很快就会遇到一些问题(OutOfMemory异常)。 - Sabian
如何更改“BaseLayer”? - Muhammad Babar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接