簡體   English   中英

Openlayers:如何判斷 map 上的圖層是否可用

[英]Openlayers: How to tell if a layer is available on the map

我有個疑問。 在openlayers中,我應該如何知道是否添加了圖層或map? 比如我有一個圖層控件,要看那個圖層在map上是否可見。

在 Leaflet 我是這樣用的

my_layer_leaflet.on("add",function(){
);

在開放層中?

var my_layer_openlayers = new ol.layer.Vector({
    title: 'MyLayer',
    visible: false,
    style: new ol.style.Style({
        image: new ol.style.Icon( ({
            anchor: [0.5, 26],
            anchorXUnits: 'fraction',
            anchorYUnits: 'pixels',
            src: 'legend/image.png'
        }))
    }),
    source:  new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: function(extent) {
        return layer_geoserver;
        },
        strategy: ol.loadingstrategy.all,
    })
});

在 layerGroup 中放置一個圖層,並向“change:layergroup”事件添加一個偵聽器:

var baseLayerGroup = new ol.layer.Group({layers: [layer_geoserver]});     
map.on("change:layergroup", function() {console.log("LayerGroup changed.")});
map.setLayerGroup(baseLayerGroup);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM