Skip to content

Commit

Permalink
Preserving MapML CRS in layer group links too
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Feb 5, 2024
1 parent ecb8314 commit c022e74
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* (c) 2024 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.web.demo;

import static org.junit.Assert.assertEquals;

import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.LayerGroupInfo;
import org.geoserver.data.test.MockData;
import org.geoserver.web.GeoServerWicketTestSupport;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.CRS;
import org.junit.Test;

public class PreviewLayerTest extends GeoServerWicketTestSupport {

/**
* Check MapML srs is preserved for layer groups
*
* @throws Exception
*/
@Test
public void testMapmlFormatLink() throws Exception {
Catalog cat = getCatalog();

LayerGroupInfo lg = cat.getFactory().createLayerGroup();
lg.setName("foo");
lg.setWorkspace(cat.getWorkspaceByName("sf"));
lg.getLayers().add(cat.getLayerByName(getLayerId(MockData.PRIMITIVEGEOFEATURE)));
lg.setBounds(new ReferencedEnvelope(0, 1, 0, 1, CRS.decode("MapML:OSMTILE")));
PreviewLayer layer = new PreviewLayer(lg);
layer.getWmsLink(
(r, p) -> {
assertEquals("MapML:OSMTILE", p.get("srs"));
assertEquals("0.0,0.0,1.0,1.0", p.get("bbox"));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.geoserver.catalog.LayerGroupInfo;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.PublishedType;
import org.geoserver.catalog.ResourcePool;
import org.geoserver.ows.URLMangler.URLType;
import org.geoserver.ows.util.ResponseUtils;
import org.geoserver.security.DisabledServiceResourceFilter;
Expand All @@ -34,6 +35,8 @@
import org.geotools.api.feature.type.AttributeType;
import org.geotools.api.feature.type.FeatureType;
import org.geotools.api.feature.type.Name;
import org.geotools.api.referencing.FactoryException;
import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
import org.geotools.api.util.ProgressListener;
import org.geotools.data.util.DefaultProgressListener;
import org.geotools.geometry.jts.ReferencedEnvelope;
Expand Down Expand Up @@ -149,10 +152,8 @@ public GetMapRequest getRequest() {
if (groupInfo != null) {
ReferencedEnvelope bounds = groupInfo.getBounds();
request.setBbox(bounds);
String srs =
GML2EncodingUtils.toURI(
bounds.getCoordinateReferenceSystem(), SrsSyntax.AUTH_CODE, false);
request.setSRS(srs);
request.setCrs(bounds.getCoordinateReferenceSystem());
request.setSRS(lookupSRSFromBounds(bounds));
}
try {
DefaultWebMapService.autoSetBoundsAndSize(request);
Expand All @@ -167,6 +168,18 @@ public GetMapRequest getRequest() {
return request;
}

private static String lookupSRSFromBounds(ReferencedEnvelope bounds) {
// try first a method that retains the native authority code, otherwise fall back on
// GML2EncodingUtils, which prefers the EPSG authority
CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem();
if (crs == null) return null;
try {
return ResourcePool.lookupIdentifier(crs, false);
} catch (FactoryException e) {
return GML2EncodingUtils.toURI(crs, SrsSyntax.AUTH_CODE, false);
}
}

/** Expands the specified name into a list of layer info names */
private List<MapLayerInfo> expandLayers(Catalog catalog) {
List<MapLayerInfo> layers = new ArrayList<>();
Expand Down Expand Up @@ -355,6 +368,7 @@ private String findFeatureTypeGmlVersion(AttributeType featureType) {
AttributeType parent = featureType.getSuper();
return findFeatureTypeGmlVersion(parent);
}

/**
* Returns true if serviceName is available for resource, otherwise false
*
Expand Down

0 comments on commit c022e74

Please sign in to comment.