0

I have a map with some vector layers that deliver popups when the user clicks on the markers. I use a forEachFeatureAtPixel function to identify these layers. However, there are also several background layers which should do nothing if you click on them. After looking through this forum for methods, I am able to exclude one layer from the function, but how would I exclude several layers?

Background1 and background2 are the layers that should not deliver any popups. My code is like this:

var background1 = new ol.layer.Vector...

var background2 = new ol.layer.Vector...

var feature = map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
if (layer != background1) return feature;
});

if (feature) {

//etc.

That works fine, but I also want to exclude background2. I thought I could write "if (layer != background1 || background2) return feature;" but that doesn't work. What should I do?

1
  • Why || and not &&. I mean in terms of logic you want to exclude these two layers, right?. If yes, It should be if (layer != background1 && layer != background2)
    – pavlos
    Jan 25, 2017 at 7:49

1 Answer 1

1

if (layer != background1 && layer != background2)

1
  • We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.
    – mgri
    Jan 25, 2017 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.