How does OSM draw the text for road names?

Hi everyone,

I’m busy trying to create a mobile application that allows for offline maps. I’m using extracted OSM data for the geometry I want to render and I’m writing a small OpenGL renderer to render the data on the phone. So far, everything is working great, except, one thing I’m having trouble with are the road names.

How does OSM figure out where it should draw the name of the road? Does it precompute and store points along the road or is it able to work it out in real time using the entire road geometry (this seems computationally expensive for motorways and trunks).

I’ve noticed that with the text on the OSM map, they’re baked into the final rendered tile, but with google maps, the text keeps itself facing the right way, no matter the rotation of the map, so I think its data that renders dynamically on the map. But if they’re rendering it dynamically, how would they go about ensuring the text for the road name follows the curvature of the road without having to retrieve the road geometry every time they want to render the name?

Are there any resources that I can use to learn how OSM decides where to put road names? Or perhaps how text rendering for maps is accomplished in general?

Thanks,

Have you looked at the mapsforge library? https://wiki.openstreetmap.org/wiki/Mapsforge

It takes care of all those details for you.

If you’re still keen on doing it yourself, you might find the source code of interest, regarding the logic for placing labels.