Default labeling in OpenLayers 3.10.1 labels each part of a MultiPolygon. I want to know if it is possible to label only the first polygon in the MultiPolygon.
You can use a separate style for the label with a geometry function, which returns a single point for the label position.
var styles = [
// Style for the label
new ol.style.Style({
text: new ol.style.Text({..}),
geometry: function(feature) {
// expecting a MultiPolygon here
var interiorPoints = feature.getGeometry().getInteriorPoints();
return interiorPoints.getPoint(0);
}
}),
// Style for the polygons
new ol.style.Style({
stroke: new ol.style.Stroke({...}),
fill: new ol.style.Fill({...})
})
];
http://jsfiddle.net/p0acpbtg/2/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With