Commit 3a9c21a0 authored by Andrea Aime's avatar Andrea Aime
Browse files

[GEOS-7010] GeoServer layer preview can be too large or too wide

parent 9c5c560f
......@@ -80,13 +80,28 @@ public class DefaultWebMapService implements WebMapService, ApplicationContextAw
/**
* longest side for the preview
*/
public static int MAX_SIDE = 512;
public static int MAX_SIDE = 768;
/**
* minimum height to have a decent looking OL preview
* minimum height to have a reasonable looking OL preview
*/
public static int MIN_OL_HEIGHT = 330;
/**
* minimum width to have a reasonable looking OL preview
*/
public static int MIN_OL_WIDTH = 330;
/**
* max height to have a reasonable looking OL preview
*/
public static int MAX_OL_HEIGHT = 768;
/**
* max width to have a reasonable looking OL preview
*/
public static int MAX_OL_WIDTH = 1024;
/**
* default for 'srs' parameter.
*/
......@@ -412,7 +427,7 @@ public class DefaultWebMapService implements WebMapService, ApplicationContextAw
* @see org.geoserver.wms.WebMapService#getStyles(org.geoserver.sld.GetStylesRequest)
*/
public StyledLayerDescriptor getStyles(GetStylesRequest request) {
return (StyledLayerDescriptor) getStyles.run(request);
return getStyles.run(request);
}
......@@ -623,14 +638,20 @@ public class DefaultWebMapService implements WebMapService, ApplicationContextAw
mwidth = (mheight * bbratio >= 1) ? mheight * bbratio : 1;
}
// make sure OL output height is sufficient to show the OL scale bar fully
if (mheight < MIN_OL_HEIGHT
&& ("application/openlayers".equalsIgnoreCase(getMap.getFormat()) || "openlayers"
.equalsIgnoreCase(getMap.getFormat()))) {
mheight = MIN_OL_HEIGHT;
mwidth = (mheight * bbratio >= 1) ? mheight * bbratio : 1;
// OL specific adjustments
if ("application/openlayers".equalsIgnoreCase(getMap.getFormat())
|| "openlayers".equalsIgnoreCase(getMap.getFormat())) {
if (mheight < MIN_OL_HEIGHT) {
mheight = MIN_OL_HEIGHT;
} else if (mheight > MAX_OL_HEIGHT) {
mheight = MAX_OL_HEIGHT;
}
if (mwidth < MIN_OL_WIDTH) {
mwidth = MIN_OL_WIDTH;
} else if (mwidth > MAX_OL_WIDTH) {
mwidth = MAX_OL_WIDTH;
}
}
}
}
......
......@@ -28,7 +28,7 @@ public class DefaultWebMapServiceTest extends WMSTestSupport {
* @throws Exception
*/
@Test
public void test1() throws Exception {
public void testBasic() throws Exception {
GetMapRequest mockGMR = createGetMapRequest(MockData.BASIC_POLYGONS);
/* Create a request */
......@@ -56,8 +56,8 @@ public class DefaultWebMapServiceTest extends WMSTestSupport {
assertTrue(bbox.getMinX() == -180.0 && bbox.getMaxX() == 180.0 && bbox.getMinY() == -90.0
&& bbox.getMaxY() == 90.0);
assertEquals("image/png", format);
assertEquals(width, 512);
assertEquals(height, 256);
assertEquals(width, 768);
assertEquals(height, 384);
}
/**
......@@ -66,7 +66,7 @@ public class DefaultWebMapServiceTest extends WMSTestSupport {
* @throws Exception
*/
@Test
public void test2() throws Exception {
public void testReprojection() throws Exception {
GetMapRequest mockGMR = createGetMapRequest(MockData.BASIC_POLYGONS);
/* Create a request */
......@@ -98,8 +98,8 @@ public class DefaultWebMapServiceTest extends WMSTestSupport {
&& Math.abs(bbox.getMaxX() - 1.9236008009077676E7) < 1E-4
&& Math.abs(bbox.getMaxY() - 2.2026354993694823E7) < 1E-4);
assertEquals("image/gif", format);
assertEquals(447, width);
assertEquals(512, height);
assertEquals(670, width);
assertEquals(768, height);
}
/**
......@@ -109,7 +109,7 @@ public class DefaultWebMapServiceTest extends WMSTestSupport {
* @throws Exception
*/
@Test
public void test3() throws Exception {
public void testAutoSetWidthHeight() throws Exception {
GetMapRequest mockStreams = createGetMapRequest(MockData.BRIDGES);
GetMapRequest mockBridges = createGetMapRequest(MockData.STREAMS);
......@@ -145,12 +145,39 @@ public class DefaultWebMapServiceTest extends WMSTestSupport {
&& Math.abs(bbox.getMaxX() - 1.9236008009077676E7) < 1E-4
&& Math.abs(bbox.getMaxY() - 2.2026354993694823E7) < 1E-4);
assertEquals("image/gif", format);
assertEquals(447, width);
assertEquals(512, height);
assertEquals(670, width);
assertEquals(768, height);
}
/**
* This test is incomplete because I (arneke) had trouble finding mock data with proper bounding
* boxes
*
* @throws Exception
*/
@Test
public void testAutoSetWidthHeightOL() throws Exception {
DefaultWebMapService reflector = new DefaultWebMapService(getWMS());
// request too stretched east/west
GetMapRequest request = createGetMapRequest(MockData.BRIDGES);
request.setBbox(new Envelope(-180, 180, 0, 10));
request.setFormat("application/openlayers");
reflector.autoSetBoundsAndSize(request);
assertEquals(768, request.getWidth());
assertEquals(330, request.getHeight());
// request too stretched south/north
request = createGetMapRequest(MockData.BRIDGES);
request.setBbox(new Envelope(-0, 10, -90, 90));
request.setFormat("application/openlayers");
reflector.autoSetBoundsAndSize(request);
assertEquals(330, request.getWidth());
assertEquals(768, request.getHeight());
}
@Test
public void testAdvancedProjectionEnabled(){
public void testAdvancedProjectionEnabled() {
// Ensure that by default advanced projection handling is enabled
assertTrue(DefaultWebMapService.isAdvancedProjectionHandlingEnabled());
}
......
......@@ -230,7 +230,8 @@ public class AnimatorTest extends WMSTestSupport {
LayerGroupInfo eoGroup = createLakesPlacesLayerGroup(catalog, "eoGroup", LayerGroupInfo.Mode.EO, catalog.getLayerByName(getLayerId(MockData.LAKES)));
try {
String requestURL = "wms/animate?BBOX=0.0000,-0.0020,0.0035,0.0010&aparam=layers&avalues=" +
String requestURL = "wms/animate?BBOX=0.0000,-0.0020,0.0035,0.0010&width=512&aparam=layers&avalues="
+
singleGroup.getName() + "," +
namedGroup.getName() + "," +
eoGroup.getName();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment