So I'm trying to use the Mapbox SDK in an offline mode by merging tiles in a local DB file I created from my own tile server by using
./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]
command from the mapbox-gl-native library.
I put the file in the /path/to/file/files directory and I implemented the merging code as shown in the example : merge offline tiles example
When I open the app I get a toast says the merging went successfully but I can't see the map. all I see is a blank surface with the background color of my map style.
As shown in the example, I make sure the app is not connected to the internet and then I merge the DB file before I load the style:
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);
}
});
}
My mergeDb function:
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);
}
});
}
Any idea what could be the problem?