changeset 2510:4861ab2c28d2

map print: add legend flys-client/trunk@4365 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 09 May 2012 16:13:45 +0000 (2012-05-09)
parents 3952429cc41b
children 1aa6aec70b97
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java flys-client/src/main/webapp/WEB-INF/config.yaml
diffstat 3 files changed, 65 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed May 09 13:15:26 2012 +0000
+++ b/flys-client/ChangeLog	Wed May 09 16:13:45 2012 +0000
@@ -1,3 +1,12 @@
+2012-05-09	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java:
+	  Generate legen via getlegendgraphic of the layers. Does not
+	  look too pretty right now.
+
+	* src/main/webapp/WEB-INF/config.yaml: Added legend block. We need
+	  to learn how the layout really work to make it look pretty.
+
 2012-05-09	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/server/MapPrintServiceImpl.java	Wed May 09 13:15:26 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java	Wed May 09 16:13:45 2012 +0000
@@ -15,6 +15,7 @@
 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
 
 import de.intevation.flys.client.shared.model.MapConfig;
+import de.intevation.flys.client.shared.MapUtils;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
@@ -131,20 +132,22 @@
         spec.put("srs",          "EPSG:" + mapConfig.getSrid());
         spec.put("dpi",          Integer.valueOf(254));
         spec.put("units",        "m");
+        spec.put("geodaetic",    "true");
         spec.put("outputFormat", "pdf");
 
-
-        List<Layer> ls = new ArrayList<Layer>();
-        Layer l = new Layer();
-
         String ns = ArtifactNamespaceContext.NAMESPACE_URI;
-        NodeList facets = descDocument.getElementsByTagNameNS(ns, "facet");
 
-        for (int i = 0, N = facets.getLength(); i < N; ++i) {
-            Element element = (Element)facets.item(i);
-            if (l.setup(element)) {
-                ls.add(l);
-                l = new Layer();
+        List<Layer> ls = new ArrayList<Layer>();
+        {   Layer l = new Layer();
+
+            NodeList facets = descDocument.getElementsByTagNameNS(ns, "facet");
+
+            for (int i = 0, N = facets.getLength(); i < N; ++i) {
+                Element element = (Element)facets.item(i);
+                if (l.setup(element)) {
+                    ls.add(l);
+                    l = new Layer();
+                }
             }
         }
 
@@ -153,8 +156,8 @@
 
         List<Object> layers = new ArrayList<Object>(ls.size());
 
-        for (Layer layer: ls) {
-            layers.add(layer.toMap());
+        for (int i = ls.size()-1; i >= 0; --i) {
+            layers.add(ls.get(i).toMap());
         }
 
         spec.put("layers", layers);
@@ -162,23 +165,47 @@
 
         List<Object> pages = new ArrayList<Object>(1);
 
-        spec.put("pages", pages);
 
         Map<String, Object> page = new LinkedHashMap<String, Object>();
 
         List<Object> bounds = new ArrayList<Object>(4);
-        bounds.add(Double.valueOf(minX));
-        bounds.add(Double.valueOf(minY));
-        bounds.add(Double.valueOf(maxX));
-        bounds.add(Double.valueOf(maxY));
+        bounds.add(minX);
+        bounds.add(minY);
+        bounds.add(maxX);
+        bounds.add(maxY);
+        page.put("bbox", bounds);
 
-        page.put("bbox", bounds);
+        /*
+        bounds.add(Double.valueOf((minX+maxX)*0.5));
+        bounds.add(Double.valueOf((minY+maxY)*0.5));
+
+        page.put("center", bounds);
+        page.put("scale", Integer.valueOf(50000));
+        */
 
         page.put("mapTitle", "FLYS Karte");
         page.put("comment", "Eine mit FLYS gedruckte Karte.");
         page.put("rotation", Integer.valueOf(0));
 
         pages.add(page);
+        spec.put("pages", pages);
+
+        List<Object> legends = new ArrayList<Object>(layers.size());
+
+        for (Layer layer: ls) {
+            Map<String, Object> legend = new LinkedHashMap<String, Object>();
+            List<Object> classes = new ArrayList<Object>(1);
+            Map<String, Object> clazz = new LinkedHashMap<String, Object>();
+            String lgu = MapUtils.getLegendGraphicUrl(layer.url, layer.layers);
+            clazz.put("icon", lgu);
+            clazz.put("name", layer.description);
+            classes.add(clazz);
+            legend.put("classes", classes);
+            legend.put("name", layer.description);
+            legends.add(legend);
+        }
+
+        spec.put("legends", legends);
 
         return JSON.toJSONString(spec);
     }
@@ -277,6 +304,12 @@
                 throw new ServletException(nfe);
             }
         }
+        if (log.isDebugEnabled()) {
+            log.debug("minX: " + minX);
+            log.debug("maxX: " + maxX);
+            log.debug("minY: " + minY);
+            log.debug("maxY: " + maxY);
+        }
 
         String spec = generateSpec(
             descDocument,
@@ -285,6 +318,7 @@
             maxX, maxY);
 
         if (log.isDebugEnabled()) {
+            log.debug("Generated spec:");
             log.debug(spec);
             //System.err.println(spec);
         }
--- a/flys-client/src/main/webapp/WEB-INF/config.yaml	Wed May 09 13:15:26 2012 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/config.yaml	Wed May 09 16:13:45 2012 +0000
@@ -175,4 +175,8 @@
           fontSize: 9
           align: right
           text: '1:${scale} ${now MM.dd.yyyy}'
+        - !legends
+          align: left
+          maxIconWidth: 32
+          maxIconHeight: 32
       footer: *commonFooter

http://dive4elements.wald.intevation.org