In Mapbox Studio you can control the drawing order of your labels by using the symbol-sort-key property in your symbol layer. This property accepts a numeric value for each feature, and when two symbols overlap, the one with the higher sort key is drawn on top.
To sort your labels based on the “Hectares” field, follow these steps:
-
Select Your Symbol Layer:
Open your style in Mapbox Studio and choose the symbol layer that contains the labels you want to sort.
-
Edit the Layout Properties:
In the layer’s settings, locate the Layout section where the symbol-sort-key property can be added or edited.
-
Set the symbol-sort-key Expression:
Enter an expression that retrieves the value of your “Hectares” field. If your field is already a numeric value, you can use:
"symbol-sort-key": ["get", "Hectares"]
If your “Hectares” field is stored as a string or you want to ensure it’s interpreted as a number, use:
"symbol-sort-key": ["to-number", ["get", "Hectares"]]
-
Optional - Adjusting for Order:
By default, features with a higher “Hectares” value will be drawn on top. If you need the reverse (so that lower values are drawn on top), you can multiply the value by -1:
"symbol-sort-key": ["*", -1, ["to-number", ["get", "Hectares"]]]
-
Save and Publish:
After setting your expression, save the changes and publish your style. The labels will now be sorted based on the “Hectares” field.
This approach uses Mapbox’s data-driven styling capabilities, ensuring that your labels’ z-order reflects the relative sizes (or areas) specified in your dataset.