2017-02-23 620 views
1

我在工作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://stackoverflow.com/help/how-to-ask](http://stackoverflow.com/help/how-to-ask) –

回答

0

可能的問題是:如何跟蹤與方法forEachLayerAtPixel特定層? 因爲顯然總是返回未定義的aka變量未設置。