Mapbox-gl-native: Decouple style loading from OnMapReady

Created on 26 Jun 2018  路  3Comments  路  Source: mapbox/mapbox-gl-native

To improve general map initialization time and more specificly map loading time when their isn't an internet connection. We should decouple OnMapReady invocation from the style finished loading event. OnMapReady should be called when the map is ready to render and we should provide a separate callback for when the style has finished loading. This change will require public API changes and will fit in well with the prospoed Style.java refactors in #9338.

wip branch.

Android SEMVER-MAJOR high priority

Most helpful comment

Yes, without any additional changes to the api that would result in not having those sources/layers added to the finished loaded style. eg. clustering is not showing up anymore:

image

For this reason I would like to include #9338 and refactor the API as:

    mapView.getMapAsync(map -> {
      // we get callback once the native lib has loaded
      map.setStyle(Style.MAPBOX_STREETS, style -> {
        // we get callback once the style has loaded
        style.addSource(new GeoJsonSource(MARKER_SOURCE, markers));
        style.addLayer(
          new SymbolLayer(MARKER_LAYER, MARKER_SOURCE)
        );
      });

The users won't be able to add sources/layers until the style has finished loading. Above api change would also help with implementing #10947.

All 3 comments

@tobrun if users are using OnMapReady as a hook for adding new sources/layers to the map via runtime styling, would the change proposed here cause issues where dynamically added layers would be lost after a remote style was finished loading? (Related: https://github.com/mapbox/mapbox-gl-native/issues/10947)

Yes, without any additional changes to the api that would result in not having those sources/layers added to the finished loaded style. eg. clustering is not showing up anymore:

image

For this reason I would like to include #9338 and refactor the API as:

    mapView.getMapAsync(map -> {
      // we get callback once the native lib has loaded
      map.setStyle(Style.MAPBOX_STREETS, style -> {
        // we get callback once the style has loaded
        style.addSource(new GeoJsonSource(MARKER_SOURCE, markers));
        style.addLayer(
          new SymbolLayer(MARKER_LAYER, MARKER_SOURCE)
        );
      });

The users won't be able to add sources/layers until the style has finished loading. Above api change would also help with implementing #10947.

done with #13484

Was this page helpful?
0 / 5 - 0 ratings