[GIS] How to get the polygon defining a road when I have the way’s `osm_id`

openstreetmap

I have the osm_id of various roads defined in OpenStreetMap and I am trying to get the polygon defining the road. How might I do this, preferably in JavaScript and preferably without downloading data from OSM to my own server. I am new the whole GIS ecosystem so I apologise if my question does not make sense because I misunderstood something.

What I intent to do is to highlight certain roads on my map and for that I thought of adding a new layer (I am using Mapbox.js) which would contain a coloured polygon over the road I'm trying to highlight.

Best Answer

You can use OSM's regular API for fetching the OSM way via its ID. Example: https://www.openstreetmap.org/api/0.6/way/136322077/full

The /full is important for fetching all of its nodes, too. The nodes define the geometry of the way. The order of the nodes is defined by the <nd ref> elements of the way. See OSM XML for more information.

Also read about when not to use this API and the API usage policy. Since this is the editing API it is not meant for bulk queries.

Related Question