2

I have started to build an android apps using Mapbox Android SDK. I want to use my custom mbtiles file created from Tilemill. I was following this instruction

Code to Display the Tilemills mbtiles in android project

I have successfully implemented this code and working fine. But the problem, when I am building APK its becoming a huge file as my MBTiles file is too big. This is why its taking long to open the apps. Is there any way to get access the MBTiles file from online server storage such as http://www.example.com/mymap.mbtiles? I have tried the MapView Activity with the following code but didn't get any luck

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setZoom(10);
        mapView.setCenter(new LatLng(38.8977, -77.0365));
        mapView.setTileSource(new MBTilesLayer(this, "http://www.example.com/mymap.mbtiles"));

The XML file contains

<com.mapbox.mapboxsdk.views.MapView
    android:id="@+id/mapview
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
4

2 回答 2

3

在我看来,您在问题中使用的 API 现在已被弃用,取而代之的是 mapbox-gl-native 项目。但是,根据我在此处和 GitHub 上的其他答案中找到的内容,可能有一种方法可以实现您想要做的事情:

  1. 使用mb-util将您的 .mbtiles 文件提取为 .png 平铺文件和 .json 文件。
  2. 在服务器上托管这些文件。
  3. 使用 TileJsonTileLayer 而不是 MBTilesLayer 来访问在线图块。可以在 mapbox-android-sdk-legacy 项目的issue # 742中找到这样做的尝试。

如果它不起作用,我很抱歉。这是我目前能想到的最好的方法,因为我没有时间自己实现它。

于 2015-10-25T11:44:39.650 回答
0

要在 Mapbox 或 Maplibre 中显示您自己的矢量 MBTiles 文件,您基本上只需将 MBTiles 文件指向您的样式 JSON 中的矢量数据源。

sources样式 JSON 的标签中,您需要将url可能指向另一个 JSON 的值替换为这种格式

mbtiles://<file-uri>

可能看起来像这样

mbtiles://file:///data/user/0/com.example.maplibretest/cache/india_coimbatore.mbtiles

这将指示 SDK 使用此链接的 MBTiles 文件作为矢量数据的来源,而不是在线来源。为了让您将此自定义 JSON 设置为您的样式,您需要在您的应用程序中打包一个 JSON,将其复制到您可以编辑的地方,将您的 MBTiles 文件的 Uri 添加到 url,然后将该 JSON 文件样式设置为Mapbox 或 Maplibre SDK。您还可以从在线资源中获取样式 JSON,对其进行编辑,然后将其提供给 SDK。

我已经在这篇博文中详细介绍了整个过程 - https://medium.com/@ty2/how-to-display-offline-maps-using-maplibre-mapbox-39ad0f3c7543

于 2021-08-19T20:11:57.670 回答