Adding a StyleΒΆ

The most important function of a Web Map Server is the ability to style and render data. This section covers the task of adding a new style to GeoServer and configuring the default style for a particular layer.

  1. From the GeoServer Welcome Page navigate to Styles.

    ../_images/style1.png

    Navigating to Style configuration

  2. Click Add a new style

    ../_images/style2.png

    Adding a new style

  3. Click on the file upload dialogue.

    ../_images/style3.png

    Populating from a file.

  4. Navigate to the workshop (on Linux) $TRAINING_ROOT/data/user_data/ directory (on Windows %TRAINING_ROOT%\data\user_data\), select the foss4g_mainrd.sld file, and click Upload.

    Note

    In GeoServer, styles are represented via SLD (Styled Layer Descriptor) documents. SLD is an XML format for specifying the symbolization of a layer. When a SLD document is uploaded the contents are shown in the text editor. The editor can be used to edit the contents of the SLD directly.

  5. Enter “mainrd” in the Name field.

  6. Add the new style by clicking Submit. Once it’s saved, you should see something like this:

    ../_images/style4.png

    Submitting style

  7. After having created the style, it’s time to apply it to a vector layer. Click on the Layers link.

    ../_images/style5.png

    Navigating to Layers

  8. Select the “Mainrd” on the Layers page.

    ../_images/style6.png

    Selecting a layer

  9. Select the Publishing tab.

    ../_images/style7.png

    Publishing tab

  10. Assign the new created style “mainrd” as the default style.

    ../_images/style8.png

    Publishing tab

    Warning

    Many new users mistake the Available Styles for the Default Style, please take into account that they are different, the default one allows that style to be used implicitly when no style is specified in a map request, while the available ones are just optional compatible styles.

    Note

    Geoserver 2.x assigns a default style depending on the geometry of the objects and the type, for example: line, poly, raster, point.

  11. Scroll to the bottom of the page and hit Save.

  12. Use the map preview to show how looks the style, please note you’ll have to zoom in once to show the data due to the map scale filters (MaxScaleDenominator directive in the SLD).