1
votes

I'm new to using Mapbox.

I'm trying to add a new layer to my map that is above the water layer but below labels.

map.addLayer({
    'id': 'maine',
    'type': 'fill',
    'source': 'maine',
    'layout': {},
    'paint': {
        'fill-color': '#088',
        'fill-opacity': 0.8
    }
}, 'water');

(This code was taken from some example code from Mapbox.)

Right now, this creates a layer that is below the water layer and the labels. However, I can't figure out what layer ID would bring it above the water layer.

This is the stylesheet I'm using:

mapbox://styles/mapbox/light-v9

How do I find the other valid layer ID's for this style sheet? I've tried 'streets', 'roads', 'road', 'land', etc, but nothing has worked. I thought this link included all the layer names:

https://www.mapbox.com/studio/styles/mapbox/light-v9/

but the only one that keeps my new layer from just being on top of everything is 'water'. Help!

2
If my question doesn't help, can you post a live sample of your code?RobLabs

2 Answers

1
votes

You can experiment in Mapbox.com/studio by adding your maine tile set into a new style, then you can move the layer interactively to experiment and proof the effect that you want.

The second parameter for addLayer is before, so your maine source should've gone before the water layer. See the docs on addLayer for details

https://www.mapbox.com/mapbox-gl-js/api/#Map#addLayer


The names of the layers are identified by "id" in the Style.json.

You can find the names of the layers by going to the link you posted

The water layer is near the bottom of the layers stack of the Mapbox light style.

Here are the layers with water in the "id.

        "id": "waterway-river-canal",
        "id": "water shadow",
        "id": "water",
        "id": "waterway-label",
        "id": "water-label",
0
votes

Your layer ID can be found by opening your map in Mapbox Studio. If you go to View style details (the box with an arrow in the top right corner of the left hand window, it will reveal all the layers.