0

I have a basic Android app that loads and displays a local .mbtiles file using the Mapbox SDK (version 0.7.3) but there is a significant delay when first loading the app (resulting in a black screen) while it loads the tiles. It looks like it might be loading ALL of the tiles (not just the visible tiles at launch). Is there a way to change this. The .mbtiles file is approximately 257 MB in size and it takes approximately 40 seconds for the app to display the map after starting.

Any help would be greatly appreciated.

Here is where the tiles are loaded:

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.findViewById(R.id.mapview);

    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setZoom(9);
    mapView.setMinZoomLevel(8);
    mapView.setMaxZoomLevel(15);
    mapView.setCenter(new LatLng(55.676111, 12.568333));
    mapView.setTileSource(new MBTilesLayer(this, "DK_underlay_1_0_4.mbtiles"));

}

and here is are the logs showing a ~40 second gap when loading the app:

04-29 11:07:54.173  23590-23590/com.example.stugrey.testapp D/MapboxMapView﹕ centerLatLng is not specified in XML.
04-29 11:07:54.173  23590-23590/com.example.stugrey.testapp D/Mapbox MapView﹕ zoomLevel is not specified in XML.
04-29 11:08:34.236  23590-23590/com.example.stugrey.testapp D/AppUtils﹕ Device density is 320, and result of @2x check is true
04-29 11:08:34.236  23590-23590/com.example.stugrey.testapp D/MapTileDownloader﹕ Going to use @2x tiles? 'true'
04-29 11:08:34.308  23590-23590/com.example.stugrey.testapp I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018_msm8226_LNX.LA.3.5.1_RB1__release_AU ()
OpenGL ES Shader Compiler Version: E031.24.00.08
Build Date: 03/07/14 Fri
Local Branch:
Remote Branch: quic/LNX.LA.3.5.1_RB1.1
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018 + f2fd134 +  NOTHING
StuGrey
  • 1,479
  • 9
  • 20

1 Answers1

2

The slow part of your code is the creation of the MBTilesLayer. Everything else should be smooth. So one thing you could do is to move the slow new MBTilesLayer(this, "DK_underlay_1_0_4.mbtiles") code into an AsyncTask so that your UI is not blocked during the slow loading. This does not reduce the load time but ensures a non blocked UI.

So you could show a progress indicator (or placeholder) instead of a black screen.

Stefan Arn
  • 1,156
  • 12
  • 29