-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Documentation: using addLayer() to insert layer before, the 'before' is unclear #4690
Comments
Do you have a suggestion on how to improve? To me it seems pretty clear "the addLayer method takes 2 arguments: the layer as an object, and a string representing another layer's name." and in the api doc "The ID of an existing layer to insert the new layer before. If this argument is omitted, the layer will be appended to the end of the layers array."
I wonder if this should just be a warning or an error? |
It's unfortunate that the Here's a first try for improvement ...
|
Mapbox's API design doesn't usually throw errors if an Printing an error would be ideal as long as code execution continues, that is, not a |
The Mapbox Streets style doesn't have a "water" group so not sure where you're seeing that? Layer groups are specific to Mapbox Studio, GL JS and the style spec don't mention groups so I'm not sure if it's a good idea to mix in concepts like layer groups, unless they are added to the style spec. |
@andrewharvey The only way I could find out where the "water" comes from is here: https://www.mapbox.com/studio/styles/mapbox/streets-v9/ (near the bottom) The terminology is an issue, but it's out of the scope of this issue. Second try...
|
I see where you're coming from now, the "groups" in ^ are actually the source-layer which is from the Mapbox Streets v7 Tileset, not the Style Layer. If you open it up in Studio eg. https://www.mapbox.com/studio/styles/mapbox/streets-v9/edit/ you'll get the layer id's listed on the left, or just download the Style JSON to inspect the layer's https://api.mapbox.com/styles/v1/mapbox/streets-v9?access_token=ACCESS_TOKEN |
ps #4225 discusses different solutions to make it easier to insert layers in a Style without relying on an arbitrary layer id. |
Oh dear, the suggestions in #4225 are way more complicated than it needs to be. Thanks @andrewharvey. I'll take it from there. |
I had a go at implementing a warning, something like https://github.com/mapbox/mapbox-gl-js/compare/4690-warn-non-existant-before seems to work. |
@andrewharvey That looks great. Can you enumerate the available layers to further avoid confusion? e.g.
|
mapbox-gl-js version: 1.0.0-beta6 documentation
In the example of https://www.mapbox.com/mapbox-gl-js/example/geojson-layer-in-stack/, it's not clear that "water" is a Layer or a Layer Group. I keep trying Layer Groups (e.g. "road", or "poi_label"), when in fact what I needed was something like "poi-scalerank4-l15".
The only reason I realised my mistake was because I found https://www.mapbox.com/blog/labels-on-top/ hours later.
An improvement might be a clearer message in the example code, as well as a warning in the console that the layer doesn't exist.
The text was updated successfully, but these errors were encountered: