Mapnik draws shapes using a painter's algorithm. Objects that are drawn first may be visually obstructed by objects that are painted later.
The paint order of objects is first controlled by the order of the layers - in a TileMill project, layers at the bottom of the list are drawn first and layers at the top of the list are drawn last.
Within each layer, you can control the order of group of styles via Carto attachments. If you don't explicitly create any attachments in Carto, a single default group will be created behind the scenes for all the rules in a layer.
Within each style rule the paint order of objects is defined by the order they are pulled from the datasource. For example, the first result from a database query is painted first, the second result is painted second, and so on. For file-based sources such as GeoJSON or Shapefiles you would have to edit the file in an external program to control this order. For database sources (PostGIS, SQLite) you can adjust the order of the objects with an ORDER BY ...
statement in your query.
Finally, for each individual geometric object within a style the paint order of separate symbolizers is affected by the order in which the symbolizers are defined.
#bottom-layer
::first-attachment
- first object
- first symbolizer
- second symbolizer
- second object
- first symbolizer
- second symbolizer
- first object
::second-attachment
- first object
- first symbolizer
- second symbolizer
- second object
- first symbolizer
- second symbolizer
- first object
#top-layer
::first-attachment
- first object
- first symbolizer
- second symbolizer
- second object
- first symbolizer
- second symbolizer
- first object
::second-attachment
- first object
- first symbolizer
- second symbolizer
- second object
- first symbolizer
- second symbolizer
- first object