[OpenLayers-Trac] [OpenLayers] #3472: OpenLayers.Control.Split does not synchronize with other datastore

OpenLayers trac-20090302 at openlayers.org
Mon Aug 22 08:22:50 EDT 2011


#3472: OpenLayers.Control.Split does not synchronize with other datastore
----------------------+-----------------------------------------------------
 Reporter:  ckreuzbe  |       Owner:              
     Type:  bug       |      Status:  new         
 Priority:  minor     |   Milestone:  2.11 Release
Component:  general   |     Version:  2.10        
 Keywords:            |       State:              
----------------------+-----------------------------------------------------
 Hi,

 I wrote a little script for editing WFS-Data - basically I just used the
 workshop from opengeo:
 http://workshops.opengeo.org/geoext/wfs/editing.html

 So yes, I am using GeoExt, and this is how the datastore looks like:

 {{{
 var layer = new OpenLayers.Layer.Vector("vector", {
                         strategies: [new OpenLayers.Strategy.Fixed(),
 saveStrategy],
                         protocol: new OpenLayers.Protocol.WFS({
                                      url:  wfsUrl,
                                       featureType: "someLayer",
                                       featureNS: "http://somenamespace",
                                       srsName: "EPSG:900913",
                                       version: "1.1.0",
                                       geometryName: "geom"
                         })
                 });
 }}}
 ...


 {{{
 var store = new GeoExt.data.FeatureStore({
                         fields: [
                                 {name: "type", type: "int", defaultValue:
 0},
                                 {name: "cost", type: "double",
 defaultValue: 0.00},
                                 {name: "text", type: "string",
 defaultValue: ' '},
                                 {name: "hierarchy", type: "int",
 defaultValue: 0}
                         ],
                         layer: layer,
                         addFeatureFilter: function(feature) {
                                 return feature.state !==
 OpenLayers.State.DELETE;
                         }
                 });
 }}}


 Now, this is working just fine with the split-control:

 {{{
             // configure split agent
             split = new OpenLayers.Control.Split({
                 layer: layer,
                 source: layer,
                 tolerance: 0.0001,
                 deferDelete: true,
                 eventListeners: {
                     aftersplit: function(event) {
                         flashFeatures(layer,event.features);
                         // we should refresh the grid

                     }
                 }
             });
             map.addControl(split);
             split.activate();
 }}}

 But: I am also using an Ext.grid.EditorGridPanel (from extjs 3.4), which
 basically uses the store I just created as the input data.
 [[BR]]
 Now, with "deferDelete: true" I can make sure, that features that are
 deleted/splitted will be updated/deleted on the WFS properly, but my
 EditorGridPanel does not get any updates.
 [[BR]]
 And here is why:[[BR]]
 openlayers/lib/OpenLayers/Control/Split.js[[BR]]
 or[[BR]]
 tags/openlayers/release-2.10/lib/OpenLayers/Control/Split.js[[BR]]
 Line 445:


 {{{
                             this.layer.destroyFeatures(destroys, {silent:
 true});
                             for(var i=0, len=additions.length; i<len; ++i)
 {
                                 additions[i].state =
 OpenLayers.State.INSERT;
                             }
                         } else {
                             this.layer.destroyFeatures(removals, {silent:
 true});
                         }
                         this.layer.addFeatures(additions, {silent: true});
 }}}


 The parameter silent: true is set when using destroyFeatures and
 addFeatures. This parameter forces the above methods to NOT fire any
 events, which causes external views, like a DataGrid, to be out of sync,
 which causes errors.

 I suggest adding another parameter to the Split Control, e.g.
 keepSynchronized (default: false - don't change the default behaviour,
 right?), and change the code to:
 {{{
     /**
      * APIProperty: keepSynchronized
      * {Boolean} Instead of adding and removing features silently (silent:
 true),
      * add or remove them non silently (silent: false)
      */
     keepSynchronized: false,

 }}}
 ...

 {{{
                             this.layer.destroyFeatures(destroys, {silent:
 !this.keepSynchronized});
                             for(var i=0, len=additions.length; i<len; ++i)
 {
                                 additions[i].state =
 OpenLayers.State.INSERT;
                             }
                         } else {
                             this.layer.destroyFeatures(removals, {silent:
 !this.keepSynchronized});
                         }
                         this.layer.addFeatures(additions, {silent:
 !this.keepSynchronized});
 }}}

 I tested this and it worked for my example. Would be nice if it could get
 included in the 2.11 release too!
 I hope this will also help someone else having similar problems.

-- 
Ticket URL: <http://trac.openlayers.org/ticket/3472>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer


More information about the Trac mailing list