Determining draw order for ways in same layer

How can I calculate the correct draw order for ways and relations within the same layer, to ensure that different features are rendered correctly?

For instance relation 3153328 is a large meadow with loads of features contained within. How do renderers “know” to draw the meadow first and overlay everything else contained within on top of it?

There must be some fixed rules or logic that ensures predictable results, but I don’t know what it is.

Its quite simple to order features using layer tag, so bridges appear over other roads for example, but many features dont have one assigned and yet maps know how to draw them correctly.

If anyone has any information on this I’d be very interested. Thanks very much!

The renderer can do many fancy things, and even if you know one, you can’t be sure what the other will do. And this is not even your job as a mapper to define what is “correct”, because it is decision what and how do you want to show things, not the ultimate “correctness”.

For example underground map will most probably show tunnels on top, even if in reality they are not visible on the ground. But this is just an example, maps can be just very different.

In case of default style on OSM.org (osm-carto style, I co-develop) here is a part of how it determines the order of areas (however there is no “global” ordering there):

https://wiki.openstreetmap.org/wiki/Standard_tile_layer#Rendering_order

on rule is: bigger polygons first, smaller later.

not allways but very often.

regards
walter

ps: this may change on every new release of the carto style.

Thanks for your reply. I’m speaking as a developer interested in how this is achieved, rather than as a mapper. Apologies if I should have asked in a different place.

But yeah, I was basically interested in how the default map style on OSM calculates this and I think you have provided the answer in the link where it says “Landcover areas are ordered by area, with smaller ones later and collisions are allowed. It means that for a given layer smaller areas will cover larger”.

So it seems, given a subset of map data, its required to order features by area size and draw them in that order.
That makes perfect sense, so I’ll try and implement that and see how I get on. Thanks for clearing that up for me, so quickly :slight_smile:

Edit: thanks Walter for confirming this too.

Another “draw order” thing that’s perhaps worth mentioning is the z_order handling for roads that OSM Carto uses: https://github.com/gravitystorm/openstreetmap-carto/blob/master/openstreetmap-carto.lua#L180 .

Very helpful, thanks.
I’d assumed a similar fixed draw order for roads, but its good to know what the standard is.