将标签限制为MultiPolygon功能的一个标签

Enz*_*nzo 4 openlayers-3

OpenLayers 3.10.1中的默认标签标记MultiPolygon的每个部分.我想知道是否可以只标记MultiPolygon中的第一个多边形.

tsa*_*ein 7

您可以为带有几何函数的标签使用单独的样式,该函数返回标签位置的单个点.

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({...})
  })
];
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/p0acpbtg/2/