OpenLayers 5为Text添加条件样式

问题描述 投票:0回答:1

我正在尝试将有条件样式的文本添加到我放置在地图上的矢量对象。

我有一个服务,创建看起来像这样的“风格”

let myStyle = new Style(
    {
        fill: new Fill({color: Shade}),
        stroke: new Stroke({color: 'black',width:1}),
        text: new Text({text:Label})

    }) 

这有效,但我似乎无法弄清楚如何根据分辨率有条件地设置样式和显示/隐藏。

任何帮助是极大的赞赏!

angular typescript openlayers openlayers-3 openlayers-5
1个回答
2
投票

您需要将其设为样式函数,例如:

let myStyle = function(feature, resolution) {
  if (resolution < myCondition) {
    return new Style(
      {
        fill: new Fill({color: Shade}),
        stroke: new Stroke({color: 'black',width:1}),
        text: new Text({text:Label})

      });
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.