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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -175,6 +175,41 @@
|
||||
}
|
||||
}
|
||||
|
||||
function test_write_multi(t) {
|
||||
t.plan(1);
|
||||
var format = new OpenLayers.Format.WFST({
|
||||
featureNS: "http://www.openplans.org/topp",
|
||||
featureType: "states",
|
||||
featurePrefix: "topp",
|
||||
geometryName: "the_geom"
|
||||
});
|
||||
|
||||
var feature = new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Point(1,2),
|
||||
{foo: "bar"}
|
||||
);
|
||||
|
||||
var insertFeature = feature.clone();
|
||||
// null value does not show up in insert
|
||||
insertFeature.attributes.nul = null;
|
||||
insertFeature.state = OpenLayers.State.INSERT;
|
||||
var updateFeature = feature.clone();
|
||||
// undefined value means don't create a Property element
|
||||
updateFeature.attributes.unwritten = undefined;
|
||||
// null value gets Property element with no Value
|
||||
updateFeature.attributes.nul = null;
|
||||
updateFeature.fid = "fid.42";
|
||||
updateFeature.state = OpenLayers.State.UPDATE;
|
||||
var features = [insertFeature, updateFeature];
|
||||
|
||||
var expected = readXML("TransactionMulti");
|
||||
var got = format.writers["wfs"]["Transaction"].apply(format, [{
|
||||
features: features,
|
||||
options: {multi: true}}
|
||||
]);
|
||||
t.xml_eq(got, expected, "Transaction request with multi option created correctly");
|
||||
}
|
||||
|
||||
function readXML(id) {
|
||||
var xml = document.getElementById(id).firstChild.nodeValue;
|
||||
return new OpenLayers.Format.XML().read(xml).documentElement;
|
||||
@@ -243,6 +278,48 @@
|
||||
<div id="Transaction"><!--
|
||||
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0"/>
|
||||
--></div>
|
||||
<div id="TransactionMulti"><!--
|
||||
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0">
|
||||
<wfs:Insert>
|
||||
<feature:states xmlns:feature="http://www.openplans.org/topp">
|
||||
<feature:the_geom>
|
||||
<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
</gml:MultiPoint>
|
||||
</feature:the_geom>
|
||||
<feature:foo>bar</feature:foo>
|
||||
</feature:states>
|
||||
</wfs:Insert>
|
||||
<wfs:Update xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
|
||||
<wfs:Property>
|
||||
<wfs:Name>the_geom</wfs:Name>
|
||||
<wfs:Value>
|
||||
<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
</gml:MultiPoint>
|
||||
</wfs:Value>
|
||||
</wfs:Property>
|
||||
<wfs:Property>
|
||||
<wfs:Name>foo</wfs:Name>
|
||||
<wfs:Value>bar</wfs:Value>
|
||||
</wfs:Property>
|
||||
<wfs:Property>
|
||||
<wfs:Name>nul</wfs:Name>
|
||||
</wfs:Property>
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:FeatureId fid="fid.42"/>
|
||||
</ogc:Filter>
|
||||
</wfs:Update>
|
||||
</wfs:Transaction>
|
||||
--></div>
|
||||
<div id="Insert"><!--
|
||||
<wfs:Insert xmlns:wfs="http://www.opengis.net/wfs">
|
||||
<feature:states xmlns:feature="http://www.openplans.org/topp">
|
||||
|
||||
Reference in New Issue
Block a user