使用Mapbox中的Nutiteq SDK加载Mbtiles

时间:2015-09-30 08:16:11

标签: android mapbox nutiteq

我正在找出使用nutiteq SDK从mapbox加载mbtiles的方法。我知道如何使用此代码

离线加载mbtiles
// 1. Create tile data source from mbtiles file
MBTilesTileDataSource tileDataSource = new MBTilesTileDataSource("/sdcard/estonia_ntvt.mbtiles");

// 2. Load vector tile styleset
UnsignedCharVector styleBytes = AssetUtils.loadBytes("osmbright.zip");
MBVectorTileStyleSet vectorTileStyleSet = new MBVectorTileStyleSet(styleBytes);

// 3. Create vector tile decoder using the styleset
VectorTileDecoder vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet);

// 4. Create vector tile layer, using previously created data source and decoder
TileLayer vectorTileLayer = new VectorTileLayer(tileDataSource, vectorTileDecoder);

// 5. Add vector tile layer
mapView.getLayers().add(vectorTileLayer);

有没有办法使用Nutiteq SDK直接从mapbox mbtiles url加载它?

1 个答案:

答案 0 :(得分:1)

你是什么意思" mapbox mbtiles url"你能举个例子吗?通过mbtiles你的意思是离线包?

我可以想到以下MapBox网址:

一个。对于MapBox,在线栅格来源请参阅https://developer.nutiteq.com/guides/raster-tile-sources

湾对于MapBox作为在线矢量源,您还需要定义样式,并且需要更多编码:

    // load style file from assets. Nutiteq style is quite well compatible with MapBox Streets, 
    //   even though NT vector tiles are a bit different
    UnsignedCharVector styleBytes = AssetUtils.loadBytes("nutibright-v2.zip");
    if (styleBytes != null){

        // Create style set
        MBVectorTileStyleSet vectorTileStyleSet = new MBVectorTileStyleSet(styleBytes);
        MBVectorTileDecoder vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet);

        // Create tile data source and layer for vector tiles
        TileDataSource vectorTileDataSource = new HTTPTileDataSource(0, 14, "http://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v5/{zoom}/{x}/{y}.vector.pbf?access_token=pk...YOUR-MAPBOX-KEY");
        VectorTileLayer baseLayer = new VectorTileLayer(vectorTileDataSource, vectorTileDecoder);

        // add layer to map
        mapView.getLayers().add(baseLayer);

    }