GeoServer CSS module graduated to official extension

Dear All,
if you have been looking at the recent GeoServer releases you might have noticed that the CSS styling module has been graduated to extension status, making it available to a much larger audience as part of the GeoServer releases (before it was available as part of the nighly builds, for those that venture to try out new features).

For those that are not up to speed, the CSS styling module, originally written and maintained by David Winslow, allows to build styles using a CSS-like syntax which is at the same time more compact and more expressive than the usual SLD styling provided by GeoServer.
Get a feel of how it works by looking at a few examples extracted from our the CSS cookbook that we wrote recently by porting over the same examples provided in the SLD cookbook.

Render all points with a red circle, apply a bold label on top of it (the label references the “name” attrbute):

* {
   mark: symbol(circle);
   marksize: 6px;
   label: [name];
   fontfill: black;
   font-family: Arial;
   font-size: 12;
   font-weight: bold;
   labelanchor: 0.5 0;
   labeloffset: 0 5;
}

:mark {
   fill: red;
}
../../_images/point_pointwithstyledlabel.png

Build a highway like effect by painting two lines on top of each other and controlling z-order to make line crossings look good:

* {
   stroke: #333333, #6699FF;
   strokewidth: 5px, 3px;
   strokelinecap: round;
   z-index: 0, 1;
}


../../_images/line_linewithborder.png

Paint polygons of differen shades based on their population (pop attribute), dividing it in three classes (see how the filters are expressed in the CQL language):

[pop < 200000] {
   fill: #66FF66;
}

[pop >= 200000] [pop < 500000] {
   fill: #33CC33;
}

[pop >= 500000] {
   fill: #009900;
}

../../_images/polygon_attributebasedpolygon.png

You can get more examples in the CSS cookbook, and don’t forget to have a look at the reference section to learn about all styling properties.

Another thing making the use of CSS rather compelling is its editing GUI, which allows to preview the changes to the map in the same enviroment where the editing of the CSS is done:

This GUI got recently improved to allow styling of raster layers, some changes went it to make it possible to style large vector layers, as well as showing a preview of the legend graphics that the style will generated, and finally better support for GeoServer GeoTools vendor options, such as the recently introduced support for adding space around graphic fills.

Work is underway to make further improvements, such as being able to truly use meters and feet in the CSS sizes (right now only pixel measures actually work).

Another improvement that we’d like to make, time permitting, would be to make CSS a first class styling Language and merge the editing UI with the SLD one, in order to get the same nice instant feedback regardless of the styling Language in use.

Also, stay on the lookout for more documentation, the CSS cookbook will soon be compounded by a brand new section with more advanced styling examples.

As a closing remark, we’d like to thank David for accepting to graduate the module from community to official extension, and the New South Wales Geological Survey for sponsoring the creation of the CSS cookbook and associated documentation environment, the new incoming advanced examples, as well as sponsoring all the recent GUI improvements, and finally for giving me some time to learn Scala and thus start helping David with some CSS core improvements.

It is finally worth mentioning that this work was performed for a client of ours under the GeoSolutions Enterprise Services.

If you’d like to know more about what you could achieve with GeoServer, do not hesitate and get in touch with usIf you need professional services to get started with Open Source software make sure to have a look at our GeoSolutions Enterprise Services.

The GeoSolutions team.