fix for WFS-T delete and update have improper typeName. Includes tests.
Vague +1 from tschaub. WFS format now matches the more modern WFS-T v1 format as confirmed by cargo culting the WFS-T tests. (Closes #1787, #1471) git-svn-id: http://svn.openlayers.org/trunk/openlayers@8978 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -135,7 +135,8 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
|
|||||||
update: function(feature) {
|
update: function(feature) {
|
||||||
if (!feature.fid) { OpenLayers.Console.userError(OpenLayers.i18n("noFID")); }
|
if (!feature.fid) { OpenLayers.Console.userError(OpenLayers.i18n("noFID")); }
|
||||||
var updateNode = this.createElementNS(this.wfsns, 'wfs:Update');
|
var updateNode = this.createElementNS(this.wfsns, 'wfs:Update');
|
||||||
updateNode.setAttribute("typeName", this.layerName);
|
updateNode.setAttribute("typeName", this.featurePrefix + ':' + this.featureName);
|
||||||
|
updateNode.setAttribute("xmlns:" + this.featurePrefix, this.featureNS);
|
||||||
|
|
||||||
var propertyNode = this.createElementNS(this.wfsns, 'wfs:Property');
|
var propertyNode = this.createElementNS(this.wfsns, 'wfs:Property');
|
||||||
var nameNode = this.createElementNS(this.wfsns, 'wfs:Name');
|
var nameNode = this.createElementNS(this.wfsns, 'wfs:Name');
|
||||||
@@ -194,7 +195,8 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var deleteNode = this.createElementNS(this.wfsns, 'wfs:Delete');
|
var deleteNode = this.createElementNS(this.wfsns, 'wfs:Delete');
|
||||||
deleteNode.setAttribute("typeName", this.layerName);
|
deleteNode.setAttribute("typeName", this.featurePrefix + ':' + this.featureName);
|
||||||
|
deleteNode.setAttribute("xmlns:" + this.featurePrefix, this.featureNS);
|
||||||
|
|
||||||
var filterNode = this.createElementNS(this.ogcns, 'ogc:Filter');
|
var filterNode = this.createElementNS(this.ogcns, 'ogc:Filter');
|
||||||
var filterIdNode = this.createElementNS(this.ogcns, 'ogc:FeatureId');
|
var filterIdNode = this.createElementNS(this.ogcns, 'ogc:FeatureId');
|
||||||
|
|||||||
81
tests/Format/WFS.html
Normal file
81
tests/Format/WFS.html
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="../../lib/OpenLayers.js"></script>
|
||||||
|
<script>
|
||||||
|
function test_wfs_update_node(t) {
|
||||||
|
t.plan(2);
|
||||||
|
var expected = readXML("Update");
|
||||||
|
var updateFeature = new OpenLayers.Feature.Vector(
|
||||||
|
new OpenLayers.Geometry.Point(1,2),
|
||||||
|
{foo: "bar"});
|
||||||
|
updateFeature.fid = "fid.42";
|
||||||
|
updateFeature.state = OpenLayers.State.UPDATE;
|
||||||
|
var format = new OpenLayers.Format.WFS({
|
||||||
|
'featureNS':'http://www.openplans.org/topp',
|
||||||
|
'featureName': 'states',
|
||||||
|
'geometryName': 'the_geom',
|
||||||
|
'featurePrefix': 'topp'
|
||||||
|
}, {options:{}});
|
||||||
|
var updateNode = format.update(updateFeature);
|
||||||
|
t.xml_eq(updateNode, expected, "update node matches expected XML value.");
|
||||||
|
var format = new OpenLayers.Format.WFS({
|
||||||
|
'featurePrefix': 'topp'
|
||||||
|
}, {options:{typename: 'states', 'featureNS': 'http://www.openplans.org/topp', 'geometry_column': 'the_geom' }});
|
||||||
|
var updateNode = format.update(updateFeature);
|
||||||
|
t.xml_eq(updateNode, expected, "update node matches expected XML value.");
|
||||||
|
}
|
||||||
|
function test_wfs_delete_node(t) {
|
||||||
|
t.plan(2);
|
||||||
|
var expected = readXML("Delete");
|
||||||
|
var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0,0));
|
||||||
|
feature.state = OpenLayers.State.DELETE;
|
||||||
|
feature.fid = "fid.37";
|
||||||
|
var format = new OpenLayers.Format.WFS({
|
||||||
|
'featureNS':'http://www.openplans.org/topp',
|
||||||
|
'featureName': 'states',
|
||||||
|
'featurePrefix': 'topp'
|
||||||
|
}, {options:{}});
|
||||||
|
var deleteNode = format.remove(feature);
|
||||||
|
t.xml_eq(deleteNode, expected, "delete node matches expected XML value.");
|
||||||
|
var format = new OpenLayers.Format.WFS({
|
||||||
|
'featurePrefix': 'topp'
|
||||||
|
}, {options:{typename: 'states', 'featureNS': 'http://www.openplans.org/topp'}});
|
||||||
|
var deleteNode = format.remove(feature);
|
||||||
|
t.xml_eq(deleteNode, expected, "delete node matches expected XML value.");
|
||||||
|
}
|
||||||
|
function readXML(id) {
|
||||||
|
var xml = document.getElementById(id).firstChild.nodeValue;
|
||||||
|
return new OpenLayers.Format.XML().read(xml).documentElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="Update"><!--
|
||||||
|
<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:Point xmlns:gml="http://www.opengis.net/gml">
|
||||||
|
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||||
|
</gml:Point>
|
||||||
|
</wfs:Value>
|
||||||
|
</wfs:Property>
|
||||||
|
<wfs:Property>
|
||||||
|
<wfs:Name>foo</wfs:Name>
|
||||||
|
<wfs:Value>bar</wfs:Value>
|
||||||
|
</wfs:Property>
|
||||||
|
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||||
|
<ogc:FeatureId fid="fid.42"/>
|
||||||
|
</ogc:Filter>
|
||||||
|
</wfs:Update>
|
||||||
|
--></div>
|
||||||
|
<div id="Delete"><!--
|
||||||
|
<wfs:Delete xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
|
||||||
|
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||||
|
<ogc:FeatureId fid="fid.37"/>
|
||||||
|
</ogc:Filter>
|
||||||
|
</wfs:Delete>
|
||||||
|
--></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -57,6 +57,7 @@
|
|||||||
<li>Format/Filter/v1_0_0.html</li>
|
<li>Format/Filter/v1_0_0.html</li>
|
||||||
<li>Format/Filter/v1_1_0.html</li>
|
<li>Format/Filter/v1_1_0.html</li>
|
||||||
<li>Format/WFSDescribeFeatureType.html</li>
|
<li>Format/WFSDescribeFeatureType.html</li>
|
||||||
|
<li>Format/WFS.html</li>
|
||||||
<li>Format/WFST.html</li>
|
<li>Format/WFST.html</li>
|
||||||
<li>Format/WFST/v1.html</li>
|
<li>Format/WFST/v1.html</li>
|
||||||
<li>Format/WFST/v1_0_0.html</li>
|
<li>Format/WFST/v1_0_0.html</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user