简体   繁体   English

OpenLayers TileLayer,如何在强制开启/关闭和基于缩放的可见性之间切换?

[英]OpenLayers TileLayer, How to switch between force-on/off and zoom-based visibility?

i have a button to select either:我有一个按钮可以选择:

  • Force Visible强制可见
  • Force Invisible强制隐形
  • Visible between preconfigured Zoom-levels.在预配置的缩放级别之间可见。

The doc https://openlayers.org/en/latest/apidoc/module-ol_layer_Base-BaseLayer.html doesn't specify how the visible and min/maxResolution work together.文档https://openlayers.org/en/latest/apidoc/module-ol_layer_Base-BaseLayer.html没有指定 visible 和 min/maxResolution 如何协同工作。 i need the min/maxResolution to be able to be overruled by forcing visible/invisible.我需要 min/maxResolution 能够通过强制可见/不可见被否决。

What i have is this.我有的是这个。

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

Option 2 isn't showing anything.选项 2 没有显示任何内容。 i also tried as below, but it's not becoming visible.我也试过如下,但它没有变得可见。 i guess the value for 50 isn't accepted.我猜 50 的值不被接受。 i don't know against what to clamp it.我不知道反对什么夹紧它。

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

Options 1 and 2 is where i'm struggling to get it proper选项 1 和 2 是我努力使其正确的地方

Using ecmascript 5 and ol-5.3.0.js (i'm not that well versed in javascript)使用 ecmascript 5 和 ol-5.3.0.js(我不太精通 javascript)

  } else if (value == 1) { //off
    wmsLayer.setMinResolution(Infinity);
    wmsLayer.setMaxResolution(0);
  } else if (value == 2) { //on
    wmsLayer.setMinResolution(0);
    wmsLayer.setMaxResolution(Infinity);
  }

should be sufficient.应该足够了。 For "off" having both settings zero, or both Infinity would also work.对于“关闭”,两个设置都为零,或者两个 Infinity 也都有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM