Openlayers 3 forEachLayerAtPixel get only layer

1.5k Views Asked by At

I am working Openlayers 3. I added three layers WMS on the map in order as follows: Commune, District, Province. I used "forEachLayerAtPixel" to get information of the current layer when zoom. Example: When zoom to layer District then get information layer District, or zoom to layer Commune then get information layer Commune. But it only get information of layer Province, when zoom to layer District then return "undefined". I used event "pointermove" for hover on the map:

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

There are 1 best solutions below

0
On

Probably the question is: how to trace a specific layer with the method forEachLayerAtPixel? since apparently is always returning undefined aka variable not set.