【问题标题】:Multiple tile layers on osmdroidosmdroid 上的多个瓦片层
【发布时间】:2012-11-02 11:13:50
【问题描述】:

目前我正在使用 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 上渲染多个数据层,或者我一次只能显示一个数据层? 我找到了this example for GoogleMaps,但一次没有找到一些处理多重tileSources 的示例OSMdroid 代码。

【问题讨论】:

    标签: java android osmdroid


    【解决方案1】:

    是的,当然可以。您只需将另一个 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);
    

    【讨论】:

    • 根据我的经验,osmdroid 库中的层有点消耗内存,这意味着如果您添加超过 2 或 3 层,您很快就会遇到一些麻烦(OutOfMemory Exception)。
    • 如何更改BaseLayer
    猜你喜欢
    • 1970-01-01
    • 2020-08-04
    • 2020-04-15
    • 1970-01-01
    • 2017-04-22
    • 2014-02-19
    • 2022-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多