Mapbox-gl-native: [Android 5.2.0-beta.1] onMapReady callback never invoked

Created on 18 Oct 2017  路  8Comments  路  Source: mapbox/mapbox-gl-native

Hi guys! I've tried upgrade to 5.2.0.
here is my code which works fine with 5.1.4!

`
private void setupMapView() {
_mapOptions.camera(_initialCamera.build());
_mapView = new MapView(this.getContext(), _mapOptions);
_manager.addView(this, _mapView, 0);
_mapView.addOnMapChangedListener(this);
_mapView.onCreate(null);
_mapView.getMapAsync(this);
}

@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
    //WE NEVER GETS HERE
    if (_mapView == null) { return; }
    _map = mapboxMap;
    ...
 }`

Thanks!

Android needs information

Most helpful comment

@tobrun prior to 5.2.0, onMapChange() would be called with DID_FAIL_LOADING_MAP if there wasn't an internet connection. However in 5.3.1 (or 5.2.x), the map fails (black screen) silently. We'd like to alert users in this case. Is there a new way to detect if the map fails (is black)?

Also if DID_FAIL_LOADING_MAP is triggered from a different issue, is there any way to diagnose the cause other than logs? We're seeing some users encounter this but can't tell why their map won't load.

All 8 comments

@StasDoskalenko thank you for the report, I haven't looked into the difference but I was able to reproduce and work around the issue. In the code shown above you haven't provided a style Url with mapboxMapOptions. Having a style provided is necessary as OnMapReady will only be called if the style has been loaded and is ready to accept changes. Normally the default map style is loaded when the user doesn't provide one. This is done as part of onResume but the code block shown above doesn't take that in account.

@tobrun thanks!
But I've also tried to set styleUrl as:
_mapOptions.styleUrl(Style.SATELLITE_STREETS);
where SATELLITE_STREETS equals "mapbox://styles/mapbox/satellite-streets-v10"
It's didn't work for me :(

I have been trying out different use-cases to reproduce this issue but no luck:

  • in Activity#onCreate and setting contentview to MapView
  • as part of a button click and adding the view afterwards

Would you be able to share a bit more code that reproduces this issue? haven't been able to reproduce by going of the code shared in OP.

@tobrun actually, I'm trying to use new version with current RN Module (v5)

https://github.com/mapbox/react-native-mapbox-gl/blob/master/android/src/main/java/com/mapbox/reactnativemapboxgl/ReactNativeMapboxGLView.java

I've updated compileSdkVersion to 25. But still no luck :(

@StasDoskalenko thank you for adding that, since this is RN related issue. Could you follow up in that repository? Thank you. Closing as I'm not able to reproduce and issue should be handled downstream.

@tobrun just to clarify in what cases onMapChange listener can be never executed? Thanks!

If you don't have an internet connection and you haven't downloaded current style/camera configuration on map start as an offline download (eg. configure camera + style in xml or through mapboxmapoptions).

@tobrun prior to 5.2.0, onMapChange() would be called with DID_FAIL_LOADING_MAP if there wasn't an internet connection. However in 5.3.1 (or 5.2.x), the map fails (black screen) silently. We'd like to alert users in this case. Is there a new way to detect if the map fails (is black)?

Also if DID_FAIL_LOADING_MAP is triggered from a different issue, is there any way to diagnose the cause other than logs? We're seeing some users encounter this but can't tell why their map won't load.

Was this page helpful?
0 / 5 - 0 ratings