mapbox / mapbox/mapbox-navigation-android

NavigationMapRoute style dependency

Open
#2,272 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
651
Forks
321
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with NavigationMapRoute.redraw and its onDidFinishLoadingStyle callback, then inspect MapRouteArrow initialization where the duplicate source exception occurs. Refactor the class so it operates with MapboxMap alone and uses redraw on each style load; done means recreating or reloading the route does not add an existing source.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
mobile
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.