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) {

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');
  • I think you have to elaborate a little bit. There's no getClosestFeatureToCoordinate for ol.source.OSM. How do you get ol.source.Vector with OSM? – Jonatas Walker May 27 '15 at 13:07
  • I was working under the idea Alex was using something like this OSM Vector Tiles – AndyHarney May 27 '15 at 13:26

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:

  • Overpass API can only return objects within a certain radius of a coordinate (or a way, etc.). If there's no result in the given proximity of a point (think middle of the ocean), you need to continue querying with a larger radius until you find something. Unfortunately, there's no other way atm to find the closest point for a given point. – mmd Jun 6 '15 at 17:33

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.