您尝试过整理选项吗???如果不尝试,它可能会解决您的问题。
为此,请从此替换您的矢量层配置:
var vectorLayer = new ol.layer.Vector({
source: vectorSource,style: styleFunction
});
对此:
var vectorLayer = new ol.layer.Vector({
source: vectorSource,style: styleFunction,declutter: true
});
请记住,如果重叠,则杂波应该隐藏标签,并且当缩放级别足以不重叠时,将显示标签。
,
由于缩放级别,我真的看不到它不会重叠的方式,但是要使其更可见,可以尝试下面的示例。
https://codepen.io/gpproton/pen/gOOEjJj?editors=1010
function styleFunction (feature) {
return new ol.style.Style({
text: new ol.style.Text({
text: feature.get('PORT_NAME'),padding: [3,3,3],font: "bold 11px sans-serif",stroke: new ol.style.Stroke({
color: '#ffffff',width: 1
}),fill: new ol.style.Fill({
color: '#000'
})
})
});
};
本文链接:https://www.f2er.com/3058843.html