【问题标题】:OpenLayers 5 add conditional style to TextOpenLayers 5 向文本添加条件样式
【发布时间】:2019-04-03 12:55:29
【问题描述】:

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

我有一项服务可以创建如下所示的“样式”

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】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-11-08
      • 2014-11-28
      • 1970-01-01
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-16
      • 1970-01-01
      相关资源
      最近更新 更多