mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
475 stars 133 forks source link

Add layer failed: Layer 'mapbox-location-indicator-layer' is not compatible with source '' #1474

Closed VincentJoshuaET closed 2 years ago

VincentJoshuaET commented 2 years ago

Environment

Observed behavior and steps to reproduce

This works for all our other styles except for one.

binding.mapView.location.updateSettings { enabled = true }

This code will make the app crash with the below error.

com.mapbox.maps.MapboxLocationComponentException: Add layer failed: Layer 'mapbox-location-indicator-layer' is not compatible with source ''
        at com.mapbox.maps.plugin.locationcomponent.LocationLayerWrapper.bindTo(LocationLayerWrapper.kt:23)
        at com.mapbox.maps.plugin.locationcomponent.LocationComponentPositionManager.addLayerToMap(LocationComponentPositionManager.kt:30)
        at com.mapbox.maps.plugin.locationcomponent.LocationIndicatorLayerRenderer.addLayers(LocationIndicatorLayerRenderer.kt:35)
        at com.mapbox.maps.plugin.locationcomponent.LocationPuckManager.initialize(LocationPuckManager.kt:101)
        at com.mapbox.maps.plugin.locationcomponent.LocationComponentPluginImpl$activateLocationComponent$1.invoke(LocationComponentPluginImpl.kt:206)
        at com.mapbox.maps.plugin.locationcomponent.LocationComponentPluginImpl$activateLocationComponent$1.invoke(LocationComponentPluginImpl.kt:184)
        at com.mapbox.maps.plugin.MapDelegateProviderImpl.getStyle$lambda-0(MapDelegateProviderImpl.kt:21)
        at com.mapbox.maps.plugin.MapDelegateProviderImpl.$r8$lambda$prB63jRkHNgIjSUbBTljg7oBEc8(Unknown Source:0)
        at com.mapbox.maps.plugin.MapDelegateProviderImpl$$ExternalSyntheticLambda0.onStyleLoaded(Unknown Source:2)
        at com.mapbox.maps.MapboxMap.getStyle(MapboxMap.kt:360)
        at com.mapbox.maps.plugin.MapDelegateProviderImpl.getStyle(MapDelegateProviderImpl.kt:21)
        at com.mapbox.maps.plugin.locationcomponent.LocationComponentPluginImpl.activateLocationComponent(LocationComponentPluginImpl.kt:184)
        at com.mapbox.maps.plugin.locationcomponent.LocationComponentPluginImpl.applySettings(LocationComponentPluginImpl.kt:357)
        at com.mapbox.maps.plugin.locationcomponent.generated.LocationComponentSettingsBase.updateSettings(LocationComponentSettingsBase.kt:39)
        at com.nobelsystems.geoviewermobile.ui.map.MapFragment.enableLocationComponent(MapFragment.kt:510)
        at com.nobelsystems.geoviewermobile.ui.map.MapFragment.onCreateView$lambda-24(MapFragment.kt:573)
        at com.nobelsystems.geoviewermobile.ui.map.MapFragment.$r8$lambda$yrQD4sfou-QZtQL2gVd3kNMJt1g(Unknown Source:0)
        at com.nobelsystems.geoviewermobile.ui.map.MapFragment$$ExternalSyntheticLambda4.onClick(Unknown Source:2)
        at android.view.View.performClick(View.java:7792)
        at android.view.View.performClickInternal(View.java:7769)
        at android.view.View.access$3800(View.java:910)
        at android.view.View$PerformClick.run(View.java:30218)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Do we need to change anything in the Mapbox style to avoid this?

VincentJoshuaET commented 2 years ago

Just tried in iOS: does not crash, so only a problem on Android.

I don't know why this happens, because on other Mapbox styles I never have this issue.

ank27 commented 2 years ago

@VincentJoshuaET Could you let us know how are you using locationComponent and which style are you referring to ? we have an example that uses same code here for reference.

VincentJoshuaET commented 2 years ago

I use it the same way as your reference but without changing the puck.

Can we link here our own customized style not from Mapbox?

I tried many of our own styles and this did not ever happen before. Also the above style is still working for iOS, so the problem is only on Android, and I can confirm my code is working for all other styles I tried.

VincentJoshuaET commented 2 years ago

I was able to fix it by avoiding adding a source with an empty id. It’s because the location puck layer also uses a source with an empty id.

VincentJoshuaET commented 2 years ago

Maybe you should instead use a source with an arbitrary string ID? So this will not happen to others.

ZiZasaurus commented 2 years ago

@VincentJoshuaET Thank you for this suggestion, will pass it along to the team.

brendanw commented 2 years ago

Also ran into this error printout. Changing the source or layer id did not resolve. Moving

            mapView.location.updateSettings {
               enabled = true
               pulsingEnabled = true
            }

to be after addSource and addLayer calls resolved the issue.