Openlayers 3 forEachLayerAtPixel只获取图层

问题描述:

我在工作Openlayers 3。我在地图上添加了三层WMS,顺序如下:Commune,District,Province。我使用“forEachLayerAtPixel”来缩放时获取当前图层的信息。 例如:当缩放到图层区域时再获取信息图层区域,或者缩放到图层公社然后获取信息图层公社。但它只能得到图层省的信息,缩放到图层区时则返回“undefined”。我用事件“pointermove”悬停在地图上:Openlayers 3 forEachLayerAtPixel只获取图层

map.on("pointermove", function (evt) { 
    if (evt.dragging) return; 
    const hit = map.forEachLayerAtPixel(evt.pixel, (layer) => { 
        if (layer instanceof ol.layer.Tile) 
        return layer; 
        return null; 
       }); 
    console.log(hit); 
+0

嗨,你的问题是什么? – feedMe

+0

不要返回图层,否则它将停止搜索。将日志放入回调中。 –

+0

[http://*.com/help/how-to-ask](http://*.com/help/how-to-ask) –

可能的问题是:如何跟踪与方法forEachLayerAtPixel特定层? 因为显然总是返回未定义的aka变量未设置。