[英]OpenLayers TileLayer, How to switch between force-on/off and zoom-based visibility?
我有一個按鈕可以選擇:
文檔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)
} else if (value == 1) { //off
wmsLayer.setMinResolution(Infinity);
wmsLayer.setMaxResolution(0);
} else if (value == 2) { //on
wmsLayer.setMinResolution(0);
wmsLayer.setMaxResolution(Infinity);
}
應該足夠了。 對於“關閉”,兩個設置都為零,或者兩個 Infinity 也都有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.