[OpenLayers-Commits] r2015 - in sandbox/vector/lib: . OpenLayers OpenLayers/Control/EditingTool OpenLayers/Layer OpenLayers/Parser OpenLayers/Tile OpenLayers/Writer

commits at openlayers.org commits at openlayers.org
Wed Dec 6 10:55:48 EST 2006


Author: pgiraud
Date: 2006-12-06 10:55:47 -0500 (Wed, 06 Dec 2006)
New Revision: 2015

Added:
   sandbox/vector/lib/OpenLayers/Control/EditingTool/Commit.js
   sandbox/vector/lib/OpenLayers/Writer.js
   sandbox/vector/lib/OpenLayers/Writer/
   sandbox/vector/lib/OpenLayers/Writer/GML.js
   sandbox/vector/lib/OpenLayers/Writer/WFS.js
Modified:
   sandbox/vector/lib/OpenLayers.js
   sandbox/vector/lib/OpenLayers/Ajax.js
   sandbox/vector/lib/OpenLayers/Layer/GML.js
   sandbox/vector/lib/OpenLayers/Layer/Vector.js
   sandbox/vector/lib/OpenLayers/Layer/WFS.js
   sandbox/vector/lib/OpenLayers/Parser.js
   sandbox/vector/lib/OpenLayers/Parser/GML.js
   sandbox/vector/lib/OpenLayers/Tile/WFS.js
Log:
WFS-T first implementation
it needs more work on it

Modified: sandbox/vector/lib/OpenLayers/Ajax.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Ajax.js	2006-12-06 15:53:18 UTC (rev 2014)
+++ sandbox/vector/lib/OpenLayers/Ajax.js	2006-12-06 15:55:47 UTC (rev 2015)
@@ -53,7 +53,9 @@
     if (OpenLayers.ProxyHost && uri.startsWith("http")) {
         uri = OpenLayers.ProxyHost + escape(uri);
     }
+    
 
+
     var success = (onComplete) ? onComplete.bind(caller)
                                 : OpenLayers.nullHandler;
 
@@ -70,6 +72,12 @@
                      );
 };
 
+OpenLayers.serializeXMLNode = function(node) {
+    var serializer = new XMLSerializer();
+    return serializer.serializeToString(node);
+};
+
+
 /** Parse XML into a doc structure
 * @param {String} text
 *
@@ -188,8 +196,9 @@
   },
 
   request: function(url) {
+
     var parameters = this.options.parameters || '';
-    if (parameters.length > 0) parameters += '&_=';
+//    if (parameters.length > 0) parameters += '&_=';
 
     try {
       this.url = url;
@@ -211,6 +220,7 @@
       var body = this.options.postBody ? this.options.postBody : parameters;
       this.transport.send(this.options.method == 'post' ? body : null);
 
+
     } catch (e) {
       this.dispatchException(e);
     }

Added: sandbox/vector/lib/OpenLayers/Control/EditingTool/Commit.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Control/EditingTool/Commit.js	                        (rev 0)
+++ sandbox/vector/lib/OpenLayers/Control/EditingTool/Commit.js	2006-12-06 15:55:47 UTC (rev 2015)
@@ -0,0 +1,83 @@
+/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
+ * for the full text of the license. */
+
+/**
+ * @class
+ *
+ * @requires OpenLayers/Control/EditingTool.js
+ */
+OpenLayers.Control.EditingTool.Commit = OpenLayers.Class.create();
+OpenLayers.Control.EditingTool.Commit.prototype = OpenLayers.Class.inherit( OpenLayers.Control.EditingTool, {
+
+    /** @type String */
+    image: "media-floppy.png",
+
+    /** @type OpenLayers.Size */
+    size: new OpenLayers.Size(22, 22),
+
+    /**
+     * @constructor
+     */
+    initialize: function() {
+        OpenLayers.Control.EditingTool.prototype.initialize.apply(this, arguments);
+    },
+    
+    /** 
+     * Function
+     * 
+     * Turn on the current tool and catch all the concerned events.
+     */
+    turnOn: function(){
+        OpenLayers.Control.EditingTool.prototype.turnOn.apply(this, arguments);
+        this.layer.commit();
+    },
+
+    /** 
+     * Function
+     * 
+     * Turn off the current tool.
+     */    
+    turnOff: function(){
+        OpenLayers.Control.EditingTool.prototype.turnOff.apply(this, arguments);
+    },
+
+    /** 
+     * Function
+     * 
+     * Finalize the feature and add it to the vector layer.
+     */
+    finalizeGeometry: function(){},
+    
+    /**
+     * Function
+     * 
+     * @param {Event} evt
+     */
+    defaultMouseDown: function (evt) {},
+
+    /**
+     * Function
+     * 
+     * @param {Event} evt
+     */
+    defaultMouseMove: function (evt) {},
+
+    /**
+     * Function
+     * 
+     * @param {Event} evt
+     */
+    defaultMouseUp: function (evt) {},
+
+    /**
+     * Function
+     * 
+     * @param {Event} evt
+     */
+    defaultKeyDown: function(evt){},
+
+    /** @final @type String */
+    CLASS_NAME: "OpenLayers.Control.Commit"
+    
+});

Modified: sandbox/vector/lib/OpenLayers/Layer/GML.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Layer/GML.js	2006-12-06 15:53:18 UTC (rev 2014)
+++ sandbox/vector/lib/OpenLayers/Layer/GML.js	2006-12-06 15:55:47 UTC (rev 2015)
@@ -83,7 +83,8 @@
             doc = OpenLayers.parseXMLString(request.responseText);
         }
 
-        var gml = new OpenLayers.Parser.GML(doc);
+        var gml = new OpenLayers.Parser.GML();
+        gml.load(doc);
         var featureCollection = gml.featureCollection;
         
         this.addFeatures(featureCollection);

Modified: sandbox/vector/lib/OpenLayers/Layer/Vector.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Layer/Vector.js	2006-12-06 15:53:18 UTC (rev 2014)
+++ sandbox/vector/lib/OpenLayers/Layer/Vector.js	2006-12-06 15:55:47 UTC (rev 2015)
@@ -11,16 +11,27 @@
 OpenLayers.Layer.Vector.prototype = 
   OpenLayers.Class.inherit( OpenLayers.Layer, {
 
+    /** @type Boolean */
     isBaseLayer: false,
 
+    /** @type Boolean */
     isFixed: true,
 	
+    /** @type Boolean */
 	isVector: true,
 	
 	isSelected: false,
 
     map: null,
 
+    url: '',
+
+    /** @type OpenLayers.Parser */
+    parser: null,
+
+    /** @type OpenLayers.Writer */
+    writer: null,
+
     /**
      * @constructor
      * 
@@ -37,13 +48,18 @@
                             new OpenLayers.Renderer.Vml(this);
         }
         
-        if (!this.style){
+        if (!this.style) {
             this.style = OpenLayers.Style.DefaultRendererStyle;
         }
-        
+
+        // load features
+        if (!this.parser) {
+            //this.parser = new OpenLayers.Parser.GML();
+            //this.parser.load(this.url, this.map.bbox, this.requestSuccess, this.requestFailure);
+        }
+
         this.features = new Array();
         this.selection = new Array();
-
     },
 
     /**
@@ -53,8 +69,13 @@
      */
     addFeatures: function(features) {
         if (!(features instanceof Array)) {
-           features = [features];
+            features = [features];
         }
+        
+        //add reference to the layer
+        for (var i = 0; i < features.length; i++) {
+            features[i].layer = this;
+        }
 
         this.features = this.features.concat(features);
         
@@ -80,13 +101,14 @@
         }
         
         for (var i = 0; i < features.length; i++) {
-            this.features = OpenLayers.Util.removeItem(this.features, features[i]);
+            //this.features = OpenLayers.Util.removeItem(this.features, features[i]);
             
             this.renderer.eraseGeometry(features[i].geometry);
         }
         
+        
         // update the feature state
-        for(var i = 0; i < features; i++) {
+        for(var i = 0; i < features.length; i++) {
             features[i].toState(OpenLayers.State.DELETE);
         }
         
@@ -137,6 +159,15 @@
         //console.log("feature unknown");
     },
 
+
+    commit: function() {
+        if (!this.writer) {
+            this.writer = new OpenLayers.Writer.WFS();
+        }
+        this.writer.commit(this.url, this.features, this.commitSuccess, this.commitFailure);
+        // foreach features: set state to null
+    },
+
     /** @final @type String */
     CLASS_NAME: "OpenLayers.Layer.Vector"
 });

Modified: sandbox/vector/lib/OpenLayers/Layer/WFS.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Layer/WFS.js	2006-12-06 15:53:18 UTC (rev 2014)
+++ sandbox/vector/lib/OpenLayers/Layer/WFS.js	2006-12-06 15:55:47 UTC (rev 2015)
@@ -190,9 +190,31 @@
         return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(
                                                     this, arguments);
     },
+        
+    /**
+     * Called when the Ajax request returns a response
+     *
+     * @param {XmlNode} response from server
+     */
+    commitSuccess: function(request) {
+        var response = request.responseText;
+        if (response.indexOf('SUCCESS') != -1) {
+            alert ('WFS Transaction : SUCCESS');
+            // TBD redraw the layer or reset the state of features
+            // foreach features: set state to null
+        } else if (response.indexOf('FAILED') != -1 ||
+            response.indexOf('Exception') != -1) {
+            alert ('WFS Transaction : FAILED');
+        }
+    },
+    
+    /**
+     * Called when the Ajax request fails
+     *
+     * @param {XmlNode} response from server
+     */
+    commitFailure: function(request) {},
 
-
-
     /** @final @type String */
     CLASS_NAME: "OpenLayers.Layer.WFS"
 });

Modified: sandbox/vector/lib/OpenLayers/Parser/GML.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Parser/GML.js	2006-12-06 15:53:18 UTC (rev 2014)
+++ sandbox/vector/lib/OpenLayers/Parser/GML.js	2006-12-06 15:55:47 UTC (rev 2015)
@@ -16,14 +16,18 @@
     
     /** @type array */
     featureCollection: [],
-      
+    
     /** 
      * @constructor
+     */
+    initialize: function() {},
+
+    /** 
+     * loads an GML file and build the featureCollection
      * 
-     * @param {OpenLayers.Layer} layer
      * @param {XMLNode} xmlNode A GML file as an XML node.
      */
-    initialize: function(xmlNode) {
+    load: function(xmlNode) {
         var newArguments = arguments;
         
         // pgiraud : should not have to be initialized
@@ -44,7 +48,7 @@
         // Process all the featureMembers
         for (var i=0; i < featureNodes.length; i++) {
             var feature = this.processXMLNode(featureNodes[i]);
-            
+
             if (feature) {
                 this.featureCollection.push(feature);
                 

Modified: sandbox/vector/lib/OpenLayers/Parser.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Parser.js	2006-12-06 15:53:18 UTC (rev 2014)
+++ sandbox/vector/lib/OpenLayers/Parser.js	2006-12-06 15:55:47 UTC (rev 2015)
@@ -11,11 +11,14 @@
     
     /** 
     * @constructor
-    *
-    * @param {OpenLayers.Icon} icon
-    * @param {OpenLayers.LonLat lonlat
     */
-    initialize: function() {
+    initialize: function() {},
+
+    /**
+     *
+     */
+    load: function(uri, bbox, onComplete, onFailure) {
+
     },
     
     destroy: function() {

Modified: sandbox/vector/lib/OpenLayers/Tile/WFS.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Tile/WFS.js	2006-12-06 15:53:18 UTC (rev 2014)
+++ sandbox/vector/lib/OpenLayers/Tile/WFS.js	2006-12-06 15:55:47 UTC (rev 2015)
@@ -66,7 +66,7 @@
         if (this.layer.displayOutsideMaxExtent || (this.layer.maxExtent && 
             this.layer.maxExtent.intersectsBounds(this.bounds, false))) { 
             this.loadFeaturesForRegion(this.requestSuccess);
-        }         
+        }
     },
 
     /** get the full request string from the ds and the tile params 
@@ -91,7 +91,9 @@
         if (!doc || request.fileType!="XML") {
             doc = OpenLayers.parseXMLString(request.responseText);
         }
-        var gml = new OpenLayers.Parser.GML(doc);
+        
+        var gml = new OpenLayers.Parser.GML();
+        gml.load(doc);
         var featureCollection = gml.featureCollection;
         
         this.layer.addFeatures(featureCollection);

Added: sandbox/vector/lib/OpenLayers/Writer/GML.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Writer/GML.js	                        (rev 0)
+++ sandbox/vector/lib/OpenLayers/Writer/GML.js	2006-12-06 15:55:47 UTC (rev 2015)
@@ -0,0 +1,47 @@
+/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
+ * for the full text of the license. */
+
+/**
+ * @class GML
+ * 
+ */
+OpenLayers.Writer.GML = OpenLayers.Class.create();
+OpenLayers.Writer.GML.prototype = {
+    
+    /** @type {XMLNode} */
+    gml: '',
+    
+    /** 
+     * @constructor
+     */
+    initialize: function() {},
+
+    /** 
+     * builds a GML file with a given geometry
+     * 
+     * @param {OpenLayers.Geometry} geometry
+     */
+    buildXmlNode: function(geometry) {
+        this.gml = document.createElementNS("http://www.opengis.net/gml", 'gml:LineString');
+        
+        // TBD retrieve the srs from layer
+        this.gml.setAttribute("srsName", "http://www.opengis.net/gml/srs/epsg.xml#4326");
+        
+        var coordinates = document.createElementNS("http://www.opengis.net/gml", "gml:coordinates");
+        coordinates.setAttribute("decimal", ".");
+        coordinates.setAttribute("cs", ",");
+        coordinates.setAttribute("ts", " ");
+        
+        var points = geometry.path;
+        var path = "";
+        for (var i = 0; i < points.length; i++) {
+            path += points[i].lon + "," + points[i].lat + " ";
+        }
+        
+        var txtNode = document.createTextNode(path);
+        coordinates.appendChild(txtNode);
+        
+        this.gml.appendChild(coordinates);
+    },
+}
\ No newline at end of file

Added: sandbox/vector/lib/OpenLayers/Writer/WFS.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Writer/WFS.js	                        (rev 0)
+++ sandbox/vector/lib/OpenLayers/Writer/WFS.js	2006-12-06 15:55:47 UTC (rev 2015)
@@ -0,0 +1,135 @@
+/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
+ * for the full text of the license. */
+
+/**
+ * @class WKT
+ * 
+ * @requires OpenLayers/Writer.js
+ */
+OpenLayers.Writer.WFS = OpenLayers.Class.create();
+OpenLayers.Writer.WFS.prototype = OpenLayers.Class.inherit( OpenLayers.Writer, {
+ 
+    /** 
+     * @constructor
+     */
+    initialize: function(features) {
+    
+    },
+    
+    /**
+     * Destroy this class.
+     */
+    destroy: function() {},
+    
+
+    
+    commit: function(uri, features, onSuccess, onFailure) {
+
+        var transaction = document.createElementNS('http://www.opengis.net/wfs', 'wfs:Transaction');
+
+        for (var i=0; i<features.length; i++) {
+            switch (features[i].state) {
+                case OpenLayers.State.INSERT:
+                    transaction.appendChild(this._insert(features[i]));
+                    break;
+                case OpenLayers.State.UPDATE:
+                    transaction.appendChild(this._update(features[i]));
+                    break;
+                case OpenLayers.State.DELETE:
+                    transaction.appendChild(this._delete(features[i]));
+                    break;
+            }
+        }
+        
+        if (transaction.childNodes.length == 0) {
+            alert ("nothing to commit");
+            return;
+        }
+        
+        transaction = OpenLayers.serializeXMLNode(transaction);
+        
+        new OpenLayers.Ajax.Request("/geoserver/wfs/transaction", 
+                                    {
+                                        method: 'post', 
+//                                        parameters: '<?xml version="1.0" ?>' + OpenLayers.serializeXMLNode(transaction)
+                                          parameters: transaction,
+                                          onComplete: onSuccess, 
+                                          onFailure: onFailure
+                                    });
+    },
+ 
+    /**
+     * @type String
+     */
+    _insert: function(feature) {
+        var insertNode = document.createElementNS('http://www.opengis.net/wfs', 'wfs:Insert');
+        
+        //TBD typename needs to be stored and retrieved from the layer
+        // xmlns may be wrong
+        var element = document.createElementNS('http://www.opengis.net/wfs', feature.layer.params.typename);
+        // xmlns may be wrong
+        var geometry = document.createElementNS('http://www.opengis.net/wfs', feature.layer.params.geometry_column);
+        
+        var gml = new OpenLayers.Writer.GML();
+        gml.buildXmlNode(feature.geometry);
+        
+        geometry.appendChild(gml.gml);
+        element.appendChild(geometry);
+        insertNode.appendChild(element);
+        
+        return insertNode;
+    },
+
+    /**
+     * @type String
+     */
+    _update: function(feature) {
+        var updateNode = document.createElementNS('http://www.opengis.net/wfs', 'wfs:Update');
+        updateNode.setAttribute("typeName", feature.attributes.featureMember.childNodes[0].nodeName);
+
+        var propertyNode = document.createElementNS('http://www.opengis.net/wfs', 'wfs:Property');
+        var nameNode = document.createElementNS('http://www.opengis.net/wfs', 'wfs:Name');
+        
+        // TBD get the geometry field name
+        var txtNode = document.createTextNode("wkb_geometry");
+        nameNode.appendChild(txtNode);
+        propertyNode.appendChild(nameNode);
+        
+        var valueNode = document.createElementNS('http://www.opengis.net/wfs', 'wfs:Value');
+        
+        var gml = new OpenLayers.Writer.GML();
+        gml.buildXmlNode(feature.geometry);
+        valueNode.appendChild(gml.gml);
+
+        propertyNode.appendChild(valueNode);
+        updateNode.appendChild(propertyNode);
+        
+        var filterNode = document.createElementNS('http://www.opengis.net/ogc', 'ogc:Filter');
+        var filterIdNode = document.createElementNS('http://www.opengis.net/ogc', 'ogc:FeatureId');
+        filterIdNode.setAttribute("fid", feature.attributes.featureMember.childNodes[0].attributes['fid'].nodeValue);
+        filterNode.appendChild(filterIdNode);
+        updateNode.appendChild(filterNode);
+        
+        return updateNode;
+    },
+
+    /**
+     * @type String
+     */
+    _delete: function(feature) {
+        var deleteNode = document.createElementNS('http://www.opengis.net/wfs', 'wfs:Delete');
+        deleteNode.setAttribute("typeName", feature.attributes.featureMember.childNodes[0].nodeName);
+ 
+        var filterNode = document.createElementNS('http://www.opengis.net/ogc', 'ogc:Filter');
+        var filterIdNode = document.createElementNS('http://www.opengis.net/ogc', 'ogc:FeatureId');
+        filterIdNode.setAttribute("fid", feature.attributes.featureMember.childNodes[0].attributes['fid'].nodeValue);
+        filterNode.appendChild(filterIdNode);
+        deleteNode.appendChild(filterNode);
+
+        return deleteNode;
+    },
+
+    /** @final @type String */
+    CLASS_NAME: "OpenLayers.Writer.WFS"
+});

Added: sandbox/vector/lib/OpenLayers/Writer.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Writer.js	                        (rev 0)
+++ sandbox/vector/lib/OpenLayers/Writer.js	2006-12-06 15:55:47 UTC (rev 2015)
@@ -0,0 +1,31 @@
+/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
+ * for the full text of the license. */
+
+
+/**
+ * @class
+ */
+OpenLayers.Writer = OpenLayers.Class.create();
+OpenLayers.Writer.prototype = {
+    
+    /** 
+    * @constructor
+    */
+    initialize: function() {},
+    
+    destroy: function() {},
+    
+
+    commit: function(uri, features, onSuccess, onFailure) {
+        
+    },
+    
+    _insert: function(feature) {},
+    _update: function(feature) {},
+    _delete: function(feature) {},
+   
+    
+    /** @final @type String */
+    CLASS_NAME: "OpenLayers.Writer"
+};

Modified: sandbox/vector/lib/OpenLayers.js
===================================================================
--- sandbox/vector/lib/OpenLayers.js	2006-12-06 15:53:18 UTC (rev 2014)
+++ sandbox/vector/lib/OpenLayers.js	2006-12-06 15:55:47 UTC (rev 2015)
@@ -114,6 +114,7 @@
         "OpenLayers/Control/EditingTool/AddPathPoint.js",
         "OpenLayers/Control/EditingTool/DrawLinearRing.js",
         "OpenLayers/Control/EditingTool/Rotate.js",
+        "OpenLayers/Control/EditingTool/Commit.js",
         "OpenLayers/Control/EditingMode.js",
         "OpenLayers/Control/EditingMode/PointSnapping.js",
         "OpenLayers/Control/EditingMode/SegmentSnapping.js",
@@ -138,7 +139,10 @@
         "OpenLayers/Style.js",
         "OpenLayers/Style/WebSafe.js",
         "OpenLayers/Parser.js",
-        "OpenLayers/Parser/GML.js"
+        "OpenLayers/Parser/GML.js",
+        "OpenLayers/Writer.js",
+        "OpenLayers/Writer/WFS.js",
+        "OpenLayers/Writer/GML.js"
         
     ); // ec.
 



More information about the Commits mailing list