1

I'm using openLayers 3.19.1.

When clicking on the map (map.on("click") event ) I retrieve the pixel I clicked on (event.pixel).

I need to get all features in an X radius on the pixel.

There is a function called "forEachFeatureIntersectingExtent" I can execute on the ol.source.Vector, but it needs an "extent" parameter.

How can i convert my pixel to an extent?

If anyone has another idea for getting all features in a specific radius of a click on the map please share.

1

This function answers my question:

public  generateExtentFromPixel(pixel: ol.Pixel, size = 100): ol.Extent {

   let EXTENT_TL = [];
   EXTENT_TL[0] = pixel[0] - size;
   EXTENT_TL[1] = pixel[1] - size;

   let EXTENT_BR = [];
   EXTENT_BR[0] = pixel[0] + size;
   EXTENT_BR[1] = pixel[1] + size;

   let newExtent: ol.Extent = [EXTENT_TL[0], EXTENT_TL[1], EXTENT_BR[0], EXTENT_BR[1]];

   return newExtent;
}

Your Answer

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

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