因此,我试图通过将图块合并到通过使用
从我自己的图块服务器创建的本地数据库文件中的图块,以离线模式使用Mapbox SDK./mbgl-offline --north [north coordinate] --west [west coordinate] --south [south coordinate] --east [east coordinate] --minZoom [minimum zoom] --maxZoom [maximum zoom] --output [output file path] --style [style URL] --token [mapbox token]
来自mapbox-gl-native库的命令。
我将文件放在/ path / to / file / files目录中,并实现了合并代码,如示例所示:merge offline tiles example
当我打开应用程序时,我敬酒说合并成功,但是我看不到地图。我所看到的只是一个空白的表面,具有我的地图样式的背景颜色。
如示例中所示,我确保应用未连接到互联网,然后在加载样式之前合并数据库文件:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the map view.
Mapbox.getInstance(this, getString(R.string.access_token));
// This contains the MapView in XML and needs to be called after the access token is configured.
setContentView(R.layout.activity_main);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
Mapbox.setConnected(false);
mergeDb();
mapView.getMapAsync(this);
}
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
MainActivity.this.mapboxMap = mapboxMap;
mapboxMap.setStyle( new Style.Builder().fromUrl("http://<my_server_ip>/styles/klokantech-basic/style.json")
, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
// enableLocationComponent(style);
}
});
}
我的mergeDb函数:
private void mergeDb(){
System.out.println(FileSource.getResourcesCachePath(this));
OfflineManager.getInstance(this).mergeOfflineRegions(FileSource.getResourcesCachePath(this) + "/myfile.db", new OfflineManager.MergeOfflineRegionsCallback() {
@Override
public void onMerge(OfflineRegion[] offlineRegions) {
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(new Style.Builder().fromUrl("http://<my_server_ip>/styles/klokantech-basic/style.json"));
}
});
Toast.makeText(
MainActivity.this,
String.format("Merged %d regions.", offlineRegions.length),
Toast.LENGTH_LONG).show();
}
@Override
public void onError(String error) {
Toast.makeText(
MainActivity.this,
String.format("Offline DB merge error." ),
Toast.LENGTH_LONG).show();
System.out.println(error);
}
});
}
任何想法可能是什么问题?