Skip to content

Add default style handling for NavigationMapboxMap #1692

@danesfeder

Description

@danesfeder

If you initialize NavigationMapboxMap with a theme that doesn't have a LocationComponent style, we will crash when initializing the LocationComponent. We should check we are giving a valid style ID to LocationComponentOptions before activating the component.

2019-01-22 16:57:10.345 26615-26615/com.mapbox.services.android.navigation.app E/Mbgl-MapChangeReceiver: Exception in onDidFinishLoadingStyle
    android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
        at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:213)
        at android.content.res.Resources.getDrawableForDensity(Resources.java:875)
        at android.content.res.Resources.getDrawable(Resources.java:818)
        at android.content.Context.getDrawable(Context.java:606)
        at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:358)
        at com.mapbox.mapboxsdk.location.Utils.getDrawable(Utils.java:75)
        at com.mapbox.mapboxsdk.location.LayerBitmapProvider.generateBitmap(LayerBitmapProvider.java:26)
        at com.mapbox.mapboxsdk.location.LocationLayerController.styleForeground(LocationLayerController.java:303)
        at com.mapbox.mapboxsdk.location.LocationLayerController.applyStyle(LocationLayerController.java:109)
        at com.mapbox.mapboxsdk.location.LocationLayerController.initializeComponents(LocationLayerController.java:92)
        at com.mapbox.mapboxsdk.location.LocationLayerController.<init>(LocationLayerController.java:84)
        at com.mapbox.mapboxsdk.location.LocationComponent.initialize(LocationComponent.java:991)
        at com.mapbox.mapboxsdk.location.LocationComponent.activateLocationComponent(LocationComponent.java:292)
        at com.mapbox.services.android.navigation.ui.v5.map.NavigationMapboxMap.initializeLocationComponent(NavigationMapboxMap.java:549)
        at com.mapbox.services.android.navigation.ui.v5.map.NavigationMapboxMap.<init>(NavigationMapboxMap.java:80)
        at com.mapbox.services.android.navigation.testapp.activity.navigationui.ComponentNavigationActivity.lambda$onMapReady$0(ComponentNavigationActivity.java:131)
        at com.mapbox.services.android.navigation.testapp.activity.navigationui.-$$Lambda$ComponentNavigationActivity$glXHDE3muYJzTzJkSKjDV_sQKt8.onStyleLoaded(Unknown Source:4)
        at com.mapbox.mapboxsdk.maps.MapboxMap.notifyStyleLoaded(MapboxMap.java:835)
        at com.mapbox.mapboxsdk.maps.MapboxMap.onFinishLoadingStyle(MapboxMap.java:202)
        at com.mapbox.mapboxsdk.maps.MapView$MapCallback.onDidFinishLoadingStyle(MapView.java:1164)
        at com.mapbox.mapboxsdk.maps.MapChangeReceiver.onDidFinishLoadingStyle(MapChangeReceiver.java:194)
        at com.mapbox.mapboxsdk.maps.NativeMapView.onDidFinishLoadingStyle(NativeMapView.java:979)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:325)
        at android.os.Looper.loop(Looper.java:142)
        at android.app.ActivityThread.main(ActivityThread.java:6798)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Check here for valid locationLayerStyleRes:

int locationLayerStyleRes = ThemeSwitcher.retrieveNavigationViewStyle(context,
R.attr.navigationViewLocationLayerStyle);
LocationComponentOptions locationComponentOptions =
LocationComponentOptions.createFromAttributes(context, locationLayerStyleRes);
locationComponent.activateLocationComponent(context, map.getStyle(), locationComponentOptions);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDefect to be fixed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions