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
Convert Mapbox Streets V6 example style to flat format #15413
base: main
Are you sure you want to change the base?
Conversation
a53d034
to
4a95e95
Compare
Evaluation contexts are now initialized with every properties set to UNKNOWN_VALUE. If an expression needs an input which is unknown, it will return UNKNOWN_VALUE.
4a95e95
to
2382682
Compare
This will be used to filter out features that will eventually be rendered
…e types Previously the style parser was having this responsibility. Now reading from feature attributes and style variables is done in the gpu compiler logic
This avoids a crash if a prop or var is not defined at runtime
This required compiling all the maki icons to a spritesheet Done using https://github.com/flother/spreet The MapboxStreetsV6 style was converted with partial automation
This was also taken into account for the cpu and gpu compilers. The GPU compiler uses the CPU compiler to evaluate var/get names at compile time
This operator is evaluated on the CPU at compile time, which means that it won't have access to runtime values (feature props, variables etc.)
2382682
to
e6bee20
Compare
📦 Preview the website for this branch here: https://deploy-preview-15413--ol-site.netlify.app/. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a few remarks about geometry-type
. The rest looks good.
Just a note on the streets-v6 example style: Use caution, I think it is not the best reference for what needs to be supported - it was a very early attempt a long time ago to get Mapbox data rendered with a minimal sensible style, and its origin was a loose manual translation of some layers of the old streets-v6 Mapbox style.
'all', | ||
['==', ['get', 'layer'], 'aeroway'], | ||
['==', ['geometry-type'], 'Polygon'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this work implicitly, without the geometry-type
filter? I'd expect when I specify a style with a fill-color
that it's applied to a polygon. Other geometry types cannot be styled with a fill-color
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had been thinking we would add things like hasFill
, hasStroke
, and hasPoint
to the parsing context. Then we could skip points and lines, for example, in cases where a style only had fill related properties. I added a similar comment to #15416.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good but the parsing context exists for an expression, not a whole style, so this would have to be done somewhere else. Maybe there could be hasFill()
etc. utility functions for flat styles?
This filtering would be a great performance improvement, I definitely agree.
], | ||
style: { | ||
'fill-color': '#f0ede9', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks suspicious. A fill-color
cannot be applied to LineString
geometry, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes absolutely! I'll fix it
['==', ['get', 'class'], 'street_limited'], | ||
], | ||
['==', ['geometry-type'], 'LineString'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above with Polygon
: stroke-color
and stroke-width
can only be applied to a LineString
, so there should not be a need to filter by geometry-type
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, a polygon or a linestring could have a stroke applied, so I think the geometry type filter is useful here (though I'm not sure if this data has street polygons in the "road" layer).
@jahow - Thanks for taking this on. Having more complex / realistic style examples will really help identify what else needs work. I'm curious about the dynamic variable name part. If we require that This would be a more significant optimization when rendering many features with many properties in cases where only a small subset of those properties are used. And perhaps it wouldn't be a very significant optimization in most cases with user-provided variables (if instead of pruning these down to just the ones that are used we always include all variables as uniforms). But I'm curious about the use case for dynamic variable names. |
I see now that the dynamic As an alternative to this {
'icon-offset': ['var', ['concat', 'offset-', ['get', 'maki']]],
} we could do this {
// ...
'icon-offset': ['match', ['get', 'maki'], 'bbq-15', [225, 0], 'bicycle-15', [0, 15] // etc.],
} But I see how this would make for a large I still feel like we may regret allowing both |
Thanks for the first look!
Yes I realize that, it does not represent a "real-life" mapbox basemap style. I figured it was still a good exercise to try and convert it, and have it be rendered by both Canvas and WebGL renderers.
Dynamic I still think having it possible for variables would be good, even if it's just for the sake of flexibility. |
This is a draft PR that aims at converting the existing Mapbox Streets v6 style used in some examples to the flat style format.
See the working WebGL vector tiles example
Achieving this requires implementing the following:
geometry-type
and dynamicvar
namesconcat
and dynamicvar
names in GPU expression compilerUNKNOWN_VALUE
; if an operator needs to read from one of these, it will also returnUNKNOWN_VALUE
; eventually, this means expressions can be evaluated on various contexts (feature available or not, resolution available or not etc.)I will break this into several separate PRs in order to progress towards this goal.
Note: icons are not loaded as separate images any more, so the maki icons were compiled into a sprite sheet using https://github.com/flother/spreet.