Skip to content

Commit

Permalink
[GEOS-11294b] mapml wms vector representation query filter
Browse files Browse the repository at this point in the history
wildcard import removed

abstract parent needs the mime

file license

cleanup

fixed test issues with projection

validating sld filters

added getStyleQuery test

Moved to util class

cleanup

test fix

removed unnecessary inheritance

cleanup

pr response

PR responses and fix to resource vs layer metadata issue

html version now adds feature kv

html source link should return mapml not features

added cql-filter test to sld filter test
  • Loading branch information
turingtestfail committed Mar 6, 2024
1 parent fb441ee commit 0f13cdf
Show file tree
Hide file tree
Showing 13 changed files with 958 additions and 420 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,14 @@ private MapMLLayerMetadata layersToOneMapMLLayerMetadata(List<RawLayer> layers)
*/
private boolean allLayersUsingFeatures(List<RawLayer> layers) {
for (RawLayer layer : layers) {
Boolean useFeatures =
layer.getPublishedInfo().getMetadata().get(MAPML_USE_FEATURES, Boolean.class);
Boolean isVector = (PublishedType.VECTOR == layer.getPublishedInfo().getType());
if (useFeatures == null || isVector == null || !useFeatures || !isVector) {
boolean useFeatures =
Optional.ofNullable(layer.getPublishedInfo())
.filter(l -> l instanceof LayerInfo)
.map(l -> ((LayerInfo) l).getResource())
.map(r -> r.getMetadata().get(MAPML_USE_FEATURES, Boolean.class))
.orElse(false);
boolean isVector = (PublishedType.VECTOR == layer.getPublishedInfo().getType());
if (!useFeatures || !isVector) {
return false;
}
}
Expand Down Expand Up @@ -1632,7 +1636,8 @@ public String getMapMLHTMLDocument() {
height,
escapeHtml4(proj),
styleName,
format))
format,
useFeaturesAllLayers))
.append("\" checked></layer->\n")
.append("</mapml-viewer>\n")
.append("</body>\n")
Expand All @@ -1648,7 +1653,8 @@ private String buildGetMap(
int width,
String proj,
String styleName,
Optional<Object> format) {
Optional<Object> format,
Boolean useFeaturesAllLayers) {
Map<String, String> kvp = new LinkedHashMap<>();
kvp.put("LAYERS", escapeHtml4(layer));
kvp.put("BBOX", toCommaDelimitedBbox(projectedBbox));
Expand All @@ -1657,11 +1663,13 @@ private String buildGetMap(
kvp.put("SRS", escapeHtml4(proj));
kvp.put("STYLES", escapeHtml4(styleName));
kvp.put("FORMAT", MAPML_MIME_TYPE);
kvp.put(
"format_options",
String formatOptions =
MapMLConstants.MAPML_WMS_MIME_TYPE_OPTION
+ ":"
+ escapeHtml4((String) format.orElse("image/png")));
+ escapeHtml4((String) format.orElse("image/png"));
if (!useFeaturesAllLayers) {
kvp.put("format_options", formatOptions);
}
kvp.put("SERVICE", "WMS");
kvp.put("REQUEST", "GetMap");
kvp.put("VERSION", "1.3.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.geoserver.wms.MapLayerInfo;
import org.geoserver.wms.WMSMapContent;
import org.geotools.api.data.FeatureSource;
import org.geotools.api.data.Query;
import org.geotools.api.feature.type.FeatureType;
import org.geotools.api.feature.type.GeometryDescriptor;
import org.geotools.api.referencing.FactoryException;
Expand All @@ -33,21 +34,23 @@ public class MapMLFeaturesBuilder {
private final GeoServer geoServer;
private final WMSMapContent mapContent;
private final GetMapRequest getMapRequest;
private final Query query;

/**
* Constructor
*
* @param mapContent the WMS map content
* @param geoServer the GeoServer
*/
public MapMLFeaturesBuilder(WMSMapContent mapContent, GeoServer geoServer) {
public MapMLFeaturesBuilder(WMSMapContent mapContent, GeoServer geoServer, Query query) {
this.geoServer = geoServer;
this.mapContent = mapContent;
this.getMapRequest = mapContent.getRequest();
featureSources =
mapContent.layers().stream()
.map(Layer::getFeatureSource)
.collect(Collectors.toList());
this.query = query;
}

/**
Expand All @@ -67,7 +70,12 @@ public Mapml getMapMLDocument() throws IOException {
throw new ServiceException(
"MapML WMS Feature format does not currently support non-vector layers.");
}
FeatureCollection featureCollection = featureSources.get(0).getFeatures();
FeatureCollection featureCollection = null;
if (query != null) {
featureCollection = featureSources.get(0).getFeatures(query);
} else {
featureCollection = featureSources.get(0).getFeatures();
}
if (!(featureCollection instanceof SimpleFeatureCollection)) {
throw new ServiceException(
"MapML WMS Feature format does not currently support Complex Features.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
import org.geoserver.ows.Request;
import org.geoserver.platform.ServiceException;
import org.geoserver.wms.GetMapOutputFormat;
import org.geoserver.wms.MapLayerInfo;
import org.geoserver.wms.MapProducerCapabilities;
import org.geoserver.wms.WMS;
import org.geoserver.wms.WMSMapContent;
import org.geoserver.wms.WebMap;
import org.geoserver.wms.map.StyleQueryUtil;
import org.geotools.api.data.Query;

/** Handles a GetMap request that for a map in MapML format. */
public class MapMLMapOutputFormat implements GetMapOutputFormat {
Expand Down Expand Up @@ -55,8 +58,27 @@ public WebMap produceMap(WMSMapContent mapContent) throws ServiceException, IOEx
HttpServletRequest httpServletRequest = request.getHttpRequest();
String formatOptions = httpServletRequest.getParameter("format_options");
if (formatOptions != null && formatOptions.contains(MAPML_FEATURE_FORMAT_OPTIONS)) {
if (mapContent.layers() != null && mapContent.layers().size() > 1) {
throw new ServiceException(
"MapML WMS Feature format does not currently support Multiple Feature Type output.");
}
if (!mapContent.getRequest().getLayers().isEmpty()
&& MapLayerInfo.TYPE_VECTOR
!= mapContent.getRequest().getLayers().get(0).getType()) {
throw new ServiceException(
"MapML WMS Feature format does not currently support non-vector layers.");
}
List<Query> queries = StyleQueryUtil.getStyleQuery(mapContent.layers(), mapContent);
Query query = null;
if (queries != null && !queries.isEmpty()) {
if (queries.size() > 1) {
throw new ServiceException(
"MapML WMS Feature format does not currently support Multiple Feature Type output.");
}
query = queries.get(0);
}
MapMLFeaturesBuilder mapMLFeaturesBuilder =
new MapMLFeaturesBuilder(mapContent, geoServer);
new MapMLFeaturesBuilder(mapContent, geoServer, query);
return new MapMLMap(mapContent, mapMLFeaturesBuilder.getMapMLDocument());
} else {
MapMLDocumentBuilder mapMLDocumentBuilder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class MapMLTestSupport extends WMSTestSupport {
* @param name the name of the layer
* @param kvp the key value pairs
* @param locale the locale
* @param bbox the bounding box
* @param srs the SRS
* @param styles the styles
* @return the MapML object
Expand All @@ -34,12 +35,13 @@ protected Mapml getWMSAsMapML(
String name,
Map kvp,
Locale locale,
String bbox,
String srs,
String styles,
boolean isFeatureRepresentation)
throws Exception {
MockHttpServletRequest request =
getMapMLWMSRequest(name, kvp, locale, srs, styles, isFeatureRepresentation);
getMapMLWMSRequest(name, kvp, locale, bbox, srs, styles, isFeatureRepresentation);
MockHttpServletResponse response = dispatch(request);
return mapml(response);
}
Expand All @@ -48,12 +50,13 @@ protected String getWMSAsMapMLString(
String name,
Map kvp,
Locale locale,
String bbox,
String srs,
String styles,
boolean isFeatureRepresentation)
throws Exception {
MockHttpServletRequest request =
getMapMLWMSRequest(name, kvp, locale, srs, styles, isFeatureRepresentation);
getMapMLWMSRequest(name, kvp, locale, bbox, srs, styles, isFeatureRepresentation);
MockHttpServletResponse response = dispatch(request);
return response.getContentAsString();
}
Expand Down Expand Up @@ -97,6 +100,7 @@ protected Mapml mapml(MockHttpServletResponse response)
* @param name the name of the layer
* @param kvp the key value pairs
* @param locale the locale
* @param bbox the bounding box
* @param srs the SRS
* @param styles the styles
* @return the request
Expand All @@ -106,6 +110,7 @@ protected MockHttpServletRequest getMapMLWMSRequest(
String name,
Map kvp,
Locale locale,
String bbox,
String srs,
String styles,
boolean isFeatureRepresentation)
Expand All @@ -131,7 +136,8 @@ protected MockHttpServletRequest getMapMLWMSRequest(
+ "&REQUEST=GetMap"
+ "&SRS="
+ srs
+ "&BBOX=0,0,1,1"
+ "&BBOX="
+ (bbox != null ? bbox : "0,0,1,1")
+ "&WIDTH=150"
+ "&HEIGHT=150"
+ "&format_options="
Expand Down
Loading

0 comments on commit 0f13cdf

Please sign in to comment.