HowTo: add styling to a mapService layer
1. Introduction
This HowTo page describes how to add a new styling description to an existing mapService layer. The description is based on the deegree3 utahDemo ready for download.
Note: For this tutorial it is recommended (but not mandatory) to use an XML aware text editor (like XMLSpy or Eclipse IDE for Java EE Developers). |
Adding style definition files to the deegree 3 services configuration is not possible via the deegree 3 services console yet. However, the services console is used for getting necessary information on style location and for checking success.
Services console login: "deegree" (without the quote signs) is the default password.
2. Preparations
For this tutorial we will use the same layer (landslide areas) as in the tutorial on
If you have not worked through this tutorial yet, you should please do so now.
3. Add layer styling
The layer landslide areas provides visualisation for polygons. Therefore we need a style definition for polygon symbolisation. As there are already polygon based layers in the utahDemo, the easiest way to go is to copy one of the existing polygon styles.
Creating the new style:
Click on the link render styles.
In the list of available Rendering style definition, click on Edit for the style utah_municipalities.
- You are now able to edit the text of the style and check the location of the xml file. All we want to know is the location of the file:
Editing: /home/mays/deegree3/deegree-utah-demo/webapps/ROOT/WEB-INF/workspace/styles/utah_municipalities.xml
We do not change anything here! So click Cancle.
- Leave the services console and use your file browser to browse to the location of the style.
Create a copy of the file WEB-INF/workspace/styles/utah_municipalities.xml and name it utah_landslideareas.xml.
Editing the new style:
- Open the new file in an XML aware text editor (see recommendation note above).
What you see here is a FeatureTypeStyle with two different rules. The first rule defines the visualisation of the polygons (PolygonSymbolizer), while the second rule defines a TextSymbolizer for visualising labels for the geometries.
Change the name of the rules: Use the Search&Replace functionality of your editor to search for Municipalities and replace all five occurences with the new name LandslideAreas.
Delete the second rule for the <TextSymbolizer>. A text symbolizer is not needed. If you want to know more about styling, please check out further reading.
Change the rule for the <PolygonSymbolizer>. Reduce complexity of styling, use a simple color rule. No need for categories. If you want to know more about styling, please check out further reading.
The complete <FeatureTypeStyle> will now look like this:
<FeatureTypeStyle xmlns="http://www.opengis.net/se" xmlns:app="http://www.deegree.org/app" xmlns:ogc="http://www.opengis.net/ogc" xmlns:sed="http://www.deegree.org/se" xmlns:deegreeogc="http://www.deegree.org/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/se http://schemas.opengis.net/se/1.1.0/FeatureStyle.xsd http://www.deegree.org/se http://schemas.deegree.org/se/1.1.0/Symbolizer-deegree.xsd"> <Name>LandslideAreas</Name> <Rule> <Name>LandslideAreas</Name> <Description> <Title>LandslideAreas</Title> </Description> <PolygonSymbolizer> <Fill> <SvgParameter name="fill">#cc3300</SvgParameter> <SvgParameter name="fill-opacity">0.3</SvgParameter> </Fill> <Stroke> <SvgParameter name="stroke">#000000</SvgParameter> <SvgParameter name="stroke-opacity">1.0</SvgParameter> <SvgParameter name="stroke-width">1</SvgParameter> </Stroke> </PolygonSymbolizer> </Rule> </FeatureTypeStyle>
Connecting the style with the WMS layer:
Click on the link web services.
In the list of available web services, click on Edit for the wms.
- You are now able to edit the text of the configuration xml file:
Scroll down to the <RequestableLayer> for LandslideAreas.
- Edit the configuration to match the following snippet:
<RequestableLayer> <Name>LandslideAreas</Name> <Title>Lanslide Areas in the County of Utah</Title> <FeatureStoreId>utah_landslides</FeatureStoreId> <DirectStyle> <File>../styles/utah_landslideareas.xml</File> </DirectStyle> </RequestableLayer>
All you need to add is the <DirectStyle>, referencing the above created file containing the feature type style.
To apply the changes, you need to click the Save button at the top of the editor. The editor window will close and the Reload link in the top left corner will turn red to inform you about changes that have not been forwarded to the server side yet.
Click the Reload button to permanently store the changes in your configuration. (Follow-up message: Applying changes. Please wait).
4. Check success
- Check the capabilities of your WMS:
Click on the Capabilities button next to the wms.
The <WMS_Capabilities> document will contain the following section:
<Layer queryable="1"> <Name>LandslideAreas</Name> <Title>Lanslide Areas in the County of Utah</Title> ... <Style> <Name>default</Name> <Title>LandslideAreas</Title> <LegendURL width="124" height="27"> <Format>image/png</Format> <OnlineResource xlink:type="simple" xlink:href="http://localhost:8080/services?request=GetLegendGraphic&version=1.3.0&service=WMS&layer=LandslideAreas&style=LandslideAreas&format=image/png"></OnlineResource> </LegendURL> </Style> <Style> <Name>LandslideAreas</Name> <Title>LandslideAreas</Title> <LegendURL width="124" height="27"> <Format>image/png</Format> <OnlineResource xlink:type="simple" xlink:href="http://localhost:8080/services?request=GetLegendGraphic&version=1.3.0&service=WMS&layer=LandslideAreas&style=LandslideAreas&format=image/png"></OnlineResource> </LegendURL> </Style> </Layer>
The <Style> section is new (compared to the capabilities response in the previous tutorial, see former capabilities section).
- View the layer in the map:
Go to the integrated OpenLayers client by clicking on see layers and activate the layer LandslideAreas in the layer list on the rigt hand side. You will now see the formerly grey landslide areas as redish polygons.
5. What next ?
The layer style is there already, but now we might want to change something we don't like, or improve the styling rules! The logical follow-up will be handled in another tutorial and teach you how to change layer styling, based on the example layer (landslide areas).
6. Further reading
Other pages on styling:
Other pages focusing on the deegree 3 services console:
Detailed description of the deegree 3 workspace and associated configuration pages:
- deegree3/WorkspaceConfiguration
- deegree3/WorkspaceConfiguration/CRSConfiguration
- deegree3/WorkspaceConfiguration/CoverageStoreConfiguration
- deegree3/WorkspaceConfiguration/DataStoreOverview
- deegree3/WorkspaceConfiguration/FeatureStoreConfiguration
- deegree3/WorkspaceConfiguration/FeatureStoreConfiguration_3.0
- deegree3/WorkspaceConfiguration/FeatureStoreConfiguration_3.1
- deegree3/WorkspaceConfiguration/JDBCConfiguration
- deegree3/WorkspaceConfiguration/MetadataStoreConfiguration
- deegree3/WorkspaceConfiguration/ObservationStoreConfiguration
- deegree3/WorkspaceConfiguration/ProxyConfiguration
- deegree3/WorkspaceConfiguration/RemoteOWSStore
- deegree3/WorkspaceConfiguration/ServicesConfiguration
- deegree3/WorkspaceConfiguration/ServicesConfiguration/ExtendedCapabilities
- deegree3/WorkspaceConfiguration/StylesConfiguration
- deegree3/WorkspaceConfiguration/TileStoreConfiguration