【发布时间】:2015-11-02 18:19:23
【问题描述】:
OpenLayers 3.10.1 中的默认标签标记了 MultiPolygon 的每个部分。我想知道是否可以只标记 MultiPolygon 中的第一个多边形。
【问题讨论】:
标签: openlayers-3
OpenLayers 3.10.1 中的默认标签标记了 MultiPolygon 的每个部分。我想知道是否可以只标记 MultiPolygon 中的第一个多边形。
【问题讨论】:
标签: openlayers-3
您可以使用带有geometry function 的标签使用单独的样式,这会为标签位置返回一个点。
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。
return interiorPoints.getPoint(1);,它将以另一个多边形为中心。如何让它以整个多面体为中心?