Skip to content

Commit

Permalink
[GEOS-9092] Add JSON as a Legend Output format (GISP 173)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianturton authored and aaime committed Jan 10, 2019
1 parent e04f36d commit 6ad2b67
Show file tree
Hide file tree
Showing 63 changed files with 5,198 additions and 1,019 deletions.
850 changes: 570 additions & 280 deletions doc/en/user/source/services/wms/get_legend_graphic/index.rst

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion doc/en/user/source/styling/sld/reference/linesymbolizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ with a repeating graphic image or symbol.
The graphic is specified by a ``<Graphic>`` sub-element,
which is described in the ``PointSymbolizer`` :ref:`sld_reference_graphic` section.


.. _sld_reference_linesymbolizer_graphicstroke:

GraphicStroke
^^^^^^^^^^^^^

Expand All @@ -89,6 +92,8 @@ which is described in the ``PointSymbolizer`` :ref:`sld_reference_graphic` secti
The spacing of the graphic symbol can be specified using the ``<Size>`` element in the ``<Graphic>`` element,
or the ``<CSSParameter name="stroke-dasharray">`` in the ``Stroke`` element.

.. _sld_reference_linesymbolizer_css:

CssParameter
^^^^^^^^^^^^

Expand Down Expand Up @@ -228,4 +233,4 @@ The following style excerpt builds a inward offset line for polygons.
:align: center

*Inwards offset line*


5 changes: 1 addition & 4 deletions src/kml/src/main/java/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
<constructor-arg ref="geoServer"/>
</bean>

<!-- icon service -->
<bean id="kmlIconService" class="org.geoserver.kml.icons.IconService">
<constructor-arg ref="catalog"/>
</bean>


<!-- http url mapping -->
<bean id="kmlURLMapping" class="org.geoserver.ows.OWSHandlerMapping">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.imageio.ImageIO;
import org.geoserver.kml.icons.IconRenderer;
import org.geoserver.platform.Operation;
import org.geoserver.platform.ServiceException;
import org.geoserver.wms.WMS;
import org.geoserver.wms.WMSMapContent;
import org.geoserver.wms.icons.IconRenderer;
import org.geoserver.wms.map.AbstractMapResponse;
import org.geoserver.wms.map.PNGMapResponse;
import org.geoserver.wms.map.RenderedImageMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import java.util.logging.Logger;
import org.geoserver.catalog.WorkspaceInfo;
import org.geoserver.kml.KmlEncodingContext;
import org.geoserver.kml.icons.IconProperties;
import org.geoserver.kml.icons.IconPropertyExtractor;
import org.geoserver.kml.icons.IconPropertyInjector;
import org.geoserver.wms.WMSInfo;
import org.geoserver.wms.icons.IconProperties;
import org.geoserver.wms.icons.IconPropertyExtractor;
import org.geoserver.wms.icons.IconPropertyInjector;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.renderer.style.ExpressionExtractor;
import org.geotools.styling.Fill;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import java.util.List;
import org.geoserver.kml.KmlEncodingContext;
import org.geoserver.kml.decorator.PlacemarkStyleDecoratorFactory.PlacemarkStyleDecorator;
import org.geoserver.kml.icons.IconTestSupport;
import org.geotools.data.DataUtilities;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.styling.TextSymbolizer;
import org.junit.Test;
import org.opengis.feature.simple.SimpleFeatureType;

public class PlacemarkStyleDecoratorTest extends IconTestSupport {
public class PlacemarkStyleDecoratorTest extends org.geoserver.wms.icons.IconTestSupport {

/**
* Test partial style transformation.
Expand Down
1 change: 1 addition & 0 deletions src/wms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-ows</artifactId>
Expand Down
17 changes: 15 additions & 2 deletions src/wms/src/main/java/applicationContext.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright (C) 2014 - 2016 Open Source Geospatial Foundation. All rights reserved.
This code is licensed under the GPL 2.0 license, available at the root
Expand Down Expand Up @@ -398,14 +398,21 @@
</bean>

<bean id="stylesResponse" class="org.geoserver.sld.GetStylesResponse"/>


<!-- icon service -->
<bean id="kmlIconService"
class="org.geoserver.wms.icons.IconService">
<constructor-arg ref="catalog" />
</bean>

<!-- http url mapping -->
<bean id="wmsURLMapping"
class="org.geoserver.ows.OWSHandlerMapping">
<constructor-arg ref="catalog"/>
<property name="alwaysUseFullPath" value="true"/>
<property name="mappings">
<props>
<prop key="/kml/icon/**/*">kmlIconService</prop>
<prop key="/wms">dispatcher</prop>
<prop key="/wms/*">dispatcher</prop>
</props>
Expand All @@ -432,6 +439,12 @@
<bean id="wmsPNGLegendGraphicResponse"
class="org.geoserver.wms.legendgraphic.PNGLegendGraphicResponse">
</bean>
<bean id="wmsJSONLegendOutputFormat"
class="org.geoserver.wms.legendgraphic.JSONLegendOutputFormat">
</bean>
<bean id="wmsJSONLegendGraphicResponse"
class="org.geoserver.wms.legendgraphic.JSONLegendGraphicResponse">
</bean>

<!--
Map producers and responses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class LegendRequest {
/** Optional rule used to refine presentation of style */
private String rule;

/** Style deterimed from a review of request parameters */
/** Style determined from a review of request parameters */
private Style style;

/** Optional legend info (from layer info or style info) */
Expand All @@ -112,6 +112,8 @@ public class LegendRequest {

/** Optional layer group info (if available ) */
private LayerGroupInfo layerGroupInfo;
/** link back to the WMS */
private WMS wms;

/** LegendRequest for a style, no associated featureType. */
public LegendRequest() {
Expand All @@ -126,12 +128,13 @@ public LegendRequest() {
*
* @param featureType
*/
public LegendRequest(FeatureType featureType) {
public LegendRequest(FeatureType featureType, WMS wms) {
if (featureType == null) {
throw new NullPointerException("FeatureType required for LegendRequest");
}
this.featureType = featureType;
this.layerName = featureType.getName();
this.wms = wms;
}

/**
Expand All @@ -140,13 +143,15 @@ public LegendRequest(FeatureType featureType) {
*
* @param featureType
* @param layerName layerName distinct to featureType name
* @param wms
*/
public LegendRequest(FeatureType featureType, Name layerName) {
public LegendRequest(FeatureType featureType, Name layerName, WMS wms) {
if (featureType == null) {
throw new NullPointerException("FeatureType required for LegendRequest");
}
this.featureType = featureType;
this.layerName = layerName;
this.wms = wms;
}

public String getLayer() {
Expand Down Expand Up @@ -248,6 +253,7 @@ public Style getStyle() {

public void setStyle(Style style) {
this.style = style;
if (style != null) this.styleName = style.getName();
}

public LegendInfo getLegendInfo() {
Expand Down Expand Up @@ -343,13 +349,18 @@ public String toString() {

private WMS wms;

public GetLegendGraphicRequest() {
super("GetLegendGraphic");
this.wms = WMS.get();
}
/**
* Creates a new GetLegendGraphicRequest object.
*
* @param wms The WMS configuration object.
*/
public GetLegendGraphicRequest() {
public GetLegendGraphicRequest(WMS wms) {
super("GetLegendGraphic");
this.wms = wms;
}

public String getExceptions() {
Expand Down Expand Up @@ -415,7 +426,7 @@ public List<FeatureType> getLayers() {
public void setLayers(List<FeatureType> layers) {
List<LegendRequest> list = new ArrayList<LegendRequest>(layers.size());
for (FeatureType type : layers) {
LegendRequest legendRequest = new LegendRequest(type);
LegendRequest legendRequest = new LegendRequest(type, wms);
list.add(legendRequest);
}
this.legends = list;
Expand Down Expand Up @@ -470,7 +481,7 @@ public void setLayer(FeatureType layer) {
if (layer == null) {
this.legends.add(new LegendRequest());
} else {
this.legends.add(new LegendRequest(layer));
this.legends.add(new LegendRequest(layer, wms));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import org.geoserver.platform.resource.Resource.Type;
import org.geoserver.wms.GetLegendGraphicOutputFormat;
import org.geoserver.wms.GetLegendGraphicRequest;
import org.geoserver.wms.WMS;
import org.geoserver.wms.legendgraphic.BufferedImageLegendGraphic;
import org.geoserver.wms.legendgraphic.LegendGraphic;
import org.geoserver.wms.legendgraphic.PNGLegendOutputFormat;
import org.opengis.feature.type.FeatureType;

Expand Down Expand Up @@ -194,7 +196,7 @@ private boolean isSampleExisting(Resource sampleLegend) {
*/
private Dimension createNewSample(StyleInfo style, GetLegendGraphicOutputFormat pngOutputFormat)
throws Exception {
GetLegendGraphicRequest legendGraphicRequest = new GetLegendGraphicRequest();
GetLegendGraphicRequest legendGraphicRequest = new GetLegendGraphicRequest(WMS.get());
Resource sampleLegendFolder = getSamplesFolder();

legendGraphicRequest.setStrict(false);
Expand All @@ -203,7 +205,7 @@ private Dimension createNewSample(StyleInfo style, GetLegendGraphicOutputFormat
legendGraphicRequest.setFormat(pngOutputFormat.getContentType());
Object legendGraphic = pngOutputFormat.produceLegendGraphic(legendGraphicRequest);
if (legendGraphic instanceof BufferedImageLegendGraphic) {
BufferedImage image = ((BufferedImageLegendGraphic) legendGraphic).getLegend();
BufferedImage image = (BufferedImage) ((LegendGraphic) legendGraphic).getLegend();

PNGWriter writer = new PNGWriter();
OutputStream outStream = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.kml.icons;
package org.geoserver.wms.icons;

import java.io.File;
import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -202,12 +202,12 @@ public boolean isExternal() {

@Override
public Style inject(Style base) {
throw new RuntimeException("An implementation is missing");
return IconPropertyInjector.injectProperties(base, null);
}

@Override
public Map<String, String> getProperties() {
throw new RuntimeException("An implementation is missing");
return Collections.emptyMap();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.kml.icons;
package org.geoserver.wms.icons;

import java.net.MalformedURLException;
import java.util.List;
Expand Down Expand Up @@ -40,6 +40,11 @@ private IconProperties propertiesFor(SimpleFeature feature) {
return new FeatureProperties(feature).properties();
}

public static IconProperties extractProperties(
List<List<MiniRule>> style, SimpleFeature feature) {
return new IconPropertyExtractor(style).propertiesFor(feature);
}

public static IconProperties extractProperties(Style style, SimpleFeature feature) {
return new IconPropertyExtractor(MiniRule.minify(style)).propertiesFor(feature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.kml.icons;
package org.geoserver.wms.icons;

import java.net.MalformedURLException;
import java.net.URL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.kml.icons;
package org.geoserver.wms.icons;

import java.awt.Graphics2D;
import java.awt.Rectangle;
Expand Down Expand Up @@ -38,7 +38,7 @@
public final class IconRenderer {
private static final ReferencedEnvelope sampleArea = new ReferencedEnvelope(-1, 1, -1, 1, null);
private static final SimpleFeatureCollection sampleData;
static Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.geoserver.kml.icons");
static Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.geoserver.wms.icons");

static {
SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.kml.icons;
package org.geoserver.wms.icons;

import java.awt.image.BufferedImage;
import java.io.IOException;
Expand Down Expand Up @@ -39,7 +39,7 @@ public IconService(Catalog catalog) {
}

@Override
protected ModelAndView handleRequestInternal(
public ModelAndView handleRequestInternal(
HttpServletRequest request, HttpServletResponse response) throws Exception {

String path = request.getPathInfo();
Expand All @@ -49,7 +49,7 @@ protected ModelAndView handleRequestInternal(
400, "Bad request, path must be of form: /icons/[<workspace>/]<style>");
return null;
}

// this is wrong - matches 2 even when no workspace in url!
String workspace = null, styleName = null;
if (m.groupCount() == 2) {
workspace = m.group(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.kml.icons;
package org.geoserver.wms.icons;

import java.net.MalformedURLException;
import java.util.Iterator;
Expand All @@ -28,7 +28,7 @@
* @author Kevin Smith, OpenGeo
*/
public class Icons {
static Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.geoserver.kml.icons");
static Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.geoserver.wms.icons");

/**
* Render symbols this much bigger than they should be then shrink them down in the KML. This
Expand Down

0 comments on commit 6ad2b67

Please sign in to comment.