Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Openlayers 3 将多多边形要素的标签限制为一个标签_Openlayers 3 - Fatal编程技术网

Openlayers 3 将多多边形要素的标签限制为一个标签

Openlayers 3 将多多边形要素的标签限制为一个标签,openlayers-3,Openlayers 3,OpenLayers 3.10.1中的默认标签为多多边形的每个部分添加标签。我想知道是否可以只为多边形中的第一个多边形添加标签。您可以为标签使用单独的样式,该样式将返回标签位置的单个点 var styles = [ // Style for the label new ol.style.Style({ text: new ol.style.Text({..}), geometry: function(feature) { // expecting a Mu

OpenLayers 3.10.1中的默认标签为多多边形的每个部分添加标签。我想知道是否可以只为多边形中的第一个多边形添加标签。

您可以为标签使用单独的样式,该样式将返回标签位置的单个点

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({...})
  })
];

太棒了<代码>+1。。。所以不喜欢
+1
。工作起来很有魅力!太棒了,对我来说不太管用。它以多多边形中的一个多边形为中心。如果我将其更改为
返回interiorPoints.getPoint(1)它以另一个多边形为中心。我怎样才能把它作为一个整体集中在多边形上?是的,对。它以第一个多边形的内部点为中心。但是,您可以计算所有多边形的凸包(使用JST或Turf.js),然后获取该多边形的内部点。或者取多重多边形范围的中点。适合我使用。谢谢