Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not find layer Exception when trying to add the location component above another layer #3171

Open
EllisGlaeser opened this issue Jan 22, 2025 · 0 comments
Labels

Comments

@EllisGlaeser
Copy link

MapLibre Android Version

11.5.1

Android SDK Version

14

Device

Google Pixel 8

What happened?

I wanted to update the location component to display as the 2nd to top layer, since I noticed that there was a layer or two on top of it at times.
When trying to provide a .layerAbove() to place it right below the top layer, I get

org.maplibre.android.style.layers.CannotAddLayerException: Could not find layer: mapbox-android-symbol-layer-2

No matter what layer I pass here, it crashes with the same exception.

Steps to reproduce

I added .layerAbove(), as in the following:

LocationComponentOptions.builder(TopoMapsActivity.instance)
     .layerAbove(aboveLayerId)
     .accuracyColor(Color.parseColor("#18620f"))
     .accuracyAlpha(0.2F)
     .build()

where the aboveLayerId is from a SymbolManager that is created just prior.

I passed the same style to the LocationComponentActivationOptions that uses this options builder that I used to create the SymbolManager.
The location component is the last thing I set up when initializing the map, and I set up all my other SymbolManagers, LineManagers, etc. using the aboveLayerId parameter with no problem, but here I get

When I use the debugger and put a breakpoint before activating the location component, I can see that this symbol layer is in the Style object, and if I even get a layer id from the layers list in the style, it crashes with that too.

Another interesting thing is that it doesn't crash if I use layerBelow(), but it doesn't produce the behavior I expected.
For example, in the following snippet, the LocationComponent would still show below everything else:

val symbolManager1 = SymbolManager(mapView, map, style)
// Put symbolManager2 directly below symbolManager1
val symbolManager2 = SymbolManager(mapView, map, style, symbolManager1.layerId) 
// Try to put the LocationComponent below symbolManager1
val locationComponentOptions =
                    LocationComponentOptions.builder(TopoMapsActivity.instance)
                        .layerBelow(symbolManager1.layerId)
                        .accuracyColor(Color.parseColor("#18620f"))
                        .accuracyAlpha(0.2F)
                        .build()
// rest of initialization code

I tried using the layer id for the LocationComponent's foreground layer as the layer above symbolManager2 which works, but it has several layers that get spread about so only the foreground layer gets displayed in the right spot.

Am I missing something? I tried just initializing the location component last, thinking that it would be added to the map last and would be displayed on top, but that doesn't work either.

Renderer

No response

Relevant log output

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant