mapnik / mapnik-support

Use the issues queue here to ask questions and offer help on using Mapnik (maybe if this works well we can retire the mailing list at http://mapnik.org/contact/?)
6 stars 6 forks source link

Expressions #132

Closed zdila closed 4 years ago

zdila commented 4 years ago

Hello,

I've read somewhere that mapnik now upports expressions everywhere. How does it distinguish between expression and value? For example stroke-dasharray="'3,3'" doesn't work.

In my case I am trying yo use it like ternary operator:

<LineSymbolizer stroke-dasharray="([intermittent] or [seasonal]) and '3,3' or '1000,0'" ...

Unfortunately it doesn't work - it renders no line. I know I can do it on SQL level, but I find this approach cleaner.

lightmare commented 4 years ago

Logical operators (and, or, not) in mapnik expressions convert arguments to boolean, and return boolean result; unlike modern scripting languages that test argument truthiness and return one of the original arguments.

edit: We might consider changing this in future. That'd obviously break expressions where the result is actually expected to be boolean, but I'd assume such usage to be rare.

zdila commented 4 years ago

Thanks for explanation.

zdila commented 4 years ago

I am trying to implement if-then-else operator. Please see https://github.com/mapnik/mapnik-support/issues/133#issuecomment-603084744.