0

I have defined coordinates. I need to know if there is any way to know the layers or features that exist in those coordinates. Is that possible?

I have used the following function, but this does it with respect to the map pixels and I want with respect to some coordinates

var result = ol_interaction_Snap.prototype.snapTo.call(this, pixel, pixelCoordinate, map);

    if (result.snapped) {
        var p = map.getPixelFromCoordinate(pixel);
        var feature = map.getFeaturesAtPixel(p);
        this.dispatchEvent(new mgis_ObjectEvent("aftersnap", feature));
    }
    return result;
  • Did you try the function above along with https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html#getPixelFromCoordinate ? – Marcin Oct 09 '19 at 14:21
  • Yes, it still doesn't work. I enclose the code of what I want to do. I have specific coordinates and I want to know if there are features in those coordinates. I modify the code of the main publication in case you can help me. – joseantonio Oct 09 '19 at 15:04

1 Answers1

1

Use getFeaturesAtCoordinate or getFeaturesInExtent for the sources of your map.
Just create a small extent around your coords.

var extent = ol.extent.boundingExtent([ coordinate ]);
extent = ol.extent.buffer(extent, .1); 
// test if features 
if (source.getFeaturesInExtent(extent).length) { 
... 
}
Viglino Jean-Marc
  • 1,371
  • 8
  • 6