[Webflysuesk-commits] r48 - in webflysuesk/branches/openlayers-integration: . webflys/src/main/resources webflys/src/main/webapp/pages

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Apr 6 14:36:43 CEST 2009


Author: iweinzierl
Date: 2009-04-06 14:36:19 +0200 (Mon, 06 Apr 2009)
New Revision: 48

Modified:
   webflysuesk/branches/openlayers-integration/ChangeLog.txt
   webflysuesk/branches/openlayers-integration/webflys/src/main/resources/MessageResources.properties
   webflysuesk/branches/openlayers-integration/webflys/src/main/resources/MessageResources_de.properties
   webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/karte.js
   webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/main.jsp
   webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/style.css
Log:
New feature: the user is able to fetch old calculation results from the server and put them into the map.

Modified: webflysuesk/branches/openlayers-integration/ChangeLog.txt
===================================================================
--- webflysuesk/branches/openlayers-integration/ChangeLog.txt	2009-03-31 15:37:36 UTC (rev 47)
+++ webflysuesk/branches/openlayers-integration/ChangeLog.txt	2009-04-06 12:36:19 UTC (rev 48)
@@ -1,3 +1,15 @@
+2009-04-06  Ingo Weinzierl <ingo.weinzierl at intevation.de>
+
+	* src/main/webapp/pages/main.jsp,
+	  src/main/webapp/pages/karte.js: New panel to show old calculation results
+	  of the current user. To avoid performance problems, the user is able to
+	  load only one result to the map.
+
+	* src/main/webapp/pages/style.css: new design for the new panel.
+
+	* src/main/resources/MessageResources_de.properties,
+	  src/main/resources/MessageResources.properties: Text for new panel.
+
 2009-03-31  Ingo Weinzierl <ingo.weinzierl at intevation.de>
 
 	* webflys/src/main/java/de/intevation/webflys/model/River.java,

Modified: webflysuesk/branches/openlayers-integration/webflys/src/main/resources/MessageResources.properties
===================================================================
--- webflysuesk/branches/openlayers-integration/webflys/src/main/resources/MessageResources.properties	2009-03-31 15:37:36 UTC (rev 47)
+++ webflysuesk/branches/openlayers-integration/webflys/src/main/resources/MessageResources.properties	2009-04-06 12:36:19 UTC (rev 48)
@@ -123,3 +123,8 @@
 main.calculation.success=Calculation successfully started
 main.calculation.failure=Calculation not started
 
+
+# --- wsplgen results
+
+wsplgen.result.title=Old jobs
+wsplgen.refresh.button=Refresh job list

Modified: webflysuesk/branches/openlayers-integration/webflys/src/main/resources/MessageResources_de.properties
===================================================================
--- webflysuesk/branches/openlayers-integration/webflys/src/main/resources/MessageResources_de.properties	2009-03-31 15:37:36 UTC (rev 47)
+++ webflysuesk/branches/openlayers-integration/webflys/src/main/resources/MessageResources_de.properties	2009-04-06 12:36:19 UTC (rev 48)
@@ -129,3 +129,9 @@
 main.calculation.submit=Berechnung starten
 main.calculation.success=Berechnung erfolgreich gestartet
 main.calculation.failure=Berechnung konnte nicht gestartet werden
+
+
+# --- wsplgen results ---
+
+wsplgen.result.title=Alte Berechnungen
+wsplgen.refresh.button=Hole alte Berechnungen

Modified: webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/karte.js
===================================================================
--- webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/karte.js	2009-03-31 15:37:36 UTC (rev 47)
+++ webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/karte.js	2009-04-06 12:36:19 UTC (rev 48)
@@ -1,7 +1,15 @@
+/** the map */
 var map = null;
+
+/** OpenLayers.Format.WMC to read a wmc configuration file for the map */
 var format = new OpenLayers.Format.WMC({'layerOptions': {buffer: 0}});
+
+/** OpenLayers.Layer.WMS layer to store the different barriers in */
 var wfs = null;
 
+/** assoziative array for result layer */
+var usk_layer = null;
+
 /**
  * Method: createMapForRiver
  * Fetch the BoundingBox of a river in the ServletContext from Servlet and
@@ -21,7 +29,7 @@
             $j(xml).find('boundingbox').each(function() {
                 var boundingXML = $j(this).text();
                 var bounds = new OpenLayers.Bounds.fromString( boundingXML );
-                
+
                 // create the map
                 createMap(bounds);
 
@@ -62,6 +70,7 @@
     };
     map = new OpenLayers.Map('map', options);
 
+/*
     // create wms layer
     var jpl_wms = new OpenLayers.Layer.WMS(
         "NASA Global Mosaic",
@@ -71,7 +80,17 @@
             layers: 'landsat7',
         }
     );
+*/
 
+    var jpl_wms = new OpenLayers.Layer.WMS(
+        "Saar",
+        "http://beige.rgb:8080/geoserver/wms", 
+        {
+            isBaseLayer: true,
+            layers: 'sf:achse'
+        }
+    );
+
     // add a basic background layer initial to the map
     map.addLayers([jpl_wms]);
 
@@ -131,8 +150,8 @@
     );
     pipes.featureAdded =
         function(feature) { addAttributesToFeature(feature, 'ROHR', 1); };
-    
 
+
     // defining a button to create rills
     var rills= new OpenLayers.Control.DrawFeature(
         wfs, OpenLayers.Handler.Path,
@@ -159,13 +178,11 @@
         function(feature) { addAttributesToFeature(feature, 'DAMM', 3); };
 
 
-        
-
     // defining a button to store the changes in the wfs layer into the PostGIS
     var save = new OpenLayers.Control.Button({
         title: "in PostGIS speichern",
         trigger: function() {
-            saveStrategy.save();   
+            saveStrategy.save();
         },
     });
 
@@ -196,55 +213,57 @@
     feature.attributes.objektart  = 'M29 RohrGrabenDamm';
     feature.attributes.typ        = typeNr;
     feature.attributes.typ_text   = typeText;
-
-    // add user_id and gewaesser in an own function because the information is
-    // fetched via Ajax request
-    addUserIdToFeature(feature);
-    addGewaesserToFeature(feature);
+    feature.attributes.level      = 1;
+    feature.attributes.gewaesser  = getGewaesser();
+    feature.attributes.user_id    = getUserId();
 }
 
+
 /**
- * Method:getGewaesser
- * Fetch the name of the river from the session via AJAX request.
+ * Method: getGewaesser
+ * Fetch the current gewaesser from the session via Ajax request.
  *
- * Parameters:
- * feature - {OpenLayers.Feature} Last feature which was added.
+ * Returns:
+ * {String} Gewaesser name
  */
-function addGewaesserToFeature(feature) {
-    var gewaesser = null;
+function getGewaesser() {
 
+    var gew = null;
+
     $j.ajax({
         type    :'GET',
         url     :'http://beige.rgb:8080/webflys/getGewaesser',
-        async   : true,
+        async   : false,
         dataType: 'xml',
         error   : function(error) {
                       alert('Error loading gewaesser: ' + error);
         },
         success : function(xml) {
             $j(xml).find('gewaesser').each(function() {
-                gewaesser = $j(this).text();
-                feature.attributes.gewaesser = gewaesser;
+                gew = $j(this).text();
             });
         }
     });
+
+    return gew;
 }
 
 
 /**
- * Method:getUserId
- * Fetch the username from the session via AJAX request.
+ * Method: getUserId
+ * Fetch the user_id from the session via Ajax request.
  *
  * Returns:
- * {String} UserId as String.
+ * {String} user id
  */
-function addUserIdToFeature(feature) {
+function getUserId() {
+
     var uid = null;
 
     $j.ajax({
         type    : 'GET',
         url     : 'http://beige.rgb:8080/webflys/userId',
-        async   : true,
+        async   : false,
         dataType: 'xml',
         error   : function(error) {
             alert('Error loading UserId: ' + error);
@@ -252,9 +271,222 @@
         success: function(xml) {
             $j(xml).find('user-name').each(function() {
                 uid = $j(this).text();
-                feature.attributes.user_id = uid;
             });
         }
     });
+
+    return uid;
 }
+
+
+/**
+ * Method: fetchUserResults
+ * This method reads the results of old calculations from a user and gewaesser
+ * via WFS and adds these results as layer to the map.
+ *
+ * Parameters:
+ * method - {String} Callback method which shall be called after the wfs request
+ * has finished.
+ * jobId  - {Number} Extends the filter for a job_id.
+ * userId - {String} The name of the user
+ * river  - {String} The name of the river
+ */
+function fetchUserResults(method, jobId, userId, river) {
+
+    var filterHead = 
+        '<?xml version="1.0" encoding="ISO-8859-1"?>' +
+        '<wfs:GetFeature xmlns:ogc="http://www.opengis.net/ogc" ' +
+        'xmlns:gml="http://www.opengis.net/gml" ' +
+        'xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0"'+ 
+        ' maxFeatures="100" outputFormat="GML2"><wfs:Query ' +
+        'typeName="usk_gf_ergebnis">';
+    var filterFoot = '</wfs:Query></wfs:GetFeature>';
+    var filterBody;
+
+    var filter_1_0 = new OpenLayers.Format.Filter({ version: "1.0.0" });
+    var xmlFormat  = new OpenLayers.Format.XML();
+    var filters    = new Array();
+
+    // fetch only features which belong to this user
+    var filter_userId = new OpenLayers.Filter.Comparison({
+        type    : OpenLayers.Filter.Comparison.EQUAL_TO,
+        property: 'user_id',
+        value   : userId
+    });
+    filters.push(filter_userId);
+
+    // fetch only features which belong to the current river
+    var filter_river = new OpenLayers.Filter.Comparison({
+        type    : OpenLayers.Filter.Comparison.EQUAL_TO,
+        property: 'gewaesser',
+        value   : river
+    });
+    filters.push(filter_river);
+
+    if( jobId != null) {
+        var filter_job = new OpenLayers.Filter.Comparison({
+            type    : OpenLayers.Filter.Comparison.EQUAL_TO,
+            property: 'job_id',
+            value   : jobId
+        });
+        filters.push(filter_job);
+    }
+
+    var filter = new OpenLayers.Filter.Logical({
+        type    : OpenLayers.Filter.Logical.AND,
+        filters : filters
+    });
+
+    filterBody = xmlFormat.write(filter_1_0.write(filter));
+
+    var final_filter = filterHead+filterBody+filterFoot;
+    var req = new OpenLayers.Request.POST({
+        method  : 'POST',
+        url     : 'http://beige.rgb:8080/geoserver/wfs',
+        data    : final_filter,
+        callback: method
+    });
+}
+
+
+/**
+ * Method: addResults
+ * This method uses the response of a wfs GetFeatureRequest with a filter on 
+ * user_id, gewaesser and job_id.
+ *
+ * Parameters:
+ * response - {XMLHttpResponse} Response of a wfs GetFeatureRequest
+ */
+function addResults(response) {
+
+    // read all features of the response
+    var features = new OpenLayers.Format.GML().read(response.responseText);
+
+    // destroy all features in the existing usk_layer and remove it from map
+    if(usk_layer != null) {
+        usk_layer.destroyFeatures(usk_layer.features);
+        map.removeLayer(usk_layer);
+    }
+
+    // create new name for usk_layer
+    usk_layer = new OpenLayers.Layer.Vector(createLayerName(features[0]));
+
+    // add new usk_layer to the map
+    map.addLayer(usk_layer);
+
+    // add all features to usk_layer
+    for(var i = 0; i < features.length; ++i) {
+        usk_layer.addFeatures([features[i]]);
+    }
+}
+
+
+/**
+ * Method: createLayerName
+ * This method creates a name for a layer from attributes of a feature.
+ *
+ * Parameters:
+ * {OpenLayers.Feature} Feature
+ *
+ * Returns:
+ * {String} A name for a layer.
+ */
+function createLayerName(feature) {
+
+    var name = null;
+
+    name = feature.attributes.job_id;
+    name = name + " - " + feature.attributes.description;
+
+    return name;
+}
+
+
+/**
+ * Method: refreshResultPanel
+ * This method creates a panel with all jobs started by the current user.
+ *
+ * Parameters:
+ * response - {XMLHttpResponse} Response of a wfs GetFeatureRequest
+ */
+function refreshResultPanel(response) {
+
+    // cleaning old results
+    $j('#results').html(null);
+
+    // array to save already written jobs
+    var usedJobId = new Array();
+
+    // read all features of the response
+    features = new OpenLayers.Format.GML().read(response.responseText);
+    for(var i = 0; i < features.length; ++i) {
+        var job = features[i].attributes.job_id;
+        var des = features[i].attributes.description;
+        var sta = features[i].attributes.startzeit;
+        var sto = features[i].attributes.stopzeit;
+
+        // add new job to the result panel
+        if($j.inArray(job, usedJobId) == '-1') {
+            var content  = '<input type="radio" name="job" value="'+job+'">';
+            content     += job;
+            content     += '- '+ des + ' ';
+            content     += '(' + sta + ')';
+            content     += '(' + sto + ')';
+            content     += '<br>';
+            $j('#results').append(content);
+            usedJobId.push(job);
+        }
+    }
+
+    if(features.length != 0) {
+        // add the button to load a selected job into the map
+        var button = '<input type="button" value="Load job" onClick="loadSelectedJob();">';
+        $j('#results').append(button);
+    }
+    else {
+        var content = '<font color="red">No results for the current user.</font>';
+        $j('#results').append(content);
+    }
+}
+
+
+/**
+ * Method: resultPanel
+ * This method fetches the calculation results of WSPLGEN from the current user
+ * and river and gives the user the possibility via radio buttons to load one of
+ * these results into the map.
+ */
+function resultPanel() {
+
+    // fetch needed information from session
+    var uid = getUserId();
+    var gew = getGewaesser();
+
+    fetchUserResults(refreshResultPanel, null, uid, gew);
+}
+
+
+/**
+ * Method: loadSelectedJob
+ * This method fetches the selected job (selected radio button) and loads this
+ * job into the map.
+ */
+function loadSelectedJob() {
+
+    // fetch needed information from session
+    var uid = getUserId();
+    var gew = getGewaesser();
+
+    // find the selected job
+    var jobId = null;
+
+    var checkboxen = $j('input[name=job]:radio');
+    $j.each(checkboxen, function() {
+        if($j(this).attr('checked') == true)
+            jobId = $j(this).val();
+    });
+
+    // load the job selected by the radio button
+    fetchUserResults(addResults, jobId, uid, gew);
+}
 // 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-31 15:37:36 UTC (rev 47)
+++ webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/main.jsp	2009-04-06 12:36:19 UTC (rev 48)
@@ -178,7 +178,17 @@
                            value="<bean:message key='main.calculation.submit' />" id="button" >
                 </html:form>
             </div>
+
+            <%-- the map --%>
             <div id="map"></div>
+            <div style="float: left; width: 75px;">&nbsp;</div>
+
+            <%-- the panel to show the results --%>
+            <fieldset id="resultPanel">
+                <input type="button" value="<bean:message key='wsplgen.refresh.button'/>" onClick="resultPanel();">
+                <legend><bean:message key="wsplgen.result.title"/></legend>
+                <div id="results"></div>
+            </fieldset>
         </div>
     </body>
 </html:html>

Modified: webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/style.css
===================================================================
--- webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/style.css	2009-03-31 15:37:36 UTC (rev 47)
+++ webflysuesk/branches/openlayers-integration/webflys/src/main/webapp/pages/style.css	2009-04-06 12:36:19 UTC (rev 48)
@@ -13,10 +13,10 @@
     float: left;
 }
 #map {
-    width: 600px;
+    width: 500px;
     height: 600px;
     border: 1px solid #669FD1;
-    float: right;
+    float: left;
 }
 #menu {
 	border: 1px solid #669FD1;
@@ -24,6 +24,12 @@
 	font-size: 8pt;
 	font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
 }
+#resultPanel {
+	border: 1px solid #669FD1;
+	width : 400px;
+	font-size: 8pt;
+	font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
+}
 #table {
 	width: 100%;
 	border: 0px;



More information about the Webflysuesk-commits mailing list