mapbox / mapbox-navigation-android

Mapbox Navigation SDK for Android
https://docs.mapbox.com/android/navigation/overview/
Other
622 stars 319 forks source link

NavigationMapRoute style dependency #2272

Open LukasPaczos opened 4 years ago

LukasPaczos commented 4 years ago

NavigationMapRoute is dependent on the valid Map Style object, even though it requires only the MapboxMap as an argument. More so, the NavigationMapRoute manages style changes under the hood, which makes the usage of the class unintuitive - the object has be created in the OnStyleLoaded callback, but it cannot get recreated in one, because it'll throw:

E/Mbgl-MapChangeReceiver: Exception in onDidFinishLoadingStyle
    com.mapbox.mapboxsdk.style.sources.CannotAddSourceException: Source mapbox-navigation-arrow-shaft-source already exists
        at com.mapbox.mapboxsdk.maps.NativeMapView.nativeAddSource(Native Method)
        at com.mapbox.mapboxsdk.maps.NativeMapView.addSource(NativeMapView.java:839)
        at com.mapbox.mapboxsdk.maps.Style.addSource(Style.java:115)
        at com.mapbox.services.android.navigation.ui.v5.route.MapRouteArrow.initializeArrowShaft(MapRouteArrow.java:191)
        at com.mapbox.services.android.navigation.ui.v5.route.MapRouteArrow.initialize(MapRouteArrow.java:165)
        at com.mapbox.services.android.navigation.ui.v5.route.MapRouteArrow.<init>(MapRouteArrow.java:106)
        at com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute.redraw(NavigationMapRoute.java:365)
        at com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute.access$000(NavigationMapRoute.java:38)
        at com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute$1.onDidFinishLoadingStyle(NavigationMapRoute.java:331)
        at com.mapbox.mapboxsdk.maps.MapChangeReceiver.onDidFinishLoadingStyle(MapChangeReceiver.java:198)
        at com.mapbox.mapboxsdk.maps.NativeMapView.onDidFinishLoadingStyle(NativeMapView.java:1035)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:326)
        at android.os.Looper.loop(Looper.java:160)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

The class should be refactored to be operational without the Style object and leverage the redraw logic for each style load.

The solution here might also resolve https://github.com/mapbox/mapbox-navigation-android/issues/2027.

Guardiola31337 commented 4 years ago

Was this addressed as part of https://github.com/mapbox/mapbox-navigation-android/pull/2437 Could you confirm @LukasPaczos?

LukasPaczos commented 4 years ago

It wasn't unfortunately. This should be targeted with the UI refactor.