More layer matching control with priority and exclusive#705
Conversation
|
@nvkelso @meetar @matteblair @burritojustice this need for control over matching order and exclusivity recently came to a head for me. Having tried a few different approaches, this is where I've settled. I'm confident the use cases are real, and fairly satisfied with the balance of syntax and implementation footprint here (both less than I feared). But of course interested in opinions, possible alternatives, etc.! |
|
I dig it. Like you mentioned, we've had to do some silly gymnastics to accomplish layer filters in the Mapzen house styles and this new syntax would simplify that for the basemaps – and make it easier to style data viz. 2x win! |
|
Added Tangram ES sister issue in tangrams/tangram-es#2036. |
|
Nice! We had discussed logic like this for Tangram ES, but actually for performance benefits rather than styling control. For layers with many siblings where the filters are effectively exclusive, matching can be much faster if sibling filter evaluation is "short circuited" like this. I can't immediately think of any reason we couldn't implement this in Tangram ES but I'll take a closer look later. |
|
Performance is a good point! Yeah, in some ways |
This PR introduces two new keywords --
priorityandexclusive-- 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
priorityandexclusivekeywords 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 asexclusiveensures that when that layer matches, no other sibling layers (and their cascading sub-layers, etc.) will; when multipleexclusivelayers match, the higher priority layer wins.For example,
exclusivecould express a singleif-elsefilter condition:When used together,
priorityandexclusivecan be used for chainedif-elseif-elsefilter cases, to ensure that only one of an ordered set of conditions matches:Separate from "flow control" cases,
prioritycan 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:
priorityvalue are matched first, with values sorted from lowest to highest (e.g.priority: 1is matched beforepriority: 2).priorityare matched after, and continue to be sorted lexically.exclusivematches, all further matching at that level in the layer tree ceases and the matching layer is used (matching continues for thatexclusivelayer's child/descendant layers).exclusive, the first one (according to the order described above) is used.