Home > Uncategorized > Geoserver: Adding styles

Geoserver: Adding styles

In the previous post we learnt how to add stores and layers. By default, geoserver, adds a style so that the layer can be displayed. In this post, we will learn how to create a custom style.

By default geoserver supports styles in SLD. SLD is rather verbose and inconvenient to write by hand so geoserver also offers an alternative called CSS which, not surprisingly, is inspired from the web technique with the same name. CSS styling for geoserver comes as a plugin and must be installed separately. The procedure for doing it is straight forward though – just follow the instructions on the linked page.

Click the CCS Styles in the left column to open up the editor. Press create new style and give it a name.

geoserver-edit-css

These are the styles created. First for the least level of detail.


[@scale > 20000000] {
label: [name];
label-anchor: 0.5 0.5;
font-family: "Times New Roman";
font-fill: black;
font-style: normal;
font-size: 14;
fill: blue;
}

Second for the middle resolution.


[@scale > 5000000] [@scale < 20000000] {
label: [name];
label-anchor: 0.5 0.5;
font-family: "Times New Roman";
font-fill: black;
font-style: normal;
font-size: 14;
fill: red;
}

And last for the finest level of detail.


[@scale < 5000000] {
label: [NAME];
label-anchor: 0.5 0.5;
font-family: "Times New Roman";
font-fill: black;
font-style: normal;
font-size: 14;
fill: green;
}

We can use to option “change layer association” to set the style for the associated layer. Alternatively, we can open up the layer publishing properties and change it from there (but that is less convenient).

geoserver-default-style

Once done we can combine the three layers into a layer group. By doing this, we get a map that adapts the layer of detail to the current zoom level.

geoserver-l3 geoserver-l2 geoserver-l1

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: