giving the WFST format a multi option, which makes sure that Multi geometries are written in transactions. r=bartvde (closes #3407)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@12168 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-07-13 13:48:31 +00:00
parent c0326c66bd
commit b5ba9db904
3 changed files with 97 additions and 1 deletions

View File

@@ -190,6 +190,10 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
* in *modified.attributes* will be included. If *modified.geometry*
* is not set, the geometry will not be included.
*
* Valid options include:
* - *multi* {Boolean} If set to true, geometries will be casted to
* Multi geometries before writing.
*
* Returns:
* {String} A serialized WFS transaction.
*/
@@ -246,11 +250,23 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
var features = obj && obj.features;
var options = obj && obj.options;
if(features) {
var name, feature;
var name, feature, geometry;
for(i=0, len=features.length; i<len; ++i) {
feature = features[i];
name = this.stateName[feature.state];
if(name) {
geometry = feature.geometry;
if (options && options.multi === true && geometry) {
var type = geometry.CLASS_NAME.split(".").pop();
if (type.indexOf("Multi") != 0) {
var Cls = OpenLayers.Geometry["Multi" + type];
if (Cls) {
feature = OpenLayers.Util.applyDefaults({
geometry: new Cls([geometry])
}, feature);
}
}
}
this.writeNode(name, feature, node);
}
}

View File

@@ -105,6 +105,9 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
* geometryName - {String} Name of geometry attribute. If featureNS is not
* configured, the default is null to avoid failing on BBOX filters,
* and it will be set on <read>. Otherwise, the default is 'the_geom'.
* multi - {Boolean} If set to true, geometries will be casted to Multi
* geometries before they are written in a transaction. No casting will
* be done when reading features.
*/
initialize: function(options) {
OpenLayers.Protocol.prototype.initialize.apply(this, [options]);