Skip to content

Commit

Permalink
switched to allowing mixed raster and vector based on layer settings
Browse files Browse the repository at this point in the history
  • Loading branch information
turingtestfail committed Mar 7, 2024
1 parent 0f13cdf commit bbb2803
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public class MapMLDocumentBuilder {

private Input zoomInput;

private boolean useFeaturesAllLayers = true;
private List<MapMLLayerMetadata> mapMLLayerMetadataList = new ArrayList<>();

private Mapml mapml;
Expand Down Expand Up @@ -285,7 +284,6 @@ public void initialize() throws ServiceException {
MapMLLayerMetadata mapMLLayerMetadata = layersToOneMapMLLayerMetadata(layers);
mapMLLayerMetadataList.add(mapMLLayerMetadata);
}
useFeaturesAllLayers = allLayersUsingFeatures(layers);
// populate Map-wide variables using the first layer
if (!mapMLLayerMetadataList.isEmpty()) {
defaultStyle =
Expand Down Expand Up @@ -355,6 +353,12 @@ private MapMLLayerMetadata layersToOneMapMLLayerMetadata(List<RawLayer> layers)
MapMLLayerMetadata mapMLLayerMetadata = new MapMLLayerMetadata();
mapMLLayerMetadata.setLayerMeta(new MetadataMap());
mapMLLayerMetadata.setUseTiles(false);
boolean useFeatures = false;
if (layers.size() == 1) {
useFeatures =
useFeatures(layers.get(0), layers.get(0).getPublishedInfo().getMetadata());
}
mapMLLayerMetadata.setUseFeatures(useFeatures);
mapMLLayerMetadata.setLayerName(layersCommaDelimited);
mapMLLayerMetadata.setStyleName(stylesCommaDelimited);
mapMLLayerMetadata.setTimeEnabled(false);
Expand All @@ -369,28 +373,6 @@ private MapMLLayerMetadata layersToOneMapMLLayerMetadata(List<RawLayer> layers)
return mapMLLayerMetadata;
}

/**
* Check if all layers in the request use features
*
* @param layers List of RawLayer objects
* @return boolean
*/
private boolean allLayersUsingFeatures(List<RawLayer> layers) {
for (RawLayer layer : layers) {
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;
}
}
return true;
}

/**
* Parses the projection into a ProjType, or throws a proper service exception indicating the
* unsupported CRS
Expand Down Expand Up @@ -565,7 +547,7 @@ private MapMLLayerMetadata layerToMapMLLayerMetadata(RawLayer layer, String styl
.getGridSubset(projType.value())
!= null;
boolean useTiles = Boolean.TRUE.equals(layerMeta.get(MAPML_USE_TILES, Boolean.class));
boolean useFeatures = Boolean.TRUE.equals(layerMeta.get(MAPML_USE_FEATURES, Boolean.class));
boolean useFeatures = useFeatures(layer, layerMeta);

return new MapMLLayerMetadata(
layerInfo,
Expand All @@ -585,6 +567,11 @@ private MapMLLayerMetadata layerToMapMLLayerMetadata(RawLayer layer, String styl
useFeatures);
}

private static boolean useFeatures(RawLayer layer, MetadataMap layerMeta) {
return (Boolean.TRUE.equals(layerMeta.get(MAPML_USE_FEATURES, Boolean.class)))
&& (PublishedType.VECTOR == layer.getPublishedInfo().getType());
}

/**
* Match the CRS of the layer to the CRS of the bbox
*
Expand Down Expand Up @@ -1030,7 +1017,8 @@ private void generateTemplatedLinks(MapMLLayerMetadata mapMLLayerMetadata) {

// query inputs
if (mapMLLayerMetadata.isQueryable()
&& !useFeaturesAllLayers) { // No query links for feature representations
&& !mapMLLayerMetadata
.isUseFeatures()) { // No query links for feature representations
if (mapMLLayerMetadata.isUseTiles() && mapMLLayerMetadata.isTileLayerExists()) {
generateWMTSQueryClientLinks(mapMLLayerMetadata);
} else {
Expand Down Expand Up @@ -1353,7 +1341,7 @@ public void generateWMSClientLinks(MapMLLayerMetadata mapMLLayerMetadata) {

// image link
Link imageLink = new Link();
if (useFeaturesAllLayers) {
if (mapMLLayerMetadata.isUseFeatures()) {
imageLink.setRel(RelType.FEATURES);
} else {
imageLink.setRel(RelType.IMAGE);
Expand All @@ -1373,7 +1361,7 @@ public void generateWMSClientLinks(MapMLLayerMetadata mapMLLayerMetadata) {
params.put("elevation", "{elevation}");
}
params.put("bbox", "{xmin},{ymin},{xmax},{ymax}");
if (useFeaturesAllLayers) {
if (mapMLLayerMetadata.isUseFeatures()) {
params.put("format", MAPML_MIME_TYPE);
params.put("format_options", MAPML_FEATURE_FORMAT_OPTIONS);
} else {
Expand Down Expand Up @@ -1636,8 +1624,7 @@ public String getMapMLHTMLDocument() {
height,
escapeHtml4(proj),
styleName,
format,
useFeaturesAllLayers))
format))
.append("\" checked></layer->\n")
.append("</mapml-viewer>\n")
.append("</body>\n")
Expand All @@ -1653,8 +1640,7 @@ private String buildGetMap(
int width,
String proj,
String styleName,
Optional<Object> format,
Boolean useFeaturesAllLayers) {
Optional<Object> format) {
Map<String, String> kvp = new LinkedHashMap<>();
kvp.put("LAYERS", escapeHtml4(layer));
kvp.put("BBOX", toCommaDelimitedBbox(projectedBbox));
Expand All @@ -1667,9 +1653,7 @@ private String buildGetMap(
MapMLConstants.MAPML_WMS_MIME_TYPE_OPTION
+ ":"
+ escapeHtml4((String) format.orElse("image/png"));
if (!useFeaturesAllLayers) {
kvp.put("format_options", formatOptions);
}
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 @@ -271,6 +271,10 @@ public void testMapMLSingleLayer() throws Exception {

@Test
public void testMapMLUseFeaturesLinks() throws Exception {
GeoServer geoServer = getGeoServer();
WMSInfo wms = geoServer.getService(WMSInfo.class);
wms.getMetadata().put(MapMLDocumentBuilder.MAPML_MULTILAYER_AS_MULTIEXTENT, Boolean.TRUE);
geoServer.save(wms);

Catalog cat = getCatalog();
LayerInfo li = cat.getLayerByName(MockData.POLYGONS.getLocalPart());
Expand Down

0 comments on commit bbb2803

Please sign in to comment.