I am attempting to show text labels for MultiLineString features within a geoJSON file using MapLibre GL JS. By utilizing the symbol-placement: point
option, I aim to display the labels across various zoom levels rather than only when extremely close, as would be the case with the line
option.
...
map.addSource('source_data', {
type: 'geojson',
data: 'sample.geojson'
});
map.addLayer({
"id": "symbols",
"type": "symbol",
"source": "source_data",
"layout": {
"symbol-placement": "point",
"text-field": '{Name}',
"text-size": 40,
"text-justify": "center",
"text-allow-overlap": false
}
});
...
My challenge lies in the fact that when there are multiple lines in the MultiLinestring, MapLibre renders a label for each line, as shown in the image below. Is there a method to display only one text label for each MultiLineString feature?
I have provided a sample of the geoJSON file I am working with (containing the two features from the image) since the original file is extensive: