I'm trying to limit the features returned when I click on the map to just those in the endPoint layer:

    endPoint = new ol.layer.Vector({
            source: new ol.source.Vector({
                features: endPoints //add an array of features

Unfortunately, before this layer is even initialised, whilst clicking on features in other layers they are getting logged to the console. I feel like I'm using the correct syntax to limit the features to just those in the endPoint layer (forEachFeatureAtPixel(pixel, callback, opt_this, opt_layerFilter, opt_this2)) but I must be doing something wrong - if I try to return layer rather than feature it gives me a null value?

Is the issue that I need to name the layer somehow?

    map.on('click', function(evt) {
      var pixel = map.getEventPixel(evt.originalEvent);
      var mapFeature = map.forEachFeatureAtPixel(pixel, function(feature, layer) {
          return feature;
            }, null, function(layer) {
                     return layer === endPoint;
  • Your message is unclear. What is your bug exactly? Do you have features of other layers that pass the filter function? That should not be the case, your usage of the method is good. No others features than the ones belonging to endpoint should pass the filter (put a debugger breakpoint to verify this). Something else in your code must be the cause of this problem.
    – htulipe
    Feb 4, 2015 at 18:59

1 Answer 1


I do my info function this way.

wmsLayer09 is the layer where I want the click search for features, so I only get features from that layer

var feature = map.forEachFeatureAtPixel(evt.pixel,
       function (feature, wmsLyr09) {
          return feature;

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.