OpenLayers文本标签即使有填充也会重叠

Ol文档指出,可以在文本标签上使用填充来进行整理。 ol/style/Text

但是即使我指示“填充”,我的标签仍然重叠。

关于代码笔的实时示例:https://codepen.io/sjvmarigerr/pen/oNNVMXb?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 15px sans-serif"
    })
  });};
leqihuan 回答:OpenLayers文本标签即使有填充也会重叠

您尝试过整理选项吗???如果不尝试,它可能会解决您的问题。 为此,请从此替换您的矢量层配置:

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

大家都在问