Closed bcamper closed 7 years ago
TODO: I noticed that negative sprite sizes in Tangram JS currently flip the sprite upside-down and anchor it from the bottom left. We should clamp negative point size values (both for explicit px
values and for %
) to zero.
cc @matteblair @nvkelso
Nice!
A new ratio-constrained scaling syntax allows the user to specify a size for the width OR height, with the unspecified dimension automatically calculated to preserve the sprite's aspect ratio. The syntax for this is to specify size as a 2D array, with the special ?px value as one of the dimensions: size: [32px, ?px] # scale the sprite to 32px wide, with auto-calc height size: [?px, 16px] # scale the sprite to 16px high, with auto-calc width Syntax note: the ?px value is a proposal. My original plan was to use a single ? character, but this is reserved YAML syntax, as are many similar candidates.
size: [32px,]
*
instead of ?
as the wildcard? Probably more YAML collisions?
size: [32px, *px]
, orsize: [32px, *]
I've seen things like auto
used here:
size: [32px, auto]
These changes make sense to me, I can't think of any issues with implementing this in Tangram ES.
I was also going to suggest auto
for the auto-constraint token. *
or *px
is interpreted as a YAML anchor, so we can't attach our own semantics to it. An empty value as in [32px,]
or [,32px]
could technically work (the empty value is interpreted as null
) but to me that looks a lot like a typo.
auto
makes sense to me, I forgot that we already use that for point angle
. I'll update the code and description.
I also considered *
(YAML reserved) and a null value (but decided against it for the reasons cited above, I think something explicit is better and less error-prone).
This PR adds two new features for setting the size of sprites on
points
-based features. Both are designed to eliminate significant boilerplate and hand-calculated code for specifying sprite sizes across zooms; this has particularly come to light with the addition of many new highway shields. This work is distinct from but builds on the recently addeddensity
parameter for textures.Percent scaling
%
qualifier now enables this when settingsize
:size: 50%
density
parameter for textures. For example:64px
anddensity: 2
has an intended CSS pixel display size of32px
.size: 100%
will display this sprite at32px
CSS pixels (e.g.32px
actual pixels on a 1x display, or64px
on a 2x retina display).px
sizing:size: [[13, 50%]], [20, 100%]] # scale from 50% to 100% across a zoom range
size: [[13, 12px]], [20, 100%]] # scale from 12px square to 100% across a zoom range
100%
, e.g.size: 200%
will scale the sprite to twice its native size.Ratio-constrained scaling
size: 16px
, which would set both the width and height to that value, or as a 2D value, e.g.size: [16px, 24px]
, which would set the width to16px
and the height to24px
.24px
), they needed to manually calculate the corresponding width for each sprite (and specify this at each desired zoom as well).size
as a 2D array, with the specialauto
value as one of the dimensions:size: [32px, auto] # scale the sprite to 32px wide, with auto-calc height
size: [auto, 16px] # scale the sprite to 16px high, with auto-calc width
size: [[15, [auto, 12px], [20, [auto, 20px]] # scale between two heights, with auto-calc width
size: [[13, [auto, 12px]], [20, 100%]] # scale from 12px high at z13, up to full size at z20
size: [50%, auto]
is the same assize: 50%
.size: [auto, auto]
.theOpted for?px
value is a proposal. My original plan was to use a single?
character, but this is reserved YAML syntax, as are many similar candidates.auto
based on PR discussion.Sprite requirement
texture
andsprite
defined will log a warning and skip features in the layer, e.g. thesedraw
blocks (assuming no other inherited parameters) both generate warnings and draw nothingdraw: { points: { color: red, size: 50% } }
draw: { points: { color: red, size: [auto, 20px] } }