[Webflysuesk-commits] r38 - in webflysuesk/branches/openlayers-integration: . webflys/src/main/java/de/intevation/webflys/servlets webflys/src/main/webapp/WEB-INF webflys/src/main/webapp/pages

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Mar 26 11:25:12 CET 2009


Author: iweinzierl
Date: 2009-03-26 11:25:12 +0100 (Thu, 26 Mar 2009)
New Revision: 38

Added:
   webflysuesk/branches/openlayers-integration/webflys/src/main/java/de/intevation/webflys/servlets/ServeWMC.java
   webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/karte.js
Modified:
   webflysuesk/branches/openlayers-integration/ChangeLog.txt
   webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/WEB-INF/web.xml
   webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/main.jsp
Log:
Integrated an OpenLayers map into the div container besides the parameters panel. The layers have to be configured in a WMC file.

Modified: webflysuesk/branches/openlayers-integration/ChangeLog.txt
===================================================================
--- webflysuesk/branches/openlayers-integration/ChangeLog.txt	2009-03-25 11:01:39 UTC (rev 37)
+++ webflysuesk/branches/openlayers-integration/ChangeLog.txt	2009-03-26 10:25:12 UTC (rev 38)
@@ -1,3 +1,17 @@
+2009-03-26  Ingo Weinzierl <ingo.weinzierl at intevation.de>
+
+	* webflys/src/main/webapp/pages/main.jsp,
+	  webflys/src/main/webapp/pages/karte.js: Integrated an OpenLayers map in
+	  the div container besides the parameter panel. A basic background layer
+	  'NASA Mosaic' is always shown in the map. Other layers can be configured
+	  in an WMC file by the user himself.
+	  TODO: Requesting the WMC file should be handled by the scheduler, not in
+	  the Servlet itself.
+
+	* webflys/src/main/java/de/intevation/webflys/servlets/ServeWMC.java,
+	  webflys/src/main/webapp/WEB-INF/web.xml: New Servlet to get the xml data
+	  of the WMC file to configure the OpenLayers map.
+
 2009-03-25  Ingo Weinzierl <ingo.weinzierl at intevation.de>
 
 	* webflys/src/main/webapp/pages/main.jsp,

Added: webflysuesk/branches/openlayers-integration/webflys/src/main/java/de/intevation/webflys/servlets/ServeWMC.java
===================================================================
--- webflysuesk/branches/openlayers-integration/webflys/src/main/java/de/intevation/webflys/servlets/ServeWMC.java	2009-03-25 11:01:39 UTC (rev 37)
+++ webflysuesk/branches/openlayers-integration/webflys/src/main/java/de/intevation/webflys/servlets/ServeWMC.java	2009-03-26 10:25:12 UTC (rev 38)
@@ -0,0 +1,108 @@
+/*
+ * ServeWMC.java
+ * -------------
+ * (c) 2009 by Intevation GmbH
+ *
+ * This file is part of WebFLYS/UeSK.
+ *
+ * WebFLYS is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * WebFLYS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with WebFLYS.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package de.intevation.webflys.servlets;
+
+/**
+ * @author Ingo Weinzierl (ingo.weinzierl at intevation.de)
+ */
+import java.io.File;
+import java.io.FileReader;
+import java.io.BufferedReader;
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServlet;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.ServletException;
+
+
+public class ServeWMC extends HttpServlet {
+
+    public static final String MIME_TYPE = "text/xml";
+
+    /**
+     * This method returns the wmc file containing the configuration of the
+     * OpenLayers map.
+     *
+     * @return File WMC config file
+     */
+    private File getWMCFile() {
+
+        // TODO The WMC file should be requested from the scheduler, so here is
+        // the wrong place for it.
+        return new File("/home/iweinzierl/wmc.xml");
+    }
+
+    /**
+     * This method reads a File and returns it's content as String.
+     *
+     * @param file The file to read.
+     * 
+     * @return Content of the file as String
+     */
+    private String readContentOfFile(File file) {
+        
+        StringBuilder  builder = new StringBuilder();
+        BufferedReader reader  = null;
+        String         line    = null;
+
+        try {
+            reader = new BufferedReader(new FileReader(file));
+            
+            while((line = reader.readLine()) != null) {
+                builder.append(line);
+            }
+        }
+        catch(IOException ioe) {
+            return null;
+        }
+        finally {
+            if(reader != null) {
+                try {
+                    reader.close();
+                }
+                catch(IOException ioe) {
+                    // Do nothing here
+                }
+            }
+        }
+
+        return builder != null ? builder.toString() : null;
+    }
+
+    public void doGet(HttpServletRequest request, HttpServletResponse response)
+    throws IOException, ServletException
+    {
+        response.setContentType(MIME_TYPE);
+
+        ServletOutputStream out = response.getOutputStream();
+
+        String wmc = readContentOfFile(getWMCFile());
+        if(wmc != null) {
+            out.println(wmc);
+        }
+        else
+            out.println(HttpServletResponse.SC_NO_CONTENT);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

Modified: webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/WEB-INF/web.xml
===================================================================
--- webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/WEB-INF/web.xml	2009-03-25 11:01:39 UTC (rev 37)
+++ webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/WEB-INF/web.xml	2009-03-26 10:25:12 UTC (rev 38)
@@ -17,6 +17,17 @@
         <url-pattern>/wst</url-pattern>
     </servlet-mapping>
 
+    <servlet>
+        <servlet-name>servewmc</servlet-name>
+        <servlet-class>de.intevation.webflys.servlets.ServeWMC</servlet-class>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>servewmc</servlet-name>
+        <url-pattern>/wmc</url-pattern>
+    </servlet-mapping>
+
+
     <filter>
         <filter-name>encoding-filter</filter-name>
         <filter-class>de.intevation.webflys.filters.EncodingFilter</filter-class>

Added: webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/karte.js
===================================================================
--- webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/karte.js	2009-03-25 11:01:39 UTC (rev 37)
+++ webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/karte.js	2009-03-26 10:25:12 UTC (rev 38)
@@ -0,0 +1,59 @@
+var map = null;
+var format = new OpenLayers.Format.WMC({'layerOptions': {buffer: 0}});
+
+/**
+ * Method: createMap
+ * Create a new map with a maxExtent. A basic background layer will be added
+ * always to the map. Other layers will be fetched from a WMC file, configurable
+ * by the user himself.
+ *
+ * Parameters:
+ * ext - {<OpenLayers.Bounds>} zoom to this extent.
+ */
+function createMap(ext) {
+
+    // add control elements
+    var control = [
+        new OpenLayers.Control.Navigation(),
+        new OpenLayers.Control.PanZoomBar(),
+        new OpenLayers.Control.LayerSwitcher(),
+        new OpenLayers.Control.MousePosition()
+    ];
+
+    // set map options
+    var options = {
+        controls: control,
+        maxExtent: ext,
+        maxResolution: 'auto',
+        numZoomLevels: 15,
+        projection: 'EPSG:4326',
+        units: 'm'
+    };
+    map = new OpenLayers.Map('map', options);
+
+    // create wms layer
+    var jpl_wms = new OpenLayers.Layer.WMS(
+        "NASA Global Mosaic",
+        "http://t1.hypercube.telascience.org/cgi-bin/landsat7", 
+        {
+            isBaseLayer: true,
+            layers: 'landsat7',
+        }
+    );
+
+    // add a basic background layer initial to the map
+    map.addLayers([jpl_wms]);
+
+    // fetch other layers from a WMC file to make the map configurable
+    $j.get(
+        'http://beige.rgb:8080/webflys/wmc',
+        function(xml) {
+            map = format.read(xml, {map: map});
+        },
+        'xml'
+    );
+
+    // zooming to the maximum extent
+    map.zoomToExtent(ext, 'true');
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

Modified: webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/main.jsp
===================================================================
--- webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/main.jsp	2009-03-25 11:01:39 UTC (rev 37)
+++ webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/main.jsp	2009-03-26 10:25:12 UTC (rev 38)
@@ -35,8 +35,21 @@
         <title><bean:message key="main.title"/></title> 
 		<link rel="stylesheet" type="text/css" href="pages/style.css" />
         <html:base/>
+
+        <%-- including needed js libs --%>
+        <script src="OpenLayers/OpenLayers.js"></script>
+        <script src="JQuery/jquery-1.3.2.js"></script>
+        <script src="karte.js"></script>
+
+        <%-- this snippet is needed to avoid conflicts between OpenLayers and jQuery --%>
+        <script type="text/javascript">
+            <!-- 
+            var $j = jQuery.noConflict();
+            -->
+        </script>
     </head>
-	<body>
+
+	<body onLoad="createMap(new OpenLayers.Bounds(-180,-90,180,90))">
         <div id="wrapper">
             <div id="wsplgen">
             <div id="errormessage">



More information about the Webflysuesk-commits mailing list