public final class MapfishJsonStyleParserPlugin extends java.lang.Object implements StyleParserPlugin
This style parser support two versions of JSON formatting. Both versions use the same parameter names for configuring the values of the various properties of the style but the layout differs between the two and version 2 is more flexible and powerful than version 1.
Version 1 is compatible with mapfish print <= v2 and is based on the OpenLayers v2 styling. The layout is as follows:
{
"version" : "1",
"styleProperty":"_gx_style",
"1": {
"fillColor":"#FF0000",
"fillOpacity":0,
"rotation" : "30",
"externalGraphic" : "mark.png"
"graphicName": "circle",
"graphicOpacity": 0.4,
"pointRadius": 5,
"strokeColor":"#FFA829",
"strokeOpacity":1,
"strokeWidth":5,
"strokeLinecap":"round",
"strokeDashstyle":"dot",
"fontColor":"#000000",
"fontFamily": "sans-serif",
"fontSize": "12px",
"fontStyle": "normal",
"fontWeight": "bold",
"haloColor": "#123456",
"haloOpacity": "0.7",
"haloRadius": "3.0",
"label": "${name}",
"labelAlign": "cm",
"labelRotation": "45",
"labelXOffset": "-25.0",
"labelYOffset": "-35.0"
}
}
Version 2 uses the same property names as version 1 but has a different structure. The layout is as follows:
{
"version" : "2",
// shared values can be declared here (at top level)
// and used in form ${constName} later in json
"val1" : "#FFA829",
// default values for properties can be defined here
" strokeDashstyle" : "dot"
"[population > 300]" : {
// default values for current rule can be defined here
// they will override default values defined at
// higher level
"rotation" : "30",
//min and max scale denominator are optional
"maxScale" : 1000000,
"minScale" : 100000,
"symbolizers" : [{
// values defined in symbolizer will override defaults
"type" : "point",
"fillColor":"#FF0000",
"fillOpacity":0,
"rotation" : "30",
"externalGraphic" : "mark.png",
"graphicName": "circle",
"graphicOpacity": 0.4,
"pointRadius": 5,
"strokeColor":"${val1}",
"strokeOpacity":1,
"strokeWidth":5,
"strokeLinecap":"round",
"strokeDashstyle":"dot"
},{
"type" : "line",
"strokeColor":"${val1}",
"strokeOpacity":1,
"strokeWidth":5,
"strokeLinecap":"round",
"strokeDashstyle":"dot"
},{
"type" : "polygon",
"fillColor":"#FF0000",
"fillOpacity":0,
"strokeColor":"${val1}",
"strokeOpacity":1,
"strokeWidth":5,
"strokeLinecap":"round",
"strokeDashstyle":"dot"
},{
"type" : "text",
"fontColor":"#000000",
"fontFamily": "sans-serif",
"fontSize": "12px",
"fontStyle": "normal",
"fontWeight": "bold",
"haloColor": "#123456",
"haloOpacity": "0.7",
"haloRadius": "3.0",
"label": "[name]",
"fillColor":"#FF0000",
"fillOpacity":0,
"labelAlign": "cm",
"labelRotation": "45",
"labelXOffset": "-25.0",
"labelYOffset": "-35.0"
}
]}
}
As illustrated above the style consists of:
Values can be referenced in the value of a property with the pattern: ${valName}
Value names can only contain numbers, characters, _ or -
Values do not have to be the full property they will be interpolated. For example:
The value is ${val}
In order to reduce duplication and keep the style definitions small, default values can be specified. The default values in the root (style level) will be used in all symbolizers if the value is not defined. The style level default will apply to all symbolizers defined in the system.
The only difference between a value and a default is that the default has a well known name, therefore defaults can also be used as values.
A styling rule has a key which is the filter which selects the features that the rule will be used to draw and the rule definition object.
The filter is either * or an
ECQL Expression) surrounded by square brackets. For example: [att < 23].
WARNING: At the moment DWITHIN and BEYOND spatial functions take a unit parameter. However it is ignored by geotools and the distance is always in the crs of the geometry projection.
The rule definition is as follows:Each rule can also have defaults. If the style and the rule have a default for the same property the rule will override the style default. All defaults can be (of course) overridden by a value in a symbolizer.
The minimum scale that the rule should evaluate to true
The maximum scale that the rule should evaluate to true
A symbolizer must have a type property (point, line, polygon, text) which indicates the type of symbolizer and it has the attributes for that type of symbolizer. All values have defaults so it is possible to define a symbolizer as with only the type property. The only exception is that the "text" symbolizer needs a label property.
Most properties can be static values or ECQL expressions. If the property has [ ] around the property value
then it will be interpreted as an ECQL expression. Otherwise it is assumed to be static text. If you need static text
that start and ends with [ ] then you will have to enter: ['propertyValue'] (where propertyValue
start and ends with [ ].
The items below with (ECQL) can have ECQL expressions.
Geotools has by default 3 types of marks:
Options: butt (sharp square edge), round (rounded edge), and square (slightly elongated square edge). Default is butt
X-Align options:
Y-Align options:
Labelling in this style format is done by defining a text symbolizer ("type":"text"). All text sybmolizers consist of:
It is important to realize that since only one type of placement can be used, an error will be reported if labelPerpendicularOffset is defined in the text symbolizer along with any of the point placement properties.
Point Placement
Point placement defines an anchor point which is the point to draw the text relative to. For example an anchor point of 0.5, 0.5 ("labelAnchorPointX" : "0.5", "labelAnchorPointY" : "0.5") would position the start of the label at the center of the geometry.
After anchor point, comes displacement displacement defines the distance from the anchor point to start the label. The combination of the two values determines the final location of the label.
Lastly, there is a label rotation which defines the orientation of the label.
There are two ways to define the anchor point, either the labelAnchorPointX/Y properties are set or the labelAlign property is set. If both are defined then the labelAlign will be ignored.
| Constructor and Description |
|---|
MapfishJsonStyleParserPlugin() |
| Modifier and Type | Method and Description |
|---|---|
com.google.common.base.Optional<org.geotools.styling.Style> |
parseStyle(Configuration configuration,
org.springframework.http.client.ClientHttpRequestFactory clientHttpRequestFactory,
java.lang.String styleString,
MapfishMapContext mapContext)
Using the string load a style.
|
public com.google.common.base.Optional<org.geotools.styling.Style> parseStyle(@Nullable
Configuration configuration,
@Nonnull
org.springframework.http.client.ClientHttpRequestFactory clientHttpRequestFactory,
@Nonnull
java.lang.String styleString,
@Nonnull
MapfishMapContext mapContext)
throws java.lang.Throwable
StyleParserPluginparseStyle in interface StyleParserPluginconfiguration - the configuration being used for the current print.clientHttpRequestFactory - an factory for making http requests.styleString - the string that provides the information for loading the style.mapContext - information about the map projection, bounds, size, etc...java.lang.Throwable