adding a feature.modified property, making the ModifyFeature control set it and the WFST format check for it so only modified attributes and a modified geometry need to be included in an Update transaction. r=bartvde (closes #3400)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@12149 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-07-04 08:37:55 +00:00
parent 3f2bd6ddc2
commit 2293987d57
5 changed files with 140 additions and 6 deletions
+12
View File
@@ -368,6 +368,11 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
this.dragControl.activate();
this.onModificationStart(this.feature);
}
// keep track of geometry modifications
var modified = feature.modified;
if (feature.geometry && !(modified && modified.geometry)) {
this._originalGeometry = feature.geometry.clone();
}
},
/**
@@ -539,6 +544,13 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
if(this.feature.state != OpenLayers.State.INSERT &&
this.feature.state != OpenLayers.State.DELETE) {
this.feature.state = OpenLayers.State.UPDATE;
if (this.modified && this._originalGeometry) {
var feature = this.feature;
feature.modified = OpenLayers.Util.extend(feature.modified, {
geometry: this._originalGeometry
});
delete this._originalGeometry;
}
}
},
+36
View File
@@ -81,6 +81,42 @@ OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, {
* {String} rendering intent currently being used
*/
renderIntent: "default",
/**
* APIProperty: modified
* {Object} An object with the originals of the geometry and attributes of
* the feature, if they were changed. Currently this property is only read
* by <OpenLayers.Format.WFST.v1>, and written by
* <OpenLayers.Control.ModifyFeature>, which sets the geometry property.
* Applications can set the originals of modified attributes in the
* attributes property. Note that applications have to check if this
* object and the attributes property is already created before using it.
* After a change made with ModifyFeature, this object could look like
*
* (code)
* {
* geometry: >Object
* }
* (end)
*
* When an application has made changes to feature attributes, it could
* have set the attributes to something like this:
*
* (code)
* {
* attributes: {
* myAttribute: "original"
* }
* }
* (end)
*
* Note that <OpenLayers.Format.WFST.v1> only checks for truthy values in
* *modified.geometry* and the attribute names in *modified.attributes*,
* but it is recommended to set the original values (and not just true) as
* attribute value, so applications could use this information to undo
* changes.
*/
modified: null,
/**
* Constructor: OpenLayers.Feature.Vector
+21 -3
View File
@@ -172,9 +172,24 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
* type - insert, update, or delete.
*
* Parameters:
* features - {Array(<OpenLayers.Feature.Vector>)} A list of features.
* features - {Array(<OpenLayers.Feature.Vector>)} A list of features. See
* below for a more detailed description of the influence of the
* feature's *modified* property.
* options - {Object}
*
* feature.modified rules:
* If a feature has a modified property set, the following checks will be
* made before a feature's geometry or attribute is included in an Update
* transaction:
* - *modified* is not set at all: The geometry and all attributes will be
* included.
* - *modified.geometry* is truthy: The geometry will be
* included. If *modified.attributes* is not set, all attributes will
* be included.
* - *modified.attributes* is set: Only the attributes with a truthy value
* in *modified.attributes* will be included. If *modified.geometry*
* is not set, the geometry will not be included.
*
* Returns:
* {String} A serialized WFS transaction.
*/
@@ -276,7 +291,8 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
}
// add in geometry
if (this.geometryName !== null) {
var modified = feature.modified;
if (this.geometryName !== null && (!modified || modified.geometry)) {
this.srsName = this.getSrsName(feature);
this.writeNode(
"Property", {name: this.geometryName, value: feature.geometry}, node
@@ -285,7 +301,9 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
// add in attributes
for(var key in feature.attributes) {
if(feature.attributes[key] !== undefined) {
if(feature.attributes[key] !== undefined &&
(!modified || !modified.attributes ||
(modified.attributes && modified.attributes[key]))) {
this.writeNode(
"Property", {name: key, value: feature.attributes[key]}, node
);