将标签限制为 MultiPolygon 特征的一个标签
Restrict labeling to one label for MultiPolygon features
OpenLayers 3.10.1 中的默认标记标记了 MultiPolygon 的每个部分。我想知道是否可以只标记 MultiPolygon 中的第一个多边形。
您可以为带有 geometry function 的标签使用单独的样式,returns 标签位置的单个点。
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({...})
})
];
OpenLayers 3.10.1 中的默认标记标记了 MultiPolygon 的每个部分。我想知道是否可以只标记 MultiPolygon 中的第一个多边形。
您可以为带有 geometry function 的标签使用单独的样式,returns 标签位置的单个点。
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({...})
})
];