Skip to content

Commit

Permalink
Fixed MapML dimension support, other MapML improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhodgson committed Apr 5, 2019
1 parent 7031a2f commit 6714005
Show file tree
Hide file tree
Showing 17 changed files with 376 additions and 204 deletions.
4 changes: 4 additions & 0 deletions src/community/mapml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-main</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public MapMLConfigurationPanel(final String panelId, final IModel<LayerInfo> mod
"mapml.enableSharding");
CheckBox enableSharding = new CheckBox("enableSharding", enableShardingModel);
add(enableSharding);

MapModel<String> shardListModel =
new MapModel<String>(
new PropertyModel<MetadataMap>(model, "resource.metadata"),
Expand All @@ -71,21 +71,21 @@ public MapMLConfigurationPanel(final String panelId, final IModel<LayerInfo> mod
new MapModel<String>(
new PropertyModel<MetadataMap>(model, "resource.metadata"),
"mapml.shardServerPattern");
TextField<String> shardServerPattern = new TextField<String>("shardServerPattern", shardServerPatternModel);
TextField<String> shardServerPattern =
new TextField<String>("shardServerPattern", shardServerPatternModel);
add(shardServerPattern);

MapModel<String> dimensionModel =
new MapModel<String>(
new PropertyModel<MetadataMap>(model, "resource.metadata"),
"mapml.dimension");
DropDownChoice<String> dimension = new DropDownChoice<String>(
"dimension",
dimensionModel,
getEnabledDimensionNames(model.getObject()));
DropDownChoice<String> dimension =
new DropDownChoice<String>(
"dimension", dimensionModel, getEnabledDimensionNames(model.getObject()));
dimension.setNullValid(true);
add(dimension);
}

List<String> getEnabledDimensionNames(LayerInfo layer) {
List<String> dimensionNames = new ArrayList<String>();
for (Map.Entry<String, Serializable> entry : layer.getResource().getMetadata().entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.geoserver.mapml;

import java.text.SimpleDateFormat;

public final class MapMLConstants {

/** format mime type */
Expand All @@ -8,4 +10,6 @@ public final class MapMLConstants {
/** format name */
public static final String FORMAT_NAME = "MAPML";

public static final SimpleDateFormat DATE_FORMAT =
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package org.geoserver.mapml;

import static org.geoserver.mapml.MapMLConstants.*;

import java.io.IOException;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import org.geoserver.catalog.DimensionInfo;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.MetadataMap;
import org.geoserver.catalog.ResourceInfo;
Expand All @@ -28,6 +34,7 @@
import org.geoserver.mapml.xml.RelType;
import org.geoserver.mapml.xml.UnitType;
import org.geoserver.ows.util.ResponseUtils;
import org.geoserver.wms.WMS;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.CRS;
import org.geotools.util.logging.Logging;
Expand All @@ -53,18 +60,19 @@ public class MapMLController {
private static final Logger LOGGER = Logging.getLogger("org.geoserver.mapml");

@Autowired GeoServer geoServer;
@Autowired WMS wms;

@RequestMapping(
value = "/{layer}/{proj}",
method = {RequestMethod.GET, RequestMethod.POST},
produces = MapMLConstants.MIME_TYPE
produces = MIME_TYPE
)
public Mapml mapML(
HttpServletRequest request,
@PathVariable("layer") String layer,
@PathVariable("proj") String proj,
@RequestParam("style") Optional<String> style)
throws NoSuchAuthorityCodeException, TransformException, FactoryException {
throws NoSuchAuthorityCodeException, TransformException, FactoryException, IOException {
LayerInfo layerInfo = geoServer.getCatalog().getLayerByName(layer);
if (layerInfo == null) {
// TODO error handling
Expand Down Expand Up @@ -109,23 +117,23 @@ public Mapml mapML(
String styleName = style.orElse("");
String baseUrl = ResponseUtils.baseURL(request);
String baseUrlPattern = baseUrl;

// handle shard config
Boolean enableSharding = layerMeta.get("mapml.enableSharding", Boolean.class);
String shardListString = layerMeta.get("mapml.shardList", String.class);
String[] shardArray = new String[0];
if(shardListString != null) {
if (shardListString != null) {
shardArray = shardListString.split("[,\\s]+");
}
String shardServerPattern = layerMeta.get("mapml.shardServerPattern", String.class);
if(shardArray.length < 1 || shardServerPattern == null || shardServerPattern.isEmpty()) {
if (shardArray.length < 1 || shardServerPattern == null || shardServerPattern.isEmpty()) {
enableSharding = Boolean.FALSE;
}
// if we have a valid shard config
if(Boolean.TRUE.equals(enableSharding)) {
if (Boolean.TRUE.equals(enableSharding)) {
baseUrlPattern = shardBaseURL(request, shardServerPattern);
}

// build the mapML doc
Mapml mapml = new Mapml();

Expand All @@ -141,7 +149,7 @@ public Mapml mapML(
metas.add(meta);
meta = new Meta();
meta.setHttpEquiv("Content-Type");
meta.setContent(MapMLConstants.MIME_TYPE + ";projection=" + projType.value());
meta.setContent(MIME_TYPE + ";projection=" + projType.value());
metas.add(meta);
List<Link> links = head.getLinks();

Expand Down Expand Up @@ -186,13 +194,13 @@ public Mapml mapML(
Input input = new Input();
input.setName("z");
input.setType(InputType.ZOOM);
input.setValue("0");
input.setValue("0");
input.setMin(0);
input.setMax(0);
extentList.add(input);

// shard list
if(Boolean.TRUE.equals(enableSharding)) {
if (Boolean.TRUE.equals(enableSharding)) {
input = new Input();
input.setName("s");
input.setType(InputType.HIDDEN);
Expand All @@ -202,21 +210,65 @@ public Mapml mapML(
Datalist datalist = new Datalist();
datalist.setId("servers");
List<Option> options = datalist.getOptions();
for(int s = 0; s < shardArray.length; s++) {
for (int s = 0; s < shardArray.length; s++) {
Option o = new Option();
o.setValue(shardArray[s]);
options.add(o);
}
extentList.add(datalist);
}

String dimension = layerMeta.get("mapml.dimension", String.class);
if("Time".equalsIgnoreCase(dimension)) {

} else if("Elevation".equalsIgnoreCase(dimension)) {

boolean timeEnabled = false;
boolean elevationEnabled = false;
if ("Time".equalsIgnoreCase(dimension)) {
if (resourceInfo instanceof FeatureTypeInfo) {
FeatureTypeInfo typeInfo = (FeatureTypeInfo) resourceInfo;
DimensionInfo timeInfo =
typeInfo.getMetadata().get(ResourceInfo.TIME, DimensionInfo.class);
if (timeInfo.isEnabled()) {
timeEnabled = true;
Set<Date> dates = wms.getFeatureTypeTimes(typeInfo);
input = new Input();
input.setName("time");
input.setList("dimList");
extentList.add(input);
Datalist datalist = new Datalist();
datalist.setId("dimList");
List<Option> options = datalist.getOptions();
for (Date date : dates) {
Option o = new Option();
o.setValue(DATE_FORMAT.format(date));
options.add(o);
}
extentList.add(datalist);
}
}
} else if ("Elevation".equalsIgnoreCase(dimension)) {
if (resourceInfo instanceof FeatureTypeInfo) {
FeatureTypeInfo typeInfo = (FeatureTypeInfo) resourceInfo;
DimensionInfo elevInfo =
typeInfo.getMetadata().get(ResourceInfo.ELEVATION, DimensionInfo.class);
if (elevInfo.isEnabled()) {
elevationEnabled = true;
Set<Double> elevs = wms.getFeatureTypeElevations(typeInfo);
input = new Input();
input.setName("elevation");
input.setList("dimList");
extentList.add(input);
Datalist datalist = new Datalist();
datalist.setId("dimList");
List<Option> options = datalist.getOptions();
for (Double elev : elevs) {
Option o = new Option();
o.setValue(elev.toString());
options.add(o);
}
extentList.add(datalist);
}
}
}

Boolean useTiles = layerMeta.get("mapml.useTiles", Boolean.class);
if (Boolean.TRUE.equals(useTiles)) {
// tile inputs
Expand Down Expand Up @@ -276,6 +328,8 @@ public Mapml mapML(
+ layerInfo.getName()
+ "&styles="
+ styleName
+ (timeEnabled ? "&time={time}" : "")
+ (elevationEnabled ? "&elevation={elevation}" : "")
+ "&bbox={txmin},{tymin},{txmax},{tymax}&format=image/png&transparent=false&width=256&height=256");
extentList.add(link);
} else {
Expand Down Expand Up @@ -352,6 +406,8 @@ public Mapml mapML(
+ layerInfo.getName()
+ "&styles="
+ styleName
+ (timeEnabled ? "&time={time}" : "")
+ (elevationEnabled ? "&elevation={elevation}" : "")
+ "&bbox={xmin},{ymin},{xmax},{ymax}&format=image/png&transparent=false&width={w}&height={h}");
extentList.add(link);
}
Expand Down Expand Up @@ -388,10 +444,13 @@ public Mapml mapML(
+ layerInfo.getName()
+ "&styles="
+ styleName
+ "&bbox={xmin},{ymin},{xmax},{ymax}"
+ (timeEnabled ? "&time={time}" : "")
+ (elevationEnabled ? "&elevation={elevation}" : "")
+ (Boolean.TRUE.equals(useTiles)
? "&bbox={txmin},{tymin},{txmax},{tymax}&width=256&height=256"
: "&bbox={xmin},{ymin},{xmax},{ymax}&width={w}&height={h}")
+ "&info_format=text/mapml"
+ "&transparent=false"
+ "&width={w}&height={h}"
+ "&x={i}&y={j}");
extentList.add(link);
}
Expand All @@ -400,7 +459,7 @@ public Mapml mapML(
mapml.setBody(body);
return mapml;
}

private static String shardBaseURL(HttpServletRequest req, String shardServerPattern) {
StringBuffer sb = new StringBuffer(req.getScheme());
sb.append("://")
Expand Down

0 comments on commit 6714005

Please sign in to comment.