【问题标题】:OpenLayers TileLayer, How to switch between force-on/off and zoom-based visibility?OpenLayers TileLayer,如何在强制开/关和基于缩放的可见性之间切换?
【发布时间】:2023-03-22 18:12:01
【问题描述】:

我有一个按钮可以选择:

  • 强制可见
  • 强制隐形
  • 在预配置的缩放级别之间可见。

文档https://openlayers.org/en/latest/apidoc/module-ol_layer_Base-BaseLayer.html 没有指定 visible 和 min/maxResolution 如何一起工作。 我需要能够通过强制可见/不可见来推翻 min/maxResolution。

我有的是这个。

  if (value == 0) { // by zoomlevel
    var mapLayer = wmsLayerDefs[index].mapLayerCfg;
    wmsLayer.setMinResolution(view.getResolutionForZoom(mapLayer.zoomLimits.max));
    wmsLayer.setMaxResolution(view.getResolutionForZoom(mapLayer.zoomLimits.min));
  } else if (value == 1) { //off
    wmsLayer.setMinResolution(view.getResolutionForZoom(0));
    wmsLayer.setMaxResolution(view.getResolutionForZoom(0));
  } else if (value == 2) { //on
    wmsLayer.setMinResolution(undefined);
    wmsLayer.setMaxResolution(undefined);
    wmsLayer.setVisible(true);
  }

选项 2 没有显示任何内容。我也尝试如下,但它没有变得可见。我猜不接受 50 的值。我不知道该反对什么。

  } else if (value == 2) { //on
    wmsLayer.setMinResolution(view.getResolutionForZoom(0));
    wmsLayer.setMaxResolution(view.getResolutionForZoom(50));
  }

选项 1 和 2 是我正在努力使其正确的地方

使用 ecmascript 5 和 ol-5.3.0.js (我不是很精通javascript)

【问题讨论】:

    标签: javascript openlayers openlayers-5


    【解决方案1】:
      } else if (value == 1) { //off
        wmsLayer.setMinResolution(Infinity);
        wmsLayer.setMaxResolution(0);
      } else if (value == 2) { //on
        wmsLayer.setMinResolution(0);
        wmsLayer.setMaxResolution(Infinity);
      }
    

    应该足够了。对于“关闭”,两个设置都为零,或者两个 Infinity 也可以工作。

    【讨论】:

    • 谢谢!我不知道无限是一种选择?
    猜你喜欢
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    • 2011-07-10
    • 1970-01-01
    • 2020-09-22
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多