TransWikia.com

OpenLayers forEachLayerAtPixel doesn't get actual pixel color when the layer's opacity is not 1

Geographic Information Systems Asked on May 18, 2021

I recently upgraded OL 4.x to 6.4.3 and got a problem with forEachLayerAtPixel. Previously forEachLayerAtPixel returned actual pixel color regardless of the layer’s opacity though, it returns rendered color on the map instead of the pixel color when the opacity is 1.

Currently it’s getting rgb of the faded color due to the opacity.
Is there any way that I can get actual pixel color regardless of the layer’s opacity?

Here is my code;

map.forEachLayerAtPixel(
      evt.pixel,
      (layer, pixel) => {
        if (pixel) {
          layerRgb = { r: pixel[0], g: pixel[1], b: pixel[2] };
        } else {
          layerRgb = null;
        }
      },      
      {
        layerFilter: function (layer) {
          return layer.get("name") === "county";
        }
      }
    );

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP