-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support user-specified feature z-indexing / sorting across layers #1349
Comments
Currently: Style layers are the main thing that define draw order. Within a style layer, features are drawn in the order they appear in the data. We could implement a To make it work across different classes of roads (main, motorway, etc) I think we'd need to draw all roads with one style layer. To make this possible, we would need to support functions that are both data-driven and dependent on zoom level. Other approaches I think would not work well: Another way to implement this would be to split layers into many sublayers. Imagine if you made a separate style layer for each Or we could use the depth buffer. Each feature would have a z value partially based on the How important is this? In https://github.com/mapbox/mapbox-gl-custom-styles/issues/129 Emerald's ordering looks ok in this case. I'm sure it breaks in other cases, but if those cases are rare enough it should be ok |
It isn't terribly rare. Sometimes surface streets pass over highways, sometime under. Usually you can rely on one or the other being a bridge or tunnel, but that assumption breaks in urban areas. In my example, there happened to be a river beneath both roads. But cities often have things like double-decker bridges or complex highway interchanges that involve multiply stacked bridges. The good news is that if one motorway bridge overlaps another, the two bridges receive a common casing. As long as no one wants to case the bridges individually, as in the openstreetmap-carto style, the main fallout is just the inconsistent over/underlapping in the screenshot above. |
See #733 for a report of the issue in the wild. |
@ansis @1ec5 thanks for the feedback. I talked to @ajashton about this, and as a temporary solution to this, we can try adding a few strategic additional style layers to help alleviate some of the most common cases of incorrect overlapping. We can split up a few of the bridges classes into different layers by additionally filtering on the
We took a quick look at taginfo. Roughly 2.5% of highways have a layer tag. About 95% of layer values are -1, 0, and 1 (most roads on the ground are These are super rough figures, since I'm generalizing from the breakdown of layer values overall, and not specifically for highways. Also, we cannot tell the breakdown of highway classes by layer value with this information. I did a quick visual scan in the editor, and although it looks like most of the highways with @ajashton is going to a bit of postgis querying to get more accurate info. My sense is that we are not going to be able to cover the majority of cases without creating a bunch of additional style layers – but even adding a few layers will be better than nothing, and we can implement that in the styles right away without any rendering or style spec changes. Regarding possible longer-term solutions:
@ansis would it also be straightforward to sort features by multiple fields? E.g. sort first by
In general we need to implement this in order to use data-driven styles for most basemap styling. Is this going to be something we consider doing? |
If I’m not mistaken, this is probably because JOSM issues a strict “Crossing ways” validator warning for bridges and tunnels without
This looks like a big number, but it’s mitigated somewhat in the styles in mapbox/mapbox-gl-styles because individual bridges don’t receive casing that would cut across overlapping bridges. It could be more prominent in other styles, though. |
This is a stretch, but if we did implement |
Yeah, I think in a lot of cases (like in the Boston example) the result is often just roads that look like they're intersecting when actually one is going above the other. |
This is also the way we should use OpenGL rendering; adding 30-60 style layers will produce more draw calls which will ultimately make rendering slower. |
What are the current thoughts on adding "group-by"? |
@stirringhalo Nothing beyond what's posted here. We're hoping that data-driven styling will reduce the need for this feature. |
@lucaswoj Sounds good, I'm following your data-driven property functions for line attributes. Excited to start using that. |
There are no blockers left to implementing this! We have zoom-and-property functions now. |
Here's an example of how to achieve z-order control in one layer with data-driven styles and Without z-indexing this is method does not help with vector tile sources. |
Closing as a duplicate of #4361 (since that issue has a more concrete proposal) |
I believe this is not a duplicate, as this feature is required across a data layer, not just a single style layer. Some of the needs for this feature could be partially alleviated by #4361 though. |
@nickidlugash - I'm not sure I follow the distinction between sorting across a data layer vs. a style layer -- could you say more? It sounds like if tunnels, roads, and bridges are already tagged with a layer number (#1349 (comment)), and you could render all of those features in a single layer styled with DDS (#1349 (comment)), then you could use the existing layer tags to populate the I do see your request for sorting by class as a separate feature request distinct from cc/ @ajashton |
Since I wrote that, iD started adding
Consider that a style might generally render motorways above residential roads (based on importance) but would make exceptions for residential overpasses over motorways. Perhaps that would be feasible with #4361 as long as the |
@chloekraw We commonly use a styling technique that uses road "casings" underneath the main road lines to visually indicate the grade separation (denoted by the Aside from this, there are other reasons why it is currently difficult to combine all roads into one style layer:
|
This addresses 2 related bugs: 1. An unevaluated mapbox expression-object was used in a condition (`if (expression)`) to decide if sorting was necessary, the assumption was probably that the default constant value of `undefined` would skip sorting. However, the unevaluated mapbox expression is not the value `undefined`, but an expression-object describing the value and its type. So, even if the mapbox expression was a constant `undefined`, the check would never be true. This leads to a lot of unnecessary sorting. This was already correct for the drawing sort in circles and symbols, and this is where the `sortFeaturesByKey` variable name originates. 2. Even where the check was correct, it would explicitly check if the sort-key was a constant with value `undefined` to skip sorting. However, we also know that the sort-key is irrelevant if it's *any* constant, not just `undefined`. Note that the second optimization would not be possible if cross-layer sorting was implemented (see mapbox/mapbox-gl-js#1349). I'm unable to provide good performance benchmarks because of #76.
In Mapnik, group rendering is used to render roads in the correct z-order. For background: @kkaefer's PR. This grouping is declared in Mapbox Studio projects in the yml:
We are currently ignoring the z-ordering, which is affecting mainly the bridges layers:
What would it take to implement something like this in GL? What would be the performance implications? I'm assuming this also requires a style-spec change. A
group-by
property would need to be defined by data layer, though, not by style layer./cc @kkaefer @ansis @1ec5 @jfirebaugh @mourner @ajashton
The text was updated successfully, but these errors were encountered: