0

I'm trying to use map.forEachLayerAtPixel in OpenLayers to see what layers are clicked, but I have a layer in the background that is a grid served by Mapserver with a grid.map file that is just a bunch of outlines.

The grid.map file has an OUTLINECOLOR but no COLOR to fill it so it's transparent inside the polygon.

However, this code does not show me as having clicked inside the grid.map polygon when I do:

map.forEachLayerAtPixel(evt.pixel, function(layer) {
  var title = layer.get('title');
  console.log(title);
}

If I put a COLOR in the grid.map file it works great but I'd like to keep it transparent.

EDIT: I've tried 2 different STYLE blocks as noted in MapServer - Show Polygon Layer with non-transparent border and transparent background and still have the same issue where it works if I set OPACITY to 1 but not as soon as I set it to 0.

What am I missing to keep a polygon transparent but still be recognized by map.forEachLayerAtPixel?

  • 2
    Try using 1% opacity. OpenLayers should detect anything except fully transparent. – Mike Feb 7 '19 at 20:47
  • Thanks, guess that is the best solution after all. – Andrew T Feb 8 '19 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.