Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Color-manipulation-like functions for zoom-based width #957

Closed
IvanSanchez opened this Issue · 6 comments

3 participants

@IvanSanchez

Wishlist item.

We all love lighten(@color,10%) and darken(@color,10%), and the rest of the color manipulation functions. They make our stylesheets compact and easy to modify.

Now, wouldn't it be cool if we could replace this snippet (taken from the Open Streets style)...

.water-outline[zoom>11] {
  line-color:darken(@water,10);
  [zoom=12] { line-width:0.8; }
  [zoom=13] { line-width:1.2; }
  [zoom=14] { line-width:1.4; }
  [zoom=15] { line-width:1.6; }
  [zoom=16] { line-width:1.8; }
  [zoom>16] { line-width:2; }
}

... with something like this?

.water-outline[zoom>11] {
  line-color:darken(@water,10);
  line-width:linearzoom(12, 0.8, 17, 2);
}

I'm thinking about stuff like cuadratic-zoom width values, and providing values for dash arrays, text size/displacement, and the color spin functions.

@tmcw
Admin

We've had some discussion about this... while it does make sense to add more useful 'functions' to carto, and it's especially nice to use zoom as a real variable when carto-parser is supported (this isn't feasible with carto.js), adding advanced mathy magic for things that will not please artists at the end of the day and require hand-tweaking as part of the language is not a goal, because it is unlikely to be 'good enough' and very likely to be completely incomprehensible to the vast majority of newbie users, for whom it is theoretically written.

@IvanSanchez

Instead of automagical "mathy" functions, how 'bout math expressions?

.foo {
  line-width: 1 + @zoom * 0.2;
}

Easier to understand and good enough (for me), but I'm wild guessing that math operators would require some overhaul of the Carto syntax parser.

@tmcw
Admin

No, math operators are already there. You can use them willy-nilly. The only thing that's missing is using the @zoom variable, because it's long gone by the time that Carto's serialized to XML. That'll happen when carto-parser is used, but won't happen before then.

@IvanSanchez

... parse stylesheet, check for @zoom variable, then expand the rule for every possible value of @zoom for this map? Maybe doing so before calling carto-parser is called would be viable.

@tmcw
Admin

To explain further, carto-parser is a Carto parser implemented in C++ that works within Mapnik. It'll actually run when maps are rendering and accept Carto as native input. Right now we're doing serialization to XML, and implementing workarounds creating 'every possibility' will quickly lead to situations in which we have n^m rules, and gigantic XML stylesheets. So, waiting for carto-parser.

@tmcw tmcw closed this
@GWHAThistory

@tmcw, any update on moving to carto-parser? Exposing @zoom could be a fun feature, even with basic math operators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.