Is there a way to get osm_id of the point that is closest to a given coordinate.
The idea is to click on map and get the osm_id
map.on('click', function(event) {
window.alert(event.coordinate);
});
You can by using ol.source getClosestFeatureToCoordindinate() and feature get().
Assuming your OpenStreetMap data is loaded into ol.source.Vector called osm.
map.on('click', function(event) {
var osm_id = osm.getClosestFeatureToCoordinate(event.coordinate).get('osm_id');
window.alert(osm_id);
)}
getClosestFeatureToCoordinate
for ol.source.OSM
. How do you get ol.source.Vector
with OSM?
Commented
May 27, 2015 at 13:07
Returning objects at a given location is possible via Overpass API.
Unfortunately I don't have a full example. But if nobody else comes up with an example I can at least provide you some helpful links: