【问题标题】:Purpose of the `aBaseUrl` parameter in the class OnlineTileSourceBase?OnlineTileSourceBase 类中“aBaseUrl”参数的用途?
【发布时间】:2015-12-02 18:06:25
【问题描述】:

我不明白OnlineTileSourceBase 类中aBaseUrl 参数的用途。我询问的原因是我试图让离线磁贴显示,但到目前为止还不能让它工作。我看到了我创建的叠加层,但没有地图数据(只有那个灰色网格),我想知道是否需要将 aBaseUrl 设置为适当的值。

设备上的数据在 sdcard/osmdroid/tiles/Mapnik/ 中。 Mapnik 包含文件夹 0, 1, ... 14,这些文件夹本身包含包含 .jpg 文件的文件夹。

在线,此代码有效(删除调用 setUseDataConnection(false) 并将平铺源设置为 MAPNIK)。基于@nightfixed here 的代码。

    public class MapActivity extends AppCompatActivity {

        final private int MIN_ZOOM_LEVEL = 0;
        final private int MAX_ZOOM_LEVEL = 14;
        final private int TILE_SIZE = 256;
        final private String IMAGE_EXTENSION = ".jpg";

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);

            CustomTileSource  tileSource = new CustomTileSource ("Default",   
                    MIN_ZOOM_LEVEL,     
                    MAX_ZOOM_LEVEL,   
                    TILE_SIZE,                      
                    IMAGE_EXTENSION,  
                    CustomTileSource.TILE_URL);  

            final MapView mapView = (MapView) findViewById(R.id.mapview);
            mapView.setTileSource(tileSource);
            // mapView.setTileSource(TileSourceFactory.MAPNIK);
            mapView.setUseDataConnection(false); // keeps the mapView from loading online tiles using network connection.

        }

    }


   public class CustomTileSource extends OnlineTileSourceBase {

    public static String[] TILE_URL = {"my_url"};

    public CustomTileSource (String aName,
                             int aZoomMinLevel,
                             int aZoomMaxLevel,
                             int aTileSizePixels,
                             String aImageFilenameEnding,
                             String[] urlArray) {
        super(
                aName,
                aZoomMinLevel,
                aZoomMaxLevel,
                aTileSizePixels,
                aImageFilenameEnding,
                urlArray);

    }

    // returns the url for each tile, depending on zoom level
    // this is where I changed the return statement to take the first url from the string array of urls
    @Override
    public String getTileURLString(MapTile aTile) {
        return TILE_URL[0] + aTile.getX() + "+" + aTile.getY() + "+" + aTile.getZoomLevel();
    }
}

【问题讨论】:

    标签: android osmdroid


    【解决方案1】:

    我建议你密切关注这个帖子:Download maps for osmdroid

    不需要CustomTileSource,使用mapView.setTileSource(TileSourceFactory.MAPNIK);

    如果您的图块位于“Mapnik”目录 (sdcard/osmdroid/tiles/Mapnik) 中,则 TileSource aName 应设置为“Mapnik”,而不是“默认”。

    离线时,aBaseUrl 无关紧要。

    【讨论】:

    • 在您链接到的帖子中,使用了网址 otile1.mqcdn.com/tiles/1.0.0/map,它适用于我(在线模式下)。如果我将该网址放在浏览器中,我会收到抱歉 - 我们无法提供您要求的内容。这是为什么呢?
    • 因为这只是基本网址。 osmdroid 添加各种参数以在每次请求时获取 1 个特定的 tile。
    • OIC,所以是的,如果我这样做 otile1.mqcdn.com/tiles/1.0.0/map/0/0/0.png 我会看到磁贴
    • 很好的链接,我刚刚将大部分内容添加到 osmdroid wiki。
    【解决方案2】:

    aBaseUrl 基本上是在线地图服务器的主要 url。例如

    http://tiles.mymapserver.com/mapdata(注意,完全虚构)

    aBaseUrl 之后,osmdroid 通过各种算法计算要加载的切片,然后在下载时将/Z/X/Y.jpg 之类的内容附加到aBaseUrl 字符串的末尾。

    【讨论】:

      猜你喜欢
      • 2019-01-15
      • 1970-01-01
      • 2015-04-04
      • 1970-01-01
      • 2020-04-26
      • 2020-11-08
      • 2013-02-20
      • 1970-01-01
      • 2011-11-29
      相关资源
      最近更新 更多