mapbox / mapbox-gl-native

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
4.35k stars 1.33k forks source link

Map style does not load if listOfflineRegions is called first #16503

Open thirstycoda opened 4 years ago

thirstycoda commented 4 years ago

Platform: Android Mapbox SDK version:

I am creating an app with an activity to allow users to view a list of downloaded offline regions and an activity with a map view. If the user opens the activity listing the offline regions before opening the activity with the map view, the callback for MapboxMap.setStyle() never triggers and the map remains grey.

This can also be demonstrated in a single activity with the following code:

        OfflineManager.getInstance(this).listOfflineRegions(new OfflineManager.ListOfflineRegionsCallback() {
            @Override
            public void onList(OfflineRegion[] offlineRegions) {
                // Intentionally empty
            }

            @Override
            public void onError(String error) {
                // TODO: Handle error
            }
        });

        mapView.getMapAsync(map -> {
            map.setStyle(Style.MAPBOX_STREETS, style -> {
                // Not executed
                this.style = style;
            });
        });

With the above code, the map remains grey. Commenting out the call to listOfflineRegions makes the map work as expected.

Note: The problem exists whether there are any offline regions or not

Steps to trigger behavior

  1. Open application
  2. Open activity with MapView - map displays correctly
  3. Close application
  4. Open application
  5. Open activity without a mapview that calls OfflineManager.listOfflineRegions()
  6. Open activity with MapView

Expected behavior

Map displays correctly

Actual behavior

Map remains grey