More layer matching control with priority
and exclusive
#705
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces two new keywords --
priority
andexclusive
-- for scenelayers
, to enable greater control over feature filter matching and styling composition.Background
Tangram layer matching has always been inclusive, meaning a feature can match multiple layers (at multiple levels of the layer style tree), which are then merged to determine the final rendering parameters. Composing complex sub-layer trees can be used to capture both feature and zoom-dependent styling along orthogonal dimensions, for example varying road line widths and colors by separate criteria.
However, two in many ways simpler behaviors have not been easily expressed with the current layer syntax:
New Syntax
The
priority
andexclusive
keywords address these cases, and can be used both separately and together.priority
: allows for the explicit definition of the matching order for sibling layers (alphabetical by layer name is still used as the default / fallback).exclusive
: marking a layer asexclusive
ensures that when that layer matches, no other sibling layers (and their cascading sub-layers, etc.) will; when multipleexclusive
layers match, the higher priority layer wins.For example,
exclusive
could express a singleif-else
filter condition:When used together,
priority
andexclusive
can be used for chainedif-elseif-else
filter cases, to ensure that only one of an ordered set of conditions matches:Separate from "flow control" cases,
priority
can simply be used on its own to disambiguate the precedence of multiple layers without reliance on naming conventions.Implementation
The implementation is a fairly narrow impact on the layer matching logic:
priority
value are matched first, with values sorted from lowest to highest (e.g.priority: 1
is matched beforepriority: 2
).priority
are matched after, and continue to be sorted lexically.exclusive
matches, all further matching at that level in the layer tree ceases and the matching layer is used (matching continues for thatexclusive
layer's child/descendant layers).exclusive
, the first one (according to the order described above) is used.