OpenLayers 5 为文本添加条件样式

OpenLayers 5 add conditional style to Text

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

我有一个服务可以创建看起来像这样的 "Style"

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

    }) 

这行得通,但我似乎无法弄清楚如何根据分辨率有条件地设置样式和 show/hide。

非常感谢任何帮助!

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

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})

      });
  }
}