diff --git a/doc/en/user/source/extensions/mapml/template.rst b/doc/en/user/source/extensions/mapml/template.rst index fc132fbc2cb..3cc27dec905 100644 --- a/doc/en/user/source/extensions/mapml/template.rst +++ b/doc/en/user/source/extensions/mapml/template.rst @@ -3,6 +3,20 @@ Templates With FreeMarker MapML templates are written in `Freemarker `_ , a Java-based template engine. The templates below are feature type specific and will not be applied in multi-layer WMS requests. See :ref:`tutorial_freemarkertemplate` for general information about FreeMarker implementation in GeoServer. +MapML supports the following template types: + ++------------------------+----------------------------------------------------------------------------------+ +| Template File Name | Purpose | ++========================+==================================================================================+ +| mapml-preview-head.ftl | Used to insert stylesheet links or elements into the mapml html preview viewer. | ++------------------------+----------------------------------------------------------------------------------+ +| mapml-head.ftl | Used to insert mapml-link elements into the mapml map-head section. | ++------------------------+----------------------------------------------------------------------------------+ +| mapml-feature-head.ftl | Used to insert map-style elements into a mapml feature document. | ++------------------------+----------------------------------------------------------------------------------+ +| mapml-feature.ftl | Used to wrap features with map-a tags that assign style classes to coordinates. | ++------------------------+----------------------------------------------------------------------------------+ + GetMap MapML HTML Preview/Layer Preview Head Stylesheet Templating ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The preview is returned when the format includes subtype=mapml. The preview is an HTML document that includes a head section with a link to the stylesheet. The default preview viewer is a simple viewer that includes a link to the default stylesheet. @@ -49,9 +63,9 @@ This would result in a head section that would resemble: -GetMap XML Head Stylesheet Templating +GetMap MapML Head Stylesheet Templating ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -MapML in XML format includes a map-head element that includes map-link elements to link to other resources, including map style variants. Additional map-link elements can be added to the map-head element by creating a mapml-head.ftl template in the GeoServer data directory in the directory for the layer we wish to append map-links to. For example we could create the mapml-head.ftl file under ``workspaces/tiger/nyc/poly_landmarks_shapefile/poly_landmarks``: +The MapML format includes a map-head element that includes map-link elements to link to other resources, including map style variants. Additional map-link elements can be added to the map-head element by creating a ``mapml-head.ftl`` template in the GeoServer data directory in the directory for the layer we wish to append map-links to. For example we could create the ``mapml-head.ftl`` file under ``workspaces/tiger/nyc/poly_landmarks_shapefile/poly_landmarks``: .. code-block:: bash @@ -81,13 +95,13 @@ This would result in a map-head section that would resemble (note the inserted c GetMap Features Inline Style Class Templating ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -MapML in XML feature format (when the parameter format_options=mapmlfeatures:true is set) has a map-head element that includes map-style elements where the style classes are defined. +MapML in feature format (when the parameter format_options=mapmlfeatures:true is set) has a map-head element that includes map-style elements where the style classes are defined. Within the map-body, map-feature elements include map-geometry with map-coordinates. -The mapml-feature-head.ftl is a file that can be used to insert map-style elements with the style class definitions. +The ``mapml-feature-head.ftl`` is a file that can be used to insert map-style elements with the style class definitions. This file is placed in the GeoServer data directory in the directory for the layer we wish to append style classes to. For example we could create the file under ``workspaces/tiger/nyc/poly_landmarks_shapefile/poly_landmarks``. -The mapml-feature-head.ftl file would look like:: +The ``mapml-feature-head.ftl`` file would look like:: @@ -112,11 +126,11 @@ This would result in a MapML feature output header that would resemble: -The mapml-feature.ftl is a file can be used to insert map-style elements with the style class definitions into the map-head. Note that this section of the template adds the styles listed but does not remove any existing styles. +The ``mapml-feature.ftl`` is a file can be used to insert map-style elements with the style class definitions into the map-head. Note that this section of the template adds the styles listed but does not remove any existing styles. It can be used to edit map-property names and values in a manner similar to :ref:`tutorials_getfeatureinfo_geojson`. Note that this template represents a full replacement of the feature. If there are attributes that need to be included without change, they need to be referenced in the template. It also can be used to add style class identifiers to map-feature elements based on the feature identifier or to wrap groupings of map-coordinates with spans that specify the style class based on an index of coordinate order (zero based index that starts at the first coordinate pair of each feature). This file is placed in the GeoServer data directory in the directory for the layer we wish to append style classes to. For example we could create the file under ``workspaces/tiger/poly_landmarks_shapefile/poly_landmarks``. -An example mapml-feature.ftl file to modify a point layer would look like:: +An example ``mapml-feature.ftl`` file to modify a point layer would look like:: @@ -242,7 +256,7 @@ For multiline features the template would like:: -A more complex example mapml-feature.ftl that operates on a multi-polygon layer and only inserts map-span tags into a specific feature:: +A more complex example ``mapml-feature.ftl`` that operates on a multi-polygon layer and only inserts map-span tags into a specific feature:: diff --git a/src/extension/mapml/src/main/java/org/geoserver/mapml/MapMLGenerator.java b/src/extension/mapml/src/main/java/org/geoserver/mapml/MapMLGenerator.java index 9937dd49a78..a851c0b67ab 100644 --- a/src/extension/mapml/src/main/java/org/geoserver/mapml/MapMLGenerator.java +++ b/src/extension/mapml/src/main/java/org/geoserver/mapml/MapMLGenerator.java @@ -204,6 +204,9 @@ private void formatGeometry(Object geometry) { for (Object geom : geometryCollection.getPointOrLineStringOrPolygon()) { formatGeometry(geom); } + } else if (geometry instanceof org.geoserver.mapml.xml.A) { + org.geoserver.mapml.xml.A a = (org.geoserver.mapml.xml.A) geometry; + formatGeometry(a.getGeometryContent().getValue()); } } diff --git a/src/extension/mapml/src/main/java/org/geoserver/mapml/xml/A.java b/src/extension/mapml/src/main/java/org/geoserver/mapml/xml/A.java new file mode 100644 index 00000000000..ace938474d3 --- /dev/null +++ b/src/extension/mapml/src/main/java/org/geoserver/mapml/xml/A.java @@ -0,0 +1,59 @@ +package org.geoserver.mapml.xml; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType( + name = "A", + propOrder = {"geometryContent"}) +public class A { + @XmlAttribute(name = "href") + protected String href; + + @XmlElementRef( + name = "GeometryContent", + type = JAXBElement.class, + namespace = "http://www.w3.org/1999/xhtml") + protected JAXBElement geometryContent; + + public String getHref() { + return href; + } + + public void setHref(String value) { + this.href = value; + } + + /** + * Gets the value of the geometryContent property. + * + * @return possible object is {@link JAXBElement }{@code <}{@link MultiPolygon }{@code >} {@link + * JAXBElement }{@code <}{@link LineString }{@code >} {@link JAXBElement }{@code <}{@link + * GeometryCollection }{@code >} {@link JAXBElement }{@code <}{@link MultiPoint }{@code >} + * {@link JAXBElement }{@code <}{@link Object }{@code >} {@link JAXBElement }{@code <}{@link + * Point }{@code >} {@link JAXBElement }{@code <}{@link MultiLineString }{@code >} {@link + * JAXBElement }{@code <}{@link Polygon }{@code >} + */ + public JAXBElement getGeometryContent() { + return geometryContent; + } + + /** + * Sets the value of the geometryContent property. + * + * @param value allowed object is {@link JAXBElement }{@code <}{@link MultiPolygon }{@code >} + * {@link JAXBElement }{@code <}{@link LineString }{@code >} {@link JAXBElement }{@code + * <}{@link GeometryCollection }{@code >} {@link JAXBElement }{@code <}{@link MultiPoint + * }{@code >} {@link JAXBElement }{@code <}{@link Object }{@code >} {@link JAXBElement + * }{@code <}{@link Point }{@code >} {@link JAXBElement }{@code <}{@link MultiLineString + * }{@code >} {@link JAXBElement }{@code <}{@link Polygon }{@code >} + */ + public void setGeometryContent(JAXBElement value) { + this.geometryContent = value; + } +} diff --git a/src/extension/mapml/src/main/java/org/geoserver/mapml/xml/GeometryCollection.java b/src/extension/mapml/src/main/java/org/geoserver/mapml/xml/GeometryCollection.java index a4aba2fa919..c47eb7a5456 100644 --- a/src/extension/mapml/src/main/java/org/geoserver/mapml/xml/GeometryCollection.java +++ b/src/extension/mapml/src/main/java/org/geoserver/mapml/xml/GeometryCollection.java @@ -68,7 +68,8 @@ public class GeometryCollection { @XmlElement( name = "map-multipolygon", type = MultiPolygon.class, - namespace = "http://www.w3.org/1999/xhtml") + namespace = "http://www.w3.org/1999/xhtml"), + @XmlElement(name = "map-a", type = A.class, namespace = "http://www.w3.org/1999/xhtml") }) protected List pointOrLineStringOrPolygon; diff --git a/src/extension/mapml/src/main/java/org/geoserver/mapml/xml/ObjectFactory.java b/src/extension/mapml/src/main/java/org/geoserver/mapml/xml/ObjectFactory.java index e33c12f7f0d..035375d7562 100644 --- a/src/extension/mapml/src/main/java/org/geoserver/mapml/xml/ObjectFactory.java +++ b/src/extension/mapml/src/main/java/org/geoserver/mapml/xml/ObjectFactory.java @@ -55,6 +55,7 @@ public class ObjectFactory { new QName("http://www.w3.org/1999/xhtml", "map-properties"); private static final QName _MultiPointCoordinates_QNAME = new QName("http://www.w3.org/1999/xhtml", "map-coordinates"); + private static final QName _A_QNAME = new QName("http://www.w3.org/1999/xhtml", "map-a"); /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes @@ -296,6 +297,16 @@ public JAXBElement createPolygon(Polygon value) { return new JAXBElement<>(_Polygon_QNAME, Polygon.class, null, value); } + /** Create an instance of {@link JAXBElement }{@code <}{@link A }{@code >}} */ + @XmlElementDecl( + namespace = "http://www.w3.org/1999/xhtml", + name = "map-a", + substitutionHeadNamespace = "http://www.w3.org/1999/xhtml", + substitutionHeadName = "GeometryContent") + public JAXBElement createA(A value) { + return new JAXBElement<>(_A_QNAME, A.class, null, value); + } + /** Create an instance of {@link JAXBElement }{@code <}{@link PropertyContent }{@code >}} */ @XmlElementDecl(namespace = "http://www.w3.org/1999/xhtml", name = "map-properties") public JAXBElement createProperties(PropertyContent value) {