Search code examples
dictionaryleafletopenstreetmap

Draw street using leaflet and osm


I'm trying to create a map which will show streets (roads, paths...) in some context. I only found how to draw polygons and ploylines, but drawing a street, with curves, using some sort of street-Id or geographical data, this I couldn't figure.

Is it even possible? or do I need to switch from leaflet?

Thank you.


Solution

  • drawing a street, with curves, using some sort of street-Id or geographical data

    Using leaflet (or any other front-end library), there is no direct way to transform geographical data (I suppose you mean lat-lon points) into street polylines. And there is a reason for this: leaflet does not "understand" the geometry of the roads from raster tiles.

    However, you can still add street polylines to your OSM basemap with the actual street geometry, using lat-lng coordinates but you will need to use an API.

    This process is called map matching and there are several APIs that to this (not free). You send raw data (lat-lng coordinates) to the API and you get a response of a polyline that is matched to the actual OSM road geometry. Search for OSM Map Matching API and you will totally find some APIs to start with.

    You could also implement your own back-end solution. One of the above APIs, the Open Source Routing Machine (http://project-osrm.org/) lets you build your own back-end service. You could go even further and build a custom back-end solution.