cssgeoserversld

How to add a literal prefix to a label using Geoserver's CSS Style


I have a layer of polygons, they have an attribute "Engine". Let's say the values (all strings) are "1", "2", "3" So I can get this to work easily:

* { fill: lightgrey; label: [Engine]; }

All the polygons are drawn and they are labeled "1", "2", and "3".

My question is - how do I label them "Engine 1", "Engine 2", and "Engine 3". I simply want to prefix the [Engine] with some literal text. Just concatenate the literal "Engine " with the value of the Engine attribute.

As a bonus - what if I want to concatenate literals and different attributes all into the same label? I haven't found documentation on how to put anything but the value of an attribute or a literal into that label. Not sure how to concatenate...

So this works as well (they all say "Engine" but you don't know which one...)

* { fill: lightgrey; label: 'Engine'; }

Ok, I finally type the whole question in, try one more thing, and it works! Just put the literal and the attribute next to each other - no concatenation operator required.

* { fill: lightgrey; label: 'Engine '[Engine]; }

Solution

  • Just put the literal and the attribute next to each other - no concatenation operator required.

    * { fill: lightgrey; label: 'Engine '[Engine]; }