changeset 2508:4aa70825bde1

map print: generate valid url to access service. flys-client/trunk@4363 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 09 May 2012 11:18:24 +0000
parents 7ef59d7e113d
children 3952429cc41b
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java flys-client/src/main/webapp/WEB-INF/config.yaml
diffstat 4 files changed, 97 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue May 08 15:37:21 2012 +0000
+++ b/flys-client/ChangeLog	Wed May 09 11:18:24 2012 +0000
@@ -1,3 +1,17 @@
+2012-05-09	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java:
+	  Accept the case that no bbox is given. Fall back to max extent in this case.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java:
+	  Generate a valid URL for the print service.
+	  A nasty internal bug in gwtopenmaps bounds (type cast problem) prevents
+	  fetching bbox when map in new. Cope with this case.
+	  TODO: Add listeners to follow the current extent.
+
+	* src/main/webapp/WEB-INF/config.yaml: Allowed another host to fetch
+	  remote images from.
+
 2012-05-07	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Tue May 08 15:37:21 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Wed May 09 11:18:24 2012 +0000
@@ -15,6 +15,7 @@
 import com.smartgwt.client.widgets.events.ResizedEvent;
 import com.smartgwt.client.widgets.events.ResizedHandler;
 
+import org.gwtopenmaps.openlayers.client.Bounds;
 import org.gwtopenmaps.openlayers.client.Map;
 import org.gwtopenmaps.openlayers.client.control.DragPan;
 import org.gwtopenmaps.openlayers.client.control.SelectFeature;
@@ -29,6 +30,7 @@
 import de.intevation.flys.client.client.ui.ImgLink;
 import de.intevation.flys.client.client.utils.EnableDisableCmd;
 import de.intevation.flys.client.shared.model.ThemeList;
+import de.intevation.flys.client.shared.model.Collection;
 
 
 /**
@@ -280,8 +282,8 @@
         return new ImgLink(
             baseUrl + MSG.downloadPDF(),
             getPrintUrl(),
-            20,
-            20);
+            20, 20,
+            true);
     }
 
 
@@ -609,8 +611,38 @@
     }
 
     public String getPrintUrl() {
-        String url = GWT.getModuleBaseURL();
-        GWT.log("TODO: Generate real print link.");
+        MapOutputTab ot = (MapOutputTab)getOutputTab();
+        Collection collection = ot.getCollection();
+        String uuid = collection.identifier();
+
+        String mapType = collection.getOutputModes().containsKey("floodmap")
+            ? "floodmap"
+            : "map";
+
+        String url = GWT.getModuleBaseURL() + "map-print?";
+
+        Map map = getMap();
+        Bounds bounds = map.getExtent();
+
+        if (bounds != null) {
+            try {
+                double minX = bounds.getLowerLeftX();
+                double maxX = bounds.getUpperRightX();
+                double minY = bounds.getLowerLeftY();
+                double maxY = bounds.getUpperRightY();
+                url += "minx=" + minX + "&";
+                url += "maxx=" + maxX + "&";
+                url += "miny=" + minY + "&";
+                url += "maxy=" + maxY + "&";
+            }
+            catch (Exception e) {
+                // XXX: Ignore it. bounds.getXXX() throw 
+                // exceptions when bound is invalid. :-/
+            }
+        }
+
+        url += "uuid=" + uuid + "&maptype=" + mapType;
+
         return url;
     }
 }
--- a/flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java	Tue May 08 15:37:21 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java	Wed May 09 11:18:24 2012 +0000
@@ -121,18 +121,16 @@
 
     protected static String generateSpec(
         Document descDocument,
-        Document outDocument,
-        double minX, double minY,
-        double maxX, double maxY
+        MapConfig mapConfig,
+        Double minX, Double minY,
+        Double maxX, Double maxY
     ) {
-        MapConfig mapConfig = MapHelper.parseConfig(outDocument);
-
         Map<String, Object> spec = new LinkedHashMap<String, Object>();
         spec.put("layout",       "A4 portrait");
         spec.put("title",        "FLYS Druck");
         spec.put("srs",          "EPSG:" + mapConfig.getSrid());
         spec.put("dpi",          Integer.valueOf(254));
-        spec.put("units",        "degrees");
+        spec.put("units",        "m");
         spec.put("outputFormat", "pdf");
 
 
@@ -203,27 +201,28 @@
         String minYS = req.getParameter("miny");
         String maxYS = req.getParameter("maxy");
 
-        if (minXS == null || maxXS == null
-        ||  minYS == null || maxYS == null) {
-            throw new ServletException("Missing minX, minY, maxX or maxY");
-        }
-
-        double minX, maxX, minY, maxY;
+        Double minX = null;
+        Double maxX = null;
+        Double minY = null;
+        Double maxY = null;
 
-        try {
-            minX = Double.parseDouble(minXS);
-            minY = Double.parseDouble(minYS);
-            maxX = Double.parseDouble(maxXS);
-            maxY = Double.parseDouble(maxYS);
-        }
-        catch (NumberFormatException nfe) {
-            throw new ServletException("Misspelled minX, minY, maxX or maxY");
+        if (minXS != null && maxXS != null
+        &&  minYS != null && maxYS == null) {
+            try {
+                minX = Double.parseDouble(minXS);
+                minY = Double.parseDouble(minYS);
+                maxX = Double.parseDouble(maxXS);
+                maxY = Double.parseDouble(maxYS);
+            }
+            catch (NumberFormatException nfe) {
+                throw new ServletException("Misspelled minX, minY, maxX or maxY");
+            }
         }
 
         String mapType = req.getParameter("maptype");
 
-        if (mapType == null || !mapType.equals("map")) {
-            mapType = "floodmap";
+        if (mapType == null || !mapType.equals("floodmap")) {
+            mapType = "map";
         }
 
         String url = getURL();
@@ -240,6 +239,9 @@
         try {
             HttpClient client = new HttpClientImpl(url);
 
+            descDocument = (Document)client.doCollectionAction(
+                requestDesc, uuid, new DocumentResponseHandler());
+
             InputStream is = client.collectionOut(
                 requestOut, uuid, mapType);
 
@@ -251,17 +253,34 @@
                 is = null;
             }
 
-            descDocument = (Document)client.doCollectionAction(
-                requestDesc, uuid, new DocumentResponseHandler());
         }
         catch (ConnectionException ce) {
             log.error(ce);
             throw new ServletException(ce);
         }
 
+        MapConfig mapConfig = MapHelper.parseConfig(outDocument);
+
+        if (minX == null) {
+            String [] parts = mapConfig.getMaxExtent().split("\\s+");
+            if (parts.length < 4) {
+                throw new ServletException(
+                    "Max extent has less than 4 values");
+            }
+            try {
+                minX = Double.valueOf(parts[0]);
+                minY = Double.valueOf(parts[1]);
+                maxX = Double.valueOf(parts[2]);
+                maxY = Double.valueOf(parts[3]);
+            }
+            catch (NumberFormatException nfe) {
+                throw new ServletException(nfe);
+            }
+        }
+
         String spec = generateSpec(
             descDocument,
-            outDocument,
+            mapConfig,
             minX, minY,
             maxX, maxY);
 
--- a/flys-client/src/main/webapp/WEB-INF/config.yaml	Tue May 08 15:37:21 2012 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/config.yaml	Wed May 09 11:18:24 2012 +0000
@@ -35,6 +35,9 @@
   - !dnsMatch
     host: tile.openstreetmap.org
     port: 80
+  - !dnsMatch
+    host: www.pegelonline.wsv.de
+    port: 80
 
 layouts:
   #===========================================================================

http://dive4elements.wald.intevation.org