Styles

This section will detail how to work with the styles pages in the Web administration interface. For more information on styles and syntax, please see the main section on Styling.

Styles are used to control the appearance of geospatial data. Styles for GeoServer are written in a number of different formats:

  • Styled Layer Descriptor (SLD): An OGC standard for geospatial styling. Available by default.
  • Cascading Style Sheets (CSS): A CSS-like syntax. Available via an extension.
  • YSLD: An SLD-equivalent based on YAML for improved authoring. Available via the ysld extension .

Styles page

On the Styles page, you can add a new style, remove a style, or view or edit an existing style.

../../_images/styles.png

Styles page

Add a Style

The buttons for adding and removing a style can be found at the top of the Styles page.

../../_images/styles_add_delete.png

Adding or removing a style

To add a new style, click Add a new style button. You will be redirected to the new style page, which is the same as the Style Editor Data tab.

The editor page provides several options for submitting a new style:

  • Type the style definition directly into the editor.

  • Generate a new default style based on an internal template:

    ../../_images/styles_editor_generate.png

    Generating a new default style.

  • Copy the contents of an existing style into the editor:

    ../../_images/styles_editor_copy.png

    Copying an existing Style from GeoServer

  • Upload a local file that contains the style:

    ../../_images/styles_upload.png

    Uploading an file from the local system

When creating a style, only the Data tab will be available. Click Apply on the new style to stay on the Style Editor page and gain access to all tabs.

Remove a Style

To remove a style, click the check box next to the style. Multiple styles can be selected at the same time. Click the Remove selected style(s) link at the top of the page. You will be asked for confirmation:

../../_images/styles_delete.png

Confirmation prompt for removing styles

Click OK to remove the selected style(s).

Style Editor

On the Styles page, click a style name to open the Style Editor.

The Style Editor page presents the style definition. The page contains four tabs with many configuration options:

  • Data: Includes basic style information, the ability to generate a style, and legend details
  • Publishing: Displays which layers are using this style
  • Layer Preview: Previews the style with an associated layer while editing
  • Layer Attributes: Displays a list of attributes for the associated layer
../../_images/styles_editor_tabs.png

Style Editor tabs

At the bottom of the Style Editor page is a number of options:

Option Description
Validate Will test the current style for correctness according to the Format option selected
Apply Makes the changes to the style and remain on the Style Editor page. This is useful to update the Layer Preview tab.
Submit Makes the changes to the style and returns to the Styles page
Cancel Cancels all changes to the style and returns to the Styles page
../../_images/styles_editor_validate_buttons.png

Style Editor options

Style definition

On all tabs, the Style Editor will display the style definition at the bottom, allowing for direct editing of the style. Switch between the tabs in order to facilitate style creation and editing.

../../_images/styles_editor.png

Style editor

The style editor supports line numbering, automatic indentation, and real-time syntax highlighting. You can also increase or decrease the font size of the editor.

Button Description
../../_images/styles_editor_undo.png Undo
../../_images/styles_editor_redo.png Redo
../../_images/styles_editor_goto.png Go to line
../../_images/styles_editor_reformat.png Auto-format the editor contents
../../_images/styles_editor_fontsize.png Change the font size in the editor

During editing and especially after editing is complete, you will want to check validation of the syntax. This can be done by clicking the Validate button at the bottom.

If no errors are found, you will see this message:

../../_images/styles_editor_noerrors.png

No validation errors

If any validation errors are found, they will be displayed:

../../_images/styles_editor_error.png

Validation error message

Style Editor: Data tab

The Data tab includes basic style information, the ability to generate a style, and legend details.

The Style Data area has mandatory basic style information:

Option Description
Name Name of the style
Workspace Workspace in which the style is contained. Styles can be inside workspaces, but can also be “global” (no workspace).
Format Format of the style. Options are SLD, CSS, and YSLD, depending on availability.
../../_images/styles_editor_data_styledata.png

Style Data area

The Style Content area allows you to generate a style, copy an existing style, or upload an existing style:

Option Description
Generate a default style Selects a generic style based on geometry. Options are Point, Line, Polygon, Raster, and Generic. Click Generate when selected.
Copy from existing style Selects an existing style in GeoServer and copy its contents to this style. Any style in GeoServer is available as an option. Not all styles will work with all layers. Click Copy when selected.
Upload a style file Selects a plain text file on your local system to add as the style. Click Upload when selected.
../../_images/styles_editor_data_stylecontent.png

Style Content area

The Legend area allows you to add, modify, or delete a custom style, and preview the legend for the style. By default GeoServer will generate a legend based on your style file, but this can be customized here:

Option Description
Add legend Allows you to use a custom legend
Online Resource Path to the custom legend graphic to use. Can be a URL or a local path (relative to the style file path). See Structure of the data directory for a description of the styles directory.
Auto-detect image size and type Populates the Width, Height, and Format options for the Online Resource
Width Width of the custom legend graphic
Height Height of the custom legend graphic
Format Mime type of the custom legend graphic
Discard legend Will remove the settings for the custom legend graphic and will instead use the default generated legend.
Preview legend Previews the legend based on the current settings
../../_images/styles_editor_data_legend.png

Legend area

Style Editor: Publishing tab

The Publishing tab displays a list of all layers on the server, with the purpose of showing which layers are associated with the current style. Layers can set a single default style and have any number of additional styles. If this style is set to be either of these options for a layer, it will be shown with a check box in the table.

Option Description
Workspace Workspace of the layer
Layer Name of the layer
Default Shows whether the style being edited is the default for a given layer
Associated Shows whether the style being edited is an additional style for a given layer
../../_images/styles_editor_data_publishing.png

Publishing tab

Style Editor: Layer Preview tab

It is very common to have to iterate your styles and test how the visualization changes over time. The Layer Preview tab allows you to make changes to the style and see them without having to navigate away from the page.

The Layer Preview tab shows a single image. GeoServer tries to identify which layer should be shown (for example, a layer for which this style is the default), but if the layer being previewed is not the desired one, click the layer name above the preview box and select a layer.

../../_images/styles_editor_data_layerpreview.png

Layer Preview tab

Style Editor: Layer Attributes tab

Most styles utilize the specific values of certain attributes of the associated layer in order to create more detailed and useful styles. (For example: styling all large cities different from small cities based on a particular attribute.)

The Layer Attributes tab will display a list of attributes for the given associated layer. GeoServer tries to identify which layer should be shown (for example, a layer for which this style is the default), but if the layer being previewed is not the desired one, click the layer name above the table and select a layer.

Option Description
name Name of the attribute
type Type of the attribute. Can be a numeric (such as “Long”), a string (“String”), or a geometry (such as “Point”).
sample Sample value of the attribute taken from the data
min Minimum value of the attribute in the data set, if applicable
max Minimum value of the attribute in the data set, if applicable
computeStats Click Compute to calculate the min and max values for that attribute, if applicable
../../_images/styles_editor_data_layerattributes.png

Layer Attributes tab

Previous: Styling