Skip to content

Commit

Permalink
Make tile layer use new legend info structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuno Oliveira committed Mar 17, 2017
1 parent e66d2ec commit b20ed4d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
Expand Up @@ -61,6 +61,8 @@
import org.geowebcache.GeoWebCacheException; import org.geowebcache.GeoWebCacheException;
import org.geowebcache.config.ConfigurationException; import org.geowebcache.config.ConfigurationException;
import org.geowebcache.config.XMLGridSubset; import org.geowebcache.config.XMLGridSubset;
import org.geowebcache.config.legends.LegendInfo;
import org.geowebcache.config.legends.LegendInfoBuilder;
import org.geowebcache.conveyor.ConveyorTile; import org.geowebcache.conveyor.ConveyorTile;
import org.geowebcache.filter.parameters.ParameterException; import org.geowebcache.filter.parameters.ParameterException;
import org.geowebcache.filter.parameters.ParameterFilter; import org.geowebcache.filter.parameters.ParameterFilter;
Expand Down Expand Up @@ -1271,38 +1273,38 @@ public void setBlobStoreId(String blobStoreId) {
} }


@Override @Override
public Map<String, LegendInfo> getLegendsInfo() { public Map<String, org.geowebcache.config.legends.LegendInfo> getLayerLegendsInfo() {
LayerInfo layerInfo = getLayerInfo(); LayerInfo layerInfo = getLayerInfo();
if (layerInfo == null) { if (layerInfo == null) {
return null; return null;
} }
Map<String, LegendInfo> legends = new HashMap<>(); Map<String, org.geowebcache.config.legends.LegendInfo> legends = new HashMap<>();
Set<StyleInfo> styles = new HashSet<>(layerInfo.getStyles()); Set<StyleInfo> styles = new HashSet<>(layerInfo.getStyles());
styles.add(layerInfo.getDefaultStyle()); styles.add(layerInfo.getDefaultStyle());
for (StyleInfo styleInfo : styles) { for (StyleInfo styleInfo : styles) {
org.geoserver.catalog.LegendInfo legendInfo = styleInfo.getLegend(); org.geoserver.catalog.LegendInfo legendInfo = styleInfo.getLegend();
LegendInfo gwcLegendInfo = new LegendInfo(); LegendInfoBuilder gwcLegendInfo = new LegendInfoBuilder();
if (legendInfo != null) { if (legendInfo != null) {
gwcLegendInfo.id = legendInfo.getId(); gwcLegendInfo.withStyleName(styleInfo.getName())
gwcLegendInfo.width = legendInfo.getWidth(); .withWidth(legendInfo.getWidth())
gwcLegendInfo.height = legendInfo.getHeight(); .withHeight(legendInfo.getHeight())
gwcLegendInfo.format = legendInfo.getFormat(); .withFormat(legendInfo.getFormat())
gwcLegendInfo.legendUrl = buildURL(RequestUtils.baseURL(Dispatcher.REQUEST.get().getHttpRequest()), .withCompleteUrl(buildURL(RequestUtils.baseURL(Dispatcher.REQUEST.get().getHttpRequest()),
legendInfo.getOnlineResource(), null, URLMangler.URLType.RESOURCE); legendInfo.getOnlineResource(), null, URLMangler.URLType.RESOURCE));
legends.put(styleInfo.prefixedName(), gwcLegendInfo); legends.put(styleInfo.prefixedName(), gwcLegendInfo.build());
} else { } else {
int finalWidth = GetLegendGraphicRequest.DEFAULT_WIDTH;
int finalHeight = GetLegendGraphicRequest.DEFAULT_HEIGHT;
String finalFormat = GetLegendGraphicRequest.DEFAULT_FORMAT;
try { try {
gwcLegendInfo.width = GetLegendGraphicRequest.DEFAULT_WIDTH;
gwcLegendInfo.height = GetLegendGraphicRequest.DEFAULT_HEIGHT;
Dimension dimension = getLegendSample().getLegendURLSize(styleInfo); Dimension dimension = getLegendSample().getLegendURLSize(styleInfo);
if (dimension != null) { if (dimension != null) {
gwcLegendInfo.width = (int) dimension.getWidth(); finalWidth = (int) dimension.getWidth();
gwcLegendInfo.height = (int) dimension.getHeight(); finalHeight = (int) dimension.getHeight();
} }
gwcLegendInfo.format = GetLegendGraphicRequest.DEFAULT_FORMAT; if (null == getWms().getLegendGraphicOutputFormat(finalFormat)) {
if (null == getWms().getLegendGraphicOutputFormat(gwcLegendInfo.format)) {
if (LOGGER.isLoggable(Level.WARNING)) { if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning("Default legend format (" + gwcLegendInfo.format + LOGGER.warning("Default legend format (" + finalFormat +
")is not supported (jai not available?), can't add LegendURL element"); ")is not supported (jai not available?), can't add LegendURL element");
} }
continue; continue;
Expand All @@ -1312,15 +1314,19 @@ public Map<String, LegendInfo> getLegendsInfo() {
} }
String layerName = layerInfo.prefixedName(); String layerName = layerInfo.prefixedName();
Map<String, String> params = params("service", "WMS", "request", Map<String, String> params = params("service", "WMS", "request",
"GetLegendGraphic", "format", gwcLegendInfo.format, "width", "GetLegendGraphic", "format", finalFormat, "width",
String.valueOf(gwcLegendInfo.width), "height", String.valueOf(finalWidth), "height",
String.valueOf(gwcLegendInfo.height), "layer", layerName); String.valueOf(finalHeight), "layer", layerName);
if (!styleInfo.getName().equals(layerInfo.getDefaultStyle().getName())) { if (!styleInfo.getName().equals(layerInfo.getDefaultStyle().getName())) {
params.put("style", styleInfo.getName()); params.put("style", styleInfo.getName());
} }
gwcLegendInfo.legendUrl = buildURL(RequestUtils.baseURL(Dispatcher.REQUEST.get().getHttpRequest()), gwcLegendInfo.withStyleName(styleInfo.getName())
"ows", params, URLMangler.URLType.SERVICE); .withWidth(finalWidth)
legends.put(styleInfo.prefixedName(), gwcLegendInfo); .withHeight(finalHeight)
.withFormat(finalFormat)
.withCompleteUrl(buildURL(RequestUtils.baseURL(
Dispatcher.REQUEST.get().getHttpRequest()), "ows", params, URLMangler.URLType.SERVICE));
legends.put(styleInfo.prefixedName(), gwcLegendInfo.build());
} }
} }
return legends; return legends;
Expand Down
Expand Up @@ -770,28 +770,28 @@ public void testGetLegendsLayer() throws Exception {
GeoServerTileLayer tileLayer = new GeoServerTileLayer(layerInfo, defaults, gridSetBroker); GeoServerTileLayer tileLayer = new GeoServerTileLayer(layerInfo, defaults, gridSetBroker);
tileLayer.setLegendSample(legendSample); tileLayer.setLegendSample(legendSample);
tileLayer.setWms(wms); tileLayer.setWms(wms);
Map<String, TileLayer.LegendInfo> legendsInfo = tileLayer.getLegendsInfo(); Map<String, org.geowebcache.config.legends.LegendInfo> legendsInfo = tileLayer.getLayerLegendsInfo();
assertThat(legendsInfo.size(), is(3)); assertThat(legendsInfo.size(), is(3));
// default_style // default_style
assertThat(legendsInfo.get("default_style"), notNullValue()); assertThat(legendsInfo.get("default_style"), notNullValue());
assertThat(legendsInfo.get("default_style").width, is(120)); assertThat(legendsInfo.get("default_style").getWidth(), is(120));
assertThat(legendsInfo.get("default_style").height, is(150)); assertThat(legendsInfo.get("default_style").getHeight(), is(150));
assertThat(legendsInfo.get("default_style").format, is("image/png")); assertThat(legendsInfo.get("default_style").getFormat(), is("image/png"));
assertThat(legendsInfo.get("default_style").legendUrl, is("http://localhost:8080/geoserver/ows?service=" + assertThat(legendsInfo.get("default_style").getLegendUrl(), is("http://localhost:8080/geoserver/ows?service=" +
"WMS&request=GetLegendGraphic&format=image%2Fpng&width=120&height=150&layer=workspace%3AMockLayerInfoName")); "WMS&request=GetLegendGraphic&format=image%2Fpng&width=120&height=150&layer=workspace%3AMockLayerInfoName"));
// alternateStyle-1 // alternateStyle-1
assertThat(legendsInfo.get("alternateStyle-1"), notNullValue()); assertThat(legendsInfo.get("alternateStyle-1"), notNullValue());
assertThat(legendsInfo.get("alternateStyle-1").width, is(120)); assertThat(legendsInfo.get("alternateStyle-1").getWidth(), is(120));
assertThat(legendsInfo.get("alternateStyle-1").height, is(150)); assertThat(legendsInfo.get("alternateStyle-1").getHeight(), is(150));
assertThat(legendsInfo.get("alternateStyle-1").format, is("image/png")); assertThat(legendsInfo.get("alternateStyle-1").getFormat(), is("image/png"));
assertThat(legendsInfo.get("alternateStyle-1").legendUrl, is("http://localhost:8080/geoserver/ows?service" + assertThat(legendsInfo.get("alternateStyle-1").getLegendUrl(), is("http://localhost:8080/geoserver/ows?service" +
"=WMS&request=GetLegendGraphic&format=image%2Fpng&width=120&height=150&layer=workspace%3AMockLayerInfoName&style=alternateStyle-1")); "=WMS&request=GetLegendGraphic&format=image%2Fpng&width=120&height=150&layer=workspace%3AMockLayerInfoName&style=alternateStyle-1"));
// alternateStyle-2 // alternateStyle-2
assertThat(legendsInfo.get("alternateStyle-2"), notNullValue()); assertThat(legendsInfo.get("alternateStyle-2"), notNullValue());
assertThat(legendsInfo.get("alternateStyle-2").width, is(150)); assertThat(legendsInfo.get("alternateStyle-2").getWidth(), is(150));
assertThat(legendsInfo.get("alternateStyle-2").height, is(200)); assertThat(legendsInfo.get("alternateStyle-2").getHeight(), is(200));
assertThat(legendsInfo.get("alternateStyle-2").format, is("image/png")); assertThat(legendsInfo.get("alternateStyle-2").getFormat(), is("image/png"));
assertThat(legendsInfo.get("alternateStyle-2").legendUrl.trim(), is("http://localhost:8080/geoserver/some-url")); assertThat(legendsInfo.get("alternateStyle-2").getLegendUrl().trim(), is("http://localhost:8080/geoserver/some-url"));
} }


private void setupUrlContext() { private void setupUrlContext() {
Expand Down

0 comments on commit b20ed4d

Please sign in to comment.