Common usage of the special zoom
filter keyword looks like:
#roads[zoom=10] {
line-width:2;
}
Which tells the renderer to, only at zoom level 10, query the roads
layer and draw lines with the width of 2.
But this becomes verbose and repetative when you want to vary the line width for every (or at least many different zoom levels):
#roads {
[zoom=1] {
line-width:2;
}
[zoom=2] {
line-width:3;
}
[zoom=3] {
line-width:4;
}
}
So, what if we could accomplish this same exact styling as above, for example, where the line-width
is one larger than the zoom without having to be explicit in code for every single zoom level?
We could allow line-width
to be an expression
so that you could do:
#roads {
line-width:@zoom+1;
}
The @
sign here in front of the zoom
keyword here indicates something important: That zoom
in this context is not a filter that controls whether a layer is actually queried for a given zoom level but rather is a token that would be dynamically evalated for every single feature that is processed for that layer.
So this works, but only in the case where we want to show lines for all zoom levels. Maybe it only makes sense to show lines for zoom levels between 2-10. In that case you would need to use zoom
in both ways:
#roads[zoom>2][zoom<10] {
line-width:@zoom+1;
}
Finally, some clever cartographers edit their data such that a certain field represents an integer for whether a certain feature should be shown at a certain zoom level, like the natural earth SCALERANK
: http://www.naturalearthdata.com/forums/topic/definition-of-scale-rank-appropriate-attribute-for-size-based-styling/
For the purposes of this example let's asssume that we are styling data now that has a SCALERANK
field and SCALERANK
maps 1:1 to zoom level, so a feature with a value of 10
should only be shown at zoom level 10
and below.
Combining the above example with scalerank could look like:
#roads {
[zoom>2][zoom<10][[SCALERANK]<10] {
line-width:@zoom+1;
}
[zoom>10][zoom<20][[SCALERANK]<20] {
line-width:@zoom+2;
}
}
But maybe we could do even better and potentially save even more typing. What if the zoom
filter selector were comparable to a data field such that we could accomplish the above styling in just a few lines:
#roads[zoom>2][zoom<20] {
[zoom<=[SCALERANK]] {
line-width:@zoom+1;
}
}
Cool, so my initial thought is that it would also seem natural for
@zoom
to be a field or a special field, like[zoom]
or{zoom}
, or to reserve a special syntax for builtin variables like$zoom
. It would be nice consistency-wise to avoid the case in which a user writesBut may not be absolutely necessary.