I would like to set the Z-ordering of the polygons on my MapBox GL JS vectortile layer with only one vector tile source. There is a "category" attribute with values: 1 and 2. Polygons with category 2 should be on the top.
This is the definiton of my layer:
map.addLayer({
'id': 'testLayer',
'type': 'fill',
'source': 'testSource','source-layer': 'polygons',
"paint": {
'fill-color': { "property": "cat",
"type": "categorical",
"stops": [
[1, "#8dd3c7"],
[2, "#ffffb3"]
]}
}
});
How can I set Z ordering?
I'vew find this: https://docs.mapbox.com/help/troubleshooting/optimize-map-label-placement/
Order of features inside layers For each layer in your style, you must specify a source. For vector sources, you must also specify a source layer for each style layer. The draw order of features inside a single vector tileset source layer can be specified in two ways: At runtime with symbol-sort-key: If you don't have control over the data at the time of tileset creation, you can influence the draw order of features at runtime using symbol-sort-key.
How to use it? I don't know the syntax and I didn't find any examples.
UPDATE: I tried with symbol-sort-key, but I got this error: "unknown property "symbol-sort-key""
map.addLayer({
'id': 'testLayer',
'type': 'fill',
'source': 'testSource','source-layer': 'polygons',
'layout': {"symbol-sort-key": ["to-number", ["get", "cat"]]},
"paint": {
'fill-color': { "property": "cat",
"type": "categorical",
"stops": [
[1, "#8dd3c7"],
[2, "#ffffb3"]
]}
}
});