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 Style.

    ../../_images/style1.png

    Navigating to Style configuration

  2. Click New

    ../../_images/style2.png

    Adding a new style

  3. Enter “manird” in the Name field and notice the file upload dialogue SLD file.

    ../../_images/style3.png

    Specifying style name and populating from a file.

  4. Navigate to the workshop data/user_data/ directory, 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 an 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. Add the new style by clicking Submit. Once it’s save, you should see something like this:

    ../../_images/style4.png

    Submitting style

  6. 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

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

    ../../_images/style6.png

    Selecting a layer

  8. Select the Publish tab.

    ../../_images/style7.png

    Publish tab

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

    ../../_images/style8.png

    Publish 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.

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

  11. Use the map preview to show how the style, zoom in an notice the scale dependencies