tangrams / tangram-docs

Documentation for the Tangram map renderer
https://tangrams.readthedocs.io/
MIT License
50 stars 27 forks source link

Explain concepts behind ordering #138

Open pnorman opened 8 years ago

pnorman commented 8 years ago

Most people with a web background will be used to the ordering model of layers then an order within the layers. Tangram's is substantially different. There is relatively little documentation on Tangram's ordering or how it differs.

The order mapping is documented as

Applies to all draw styles. Sets the drawing order of the draw style, to be used in case of depth collisions. Higher-ordered layers will be drawn over lower-ordered layers. Child layers override parent layers.

Depth collisions are undefined, as is depth.

Higher-ordered layers will be drawn over lower-ordered layers.

order is a property of draw groups which then belong to a layer or sublayer. Layers are part of the layers element which is a YAML mapping, so layers have no YAML order.

When rendering from MVT there are two additional orders: layer order within the tile and feature order within a layer. How do these come into play?

I would expect the overall order to be draw order, layer order, then feature order but I can find nothing documenting this.

meetar commented 8 years ago

Thanks for this feedback – I'll use this thread to track the changes I make to address the issue, starting with: https://github.com/tangrams/tangram-docs/commit/a371101bf5703d3ec4af48a0871a7687088ab05f

pnorman commented 8 years ago

With some testing with lines coming from the same MVT layer and the same tangram order I found out that the top-most object is the is one which comes first in the MVT ordering, the reverse of expectations.

E.g. normally in a roads layer you'd want "high value" roads to to the end in an ascending sort. This is reflected in the osm2pgsql z_order which puts motorways high so they will be at the end of a layer if that layer sorts by z_order. This is because conventional algorithms draw the first object in the layer first and later ones on top of it.

Tangram requires the reverse of this.

pnorman commented 8 years ago

Another factor that comes into ordering is the name of the styles.

If I have

styles:
    z:
        base: lines
        dash: [2, 2]
        dash_background_color: blue
layers:
    roads:
        data: { source: mapzen }
        draw:
            lines:
                order: 2
                color: green
                width: 14
            z:
                order: 2
                color: black
                width: 6

I get a different result if I change the name of the style object to "a" image with z and image with a.

nvkelso commented 8 years ago

That’s correct, names sort A to Z within the same order (or default order if not defined). I think this was a modification a couple versions ago in Tangram to add some amount of determinism (and consistent determinism between JS and ES).

On Tue, Aug 23, 2016 at 2:48 PM, Paul Norman notifications@github.com wrote:

Another factor that comes into ordering is the name of the styles.

If I have

styles: z: base: lines dash: [2, 2] dash_background_color: bluelayers: roads: data: { source: mapzen } draw: lines: order: 2 color: green width: 14 z: order: 2 color: black width: 6

I get a different result if I change the name of the style object to "a" [image: image] https://cloud.githubusercontent.com/assets/1190866/17910982/4d2fc662-6940-11e6-95bf-ca5858dbd7a7.png with z and [image: image] https://cloud.githubusercontent.com/assets/1190866/17910992/5f42a8f6-6940-11e6-899b-5f2d74d2bb34.png with a.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tangrams/tangram-docs/issues/138#issuecomment-241890843, or mute the thread https://github.com/notifications/unsubscribe-auth/AA0EO9V2PFYL40rJy5rpGBvARvMrX85Uks5qi2qjgaJpZM4JpQhQ .