[Commits] r2629 - in sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing: examples lib/GeoExt.ux/widgets

commits at geoext.org commits at geoext.org
Tue Mar 22 15:35:18 CET 2011


Author: adube
Date: 2011-03-22 15:35:18 +0100 (Tue, 22 Mar 2011)
New Revision: 2629

Modified:
   sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/examples/WFSTFeatureEditing.js
   sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/WFSTFeatureEditingManager.js
Log:
WFSTFeatureEditing - GeomType detection, draw control and actions, menu buttons, auto hide-show vector layer upon draw

Modified: sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/examples/WFSTFeatureEditing.js
===================================================================
--- sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/examples/WFSTFeatureEditing.js	2011-03-21 20:14:50 UTC (rev 2628)
+++ sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/examples/WFSTFeatureEditing.js	2011-03-22 14:35:18 UTC (rev 2629)
@@ -3,17 +3,12 @@
 Ext.onReady(function() {
     Ext.QuickTips.init();
 
-    url = "http://dev8.mapgears.com/cgi-bin/tinyows-trunk";
+    msURL = "http://dev8.mapgears.com/cgi-bin/mswms_gmap_trunk";
+    tinyURL = "http://dev8.mapgears.com/cgi-bin/tinyows-trunk";
 
-    var actions = [];
-    var action = new Ext.Action({
-      text: 'Dummy',
-      scope: this
-    });
-    actions.push(action);
-    toolbar = new Ext.Toolbar(actions);
-
+    // == Map ==
     var options = {
+        allOverlays: true,
         projection: new OpenLayers.Projection("EPSG:900913"),
         displayProjection: new OpenLayers.Projection("EPSG:4326"),
         units: "m",
@@ -24,9 +19,52 @@
     };
     map = new OpenLayers.Map('map', options);
 
+    // == Toolbar and Actions ==
+    var actions = [];
+
+    // ZoomToMaxExtent control, a "button" control
+    action = new GeoExt.Action({
+        control: new OpenLayers.Control.ZoomToMaxExtent(),
+        map: map,
+        text: "max extent",
+        tooltip: "zoom to max extent"
+    });
+    actions.push(action);
+    actions.push("-");
+
+    // Navigation control and DrawFeature controls
+    // in the same toggle group
+    action = new GeoExt.Action({
+        text: "nav",
+        control: new OpenLayers.Control.Navigation(),
+        map: map,
+        // button options
+        toggleGroup: "myGroup",
+        allowDepress: false,
+        pressed: true,
+        tooltip: "navigate",
+        // check item options
+        group: "myGroup",
+        checked: true
+    });
+    actions.push(action);
+    toolbar = new Ext.Toolbar(actions);
+
+    // == MapPanel ==
+    wmsOptions = {isBaseLayer: false, singleTile: true};
     mapPanel = new GeoExt.MapPanel({
         region: "center",
-        layers: [new OpenLayers.Layer.OSM()],
+        layers: [
+            //new OpenLayers.Layer.OSM(),
+            new OpenLayers.Layer.WMS('Bathymetry', msURL, {
+                transparent: true, layers: 'bathymetry'}, wmsOptions),
+            new OpenLayers.Layer.WMS('Drainage', msURL, {
+                transparent: true, layers: 'drainage'}, wmsOptions),
+            new OpenLayers.Layer.WMS('Roads', msURL, {
+                transparent: true, layers: 'road'}, wmsOptions),
+            new OpenLayers.Layer.WMS('Cities', msURL, {
+                transparent: true, layers: 'popplace'}, wmsOptions)
+        ],
         map: map,
         tbar: toolbar
     });
@@ -51,11 +89,13 @@
         items: [mapPanel, tree]
     });
 
-    map.setCenter(new OpenLayers.LonLat(-10762333.581055,5968203.1676758), 2);
+    map.setCenter(new OpenLayers.LonLat(-8005708,6182838), 7);
 
+    // WFSTFeatureEditingManager
     manager = new GeoExt.ux.WFSTFeatureEditingManager({
-        'map': mapPanel.map,
-        'toolbar': toolbar,
-        'url': url
+        "map": mapPanel.map,
+        "toolbar": toolbar,
+        "url": tinyURL,
+        "actionGroup": "myGroup"
     });
 });

Modified: sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/WFSTFeatureEditingManager.js
===================================================================
--- sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/WFSTFeatureEditingManager.js	2011-03-21 20:14:50 UTC (rev 2628)
+++ sandbox/mapgears/geoext.ux/ux/WFSTFeatureEditing/lib/GeoExt.ux/widgets/WFSTFeatureEditingManager.js	2011-03-22 14:35:18 UTC (rev 2629)
@@ -10,10 +10,32 @@
         'VERSION': "1.0.0"
     },
 
+    DEFAULT_DESCRIBE_FEATURETYPE_PARAMS: {
+        'SERVICE': "WFS",
+        'REQUEST': "DescribeFeatureType",
+        'VERSION': "1.0.0"
+    },
+
     DEFAULT_PROTOCOL_OPTIONS: {
         featureNS: "http://localhost"
     },
 
+    DEFAULT_ACTION_GROUP: "wfstFeatureEditing",
+
+
+/* i18n  */
+
+    drawMenuButtonText: "Draw",
+
+    drawMenuButtonTooltipText: "Add Tool: Select a layer from the list then " +
+        "digitalize a new feature by clicking on the map.",
+
+    editMenuButtonText: "Edit",
+
+    editMenuButtonTooltipText: "Edit Tool: Select a layer from the list then " +
+        "click on a feature on the map to edit it.",
+
+
 /* API */
 
     toolbar: null,
@@ -24,27 +46,63 @@
 
     capabilitiesParams: null,
 
+    describeFeatureTypeParams: null,
+
     protocolOptions: null,
 
+    geomProperty: "the_geom",
 
+    actionGroup: null,
+
+
 /* PRIVATE*/
 
     mainPanel: null,
 
     statusBar: null,
 
+    queries: null,
+
+    layers: null,
+
+    drawMenuButton: null,
+
+    editMenuButton: null,
+
+    isDrawing: false,
+
     /** private: method[constructor]
      *  Private constructor override.
      */
     constructor: function(config) {
         Ext.apply(this, config);
         arguments.callee.superclass.constructor.call(this, config);
+        this.queries = 0;
+        this.layers = [];
         this.initMainTools();
         this.url && this.createToolsFromURL(this.url);
     },
 
     initMainTools: function() {
-        
+        this.drawMenuButton = new Ext.Button({
+            //"iconCls": "wfstFeatureEditing_DrawFeature",
+            "text": this.drawMenuButtonText,
+            "menu": new Ext.menu.Menu(),
+            "tooltip": this.drawMenuButtonTooltipText
+        });
+    
+        this.editMenuButton = new Ext.Button({
+            //"iconCls": "wfstFeatureEditing_EditFeature",
+            "text": this.editMenuButtonText,
+            "menu": new Ext.menu.Menu(),
+            "tooltip": this.editMenuButtonTooltipText
+        });
+
+        this.toolbar.addItem("-");
+        this.toolbar.addItem(this.drawMenuButton);
+        this.toolbar.addItem(this.editMenuButton);
+        this.toolbar.addItem("-");
+        this.toolbar.doLayout();
     },
 
     createToolsFromURL: function(url) {
@@ -66,7 +124,7 @@
                 // todo: delegate to WFSCapabilitiesReader
                 projection: new OpenLayers.Projection(this.map.getProjection()),
                 visibility: false,
-                //displayInLayerSwitcher: false,
+                displayInLayerSwitcher: false,
                 //minScale: 250000
             }
         });
@@ -78,6 +136,8 @@
         var layers = [];
         Ext.each(records, function(record, index) {
             var layer = record.getLayer().clone();
+            layer.wfstFeatureEditing = {"manager": this};
+            
             // todo : create SaveStrategy in WFSCapabilitiesReader
             // find the save strategy and keep a reference to it
 /*
@@ -94,18 +154,154 @@
             });
 */
             layers.push(layer);
-        });
-        this.map.addLayers( layers.reverse() );
-/*
+        }, this);
+        this.map.addLayers(layers);
+        this.layers = layers;
+
         Ext.each(layers, function(layer, index) {
-            OpenLayers.loadURL(layer.protocol.url, {
-                'SERVICE': "WFS",
-                'REQUEST': "DescribeFeatureType",
-                'VERSION': "1.0.0",
-                'TYPENAME': layer.protocol.featureType
-            }, layer, wfsDFTSuccess, wfsDFTFailure
-            );
+            var params = Ext.applyIf(Ext.applyIf(
+                this.describeFeatureTypeParams || {},
+                this.DEFAULT_DESCRIBE_FEATURETYPE_PARAMS),
+                {'TYPENAME': layer.protocol.featureType});
+
+            OpenLayers.loadURL(layer.protocol.url, params,
+                {layer: layer, manager: this},
+                this.onDescribeFeatureTypeSuccess,
+                this.onDescribeFeatureTypeFailure);
+        }, this);
+    },
+
+    onDescribeFeatureTypeSuccess: function(response) {
+        var format = new OpenLayers.Format.WFSDescribeFeatureType();
+        format.setNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
+
+        var describe = format.read(response.responseXML);
+
+        if (describe && describe.featureTypes && describe.featureTypes[0]) {
+            Ext.each(describe.featureTypes[0].properties, function(property, index) {
+                if (property.name == this.manager.geomProperty) {
+                    var geomType;
+                    switch (property.localType) {
+                      case "PointPropertyType":
+                        this.layer.wfstFeatureEditing.drawHandler =
+                            OpenLayers.Handler.Point;
+                        break;
+                      case "LineStringPropertyType":
+                        this.layer.wfstFeatureEditing.drawHandler =
+                            OpenLayers.Handler.Path;
+                        break;
+                      case "PolygonPropertyType":
+                        this.layer.wfstFeatureEditing.drawHandler =
+                            OpenLayers.Handler.Polygon;
+                        break;
+                      case "MultiPointPropertyType":
+                        this.layer.wfstFeatureEditing.drawHandler =
+                            OpenLayers.Handler.Point;
+                        this.layer.wfstFeatureEditing.multiGeometry =
+                            OpenLayers.Geometry.MultiPoint;
+                        break;
+                      case "MultiLineStringPropertyType":
+                        this.layer.wfstFeatureEditing.drawHandler =
+                            OpenLayers.Handler.Path;
+                        this.layer.wfstFeatureEditing.multiGeometry =
+                            OpenLayers.Geometry.MultiLineString;
+                        break;
+                      case "MultiPolygonPropertyType":
+                        this.layer.wfstFeatureEditing.drawHandler =
+                            OpenLayers.Handler.Polygon;
+                        this.layer.wfstFeatureEditing.multiGeometry =
+                            OpenLayers.Geometry.MultiPolygon;
+                        break;
+                    }
+                    return false;
+                }
+            }, this);
+        }
+
+        this.manager.queries++;
+
+        if (this.manager.queries == this.manager.layers.length) {
+            this.manager.createEditingTools();
+        }
+    },
+
+    onDescribeFeatureTypeFailure: function(response) {
+        //todo
+    },
+
+    createEditingTools: function() {
+        Ext.each(this.layers, function(layer, index) {
+            this.createEditingToolsForLayer(layer);
+        }, this);
+        this.toolbar.doLayout();
+        this.resetAll();
+    },
+
+    createEditingToolsForLayer: function(layer) {
+
+        // ======================
+        // DrawFeature and Action
+        // ======================
+        var handler = layer.wfstFeatureEditing.drawHandler ||
+            OpenLayers.Handler.Point;
+        var drawControl = new OpenLayers.Control.DrawFeature(layer, handler);
+        drawControl.events.on({
+            "activate": function() { this.setVisibility(true); },
+            "deactivate": function() { this.setVisibility(false); },
+            "featureadded": function(e) {
+                var feature = e.feature;
+                if (feature) {
+                    var layer = feature.layer;
+                    var multiGeom = layer.wfstFeatureEditing.multiGeometry;
+    
+                    // if we're dealing with a "MultiGeometry" layer, we
+                    // must cast the geometry as "Multi" when the feature
+                    // drawing is completed
+                    if (multiGeom) {
+                        layer.eraseFeatures([feature]);
+                        feature.geometry = new multiGeom(feature.geometry);
+                    }
+                    /*
+                    this.editingTools.drawControl.deactivate();
+                    this.editingTools.selectControl.activate();
+                    this.editingTools.selectControl.select(feature);
+                    */
+                }
+            },
+            scope: layer
         });
-*/
+
+        // create the action, add it to BOTH the toolbar and menu (hidden) to
+        // allow the toogleGroup and group properties to work properly.  Show
+        // the menu item after it has been added
+        var drawAction = new GeoExt.Action({
+            text: layer.name,
+            hidden: true,
+            control: drawControl,
+            map: map,
+            disabled: !layer.inRange,
+            // button options
+            toggleGroup: this.actionGroup || this.DEFAULT_ACTION_GROUP,
+            allowDepress: false,
+            // check item options
+            group: this.actionGroup || this.DEFAULT_ACTION_GROUP
+        });
+        this.toolbar.addItem(drawAction);
+        this.drawMenuButton.menu.addItem(new Ext.menu.CheckItem(drawAction));
+        var drawMenuItem = this.drawMenuButton.menu.items.items[
+            this.drawMenuButton.menu.items.getCount() - 1
+        ];
+        drawMenuItem.show();
+        drawMenuItem.on("click", function() {
+            this.isDrawing = true;
+        }, this);
+
+        layer.wfstFeatureEditing.drawAction = drawAction;
+        layer.wfstFeatureEditing.drawControl = drawControl;
+    },
+
+    resetAll: function() {
+        this.layers = [];
+        this.queries = 0;
     }
 });



More information about the Commits mailing list