Adding support for writing wfs:Query with limited property names. Patch from bartvde, tests and mods from me. r=me,ahocevar. (closes #1827)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8928 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -108,6 +108,15 @@ OpenLayers.Format.WFST.v1_0_0 = OpenLayers.Class(
|
|||||||
if(options.featureNS) {
|
if(options.featureNS) {
|
||||||
node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS);
|
node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS);
|
||||||
}
|
}
|
||||||
|
if(options.propertyNames) {
|
||||||
|
for(var i=0,len = options.propertyNames.length; i<len; i++) {
|
||||||
|
this.writeNode(
|
||||||
|
"ogc:PropertyName",
|
||||||
|
{property: options.propertyNames[i]},
|
||||||
|
node
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(options.filter) {
|
if(options.filter) {
|
||||||
this.setFilterProperty(options.filter);
|
this.setFilterProperty(options.filter);
|
||||||
this.writeNode("ogc:Filter", options.filter, node);
|
this.writeNode("ogc:Filter", options.filter, node);
|
||||||
|
|||||||
@@ -107,11 +107,25 @@ OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class(
|
|||||||
if(options.featureNS) {
|
if(options.featureNS) {
|
||||||
node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS);
|
node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS);
|
||||||
}
|
}
|
||||||
|
if(options.propertyNames) {
|
||||||
|
for(var i=0,len = options.propertyNames.length; i<len; i++) {
|
||||||
|
this.writeNode(
|
||||||
|
"wfs:PropertyName",
|
||||||
|
{property: options.propertyNames[i]},
|
||||||
|
node
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(options.filter) {
|
if(options.filter) {
|
||||||
this.setFilterProperty(options.filter);
|
this.setFilterProperty(options.filter);
|
||||||
this.writeNode("ogc:Filter", options.filter, node);
|
this.writeNode("ogc:Filter", options.filter, node);
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
|
},
|
||||||
|
"PropertyName": function(obj) {
|
||||||
|
return this.createElementNSPlus("wfs:PropertyName", {
|
||||||
|
value: obj.property
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, OpenLayers.Format.WFST.v1.prototype.writers["wfs"]),
|
}, OpenLayers.Format.WFST.v1.prototype.writers["wfs"]),
|
||||||
"gml": OpenLayers.Format.GML.v3.prototype.writers["gml"],
|
"gml": OpenLayers.Format.GML.v3.prototype.writers["gml"],
|
||||||
|
|||||||
@@ -32,33 +32,44 @@
|
|||||||
geometryName: "the_geom"
|
geometryName: "the_geom"
|
||||||
});
|
});
|
||||||
|
|
||||||
t.plan(1);
|
var cases = [{
|
||||||
var snippets = {
|
id: "query0",
|
||||||
"Query": {
|
writer: "wfs:Query",
|
||||||
|
arg: {
|
||||||
filter: new OpenLayers.Filter.Spatial({
|
filter: new OpenLayers.Filter.Spatial({
|
||||||
type: OpenLayers.Filter.Spatial.BBOX,
|
type: OpenLayers.Filter.Spatial.BBOX,
|
||||||
value: new OpenLayers.Bounds (1,2,3,4)
|
value: new OpenLayers.Bounds (1,2,3,4)
|
||||||
})}
|
})
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
id: "getfeature0",
|
||||||
|
writer: "wfs:GetFeature",
|
||||||
|
arg: {
|
||||||
|
propertyNames: ["STATE_NAME", "STATE_FIPS", "STATE_ABBR"]
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
t.plan(cases.length);
|
||||||
|
|
||||||
|
var test, got, exp;
|
||||||
|
for(var i=0; i<cases.length; ++i) {
|
||||||
|
test = cases[i];
|
||||||
|
exp = readXML(test.id);
|
||||||
|
got = format.writeNode(test.writer, test.arg);
|
||||||
|
t.xml_eq(got, exp, test.id + ": correct request");
|
||||||
}
|
}
|
||||||
|
|
||||||
var arg;
|
|
||||||
for(var snippet in snippets) {
|
|
||||||
arg = snippets[snippet]
|
|
||||||
var expected = readXML(snippet);
|
|
||||||
var got = format.writers["wfs"][snippet].apply(format, [arg]);
|
|
||||||
t.xml_eq(got, expected, snippet + " request created correctly");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var xmlFormat = new OpenLayers.Format.XML();
|
||||||
function readXML(id) {
|
function readXML(id) {
|
||||||
var xml = document.getElementById(id).firstChild.nodeValue;
|
var xml = document.getElementById(id).firstChild.nodeValue;
|
||||||
return new OpenLayers.Format.XML().read(xml).documentElement;
|
return xmlFormat.read(xml).documentElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="map" style="width:512px; height:256px"> </div>
|
|
||||||
<div id="Transaction_Response"><!--
|
<div id="Transaction_Response"><!--
|
||||||
<wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc">
|
<wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc">
|
||||||
<wfs:InsertResult>
|
<wfs:InsertResult>
|
||||||
@@ -71,7 +82,7 @@
|
|||||||
</wfs:TransactionResult>
|
</wfs:TransactionResult>
|
||||||
</wfs:WFS_TransactionResponse>
|
</wfs:WFS_TransactionResponse>
|
||||||
--></div>
|
--></div>
|
||||||
<div id="Query"><!--
|
<div id="query0"><!--
|
||||||
<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
|
<wfs:Query 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:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||||
<ogc:BBOX>
|
<ogc:BBOX>
|
||||||
@@ -83,5 +94,18 @@
|
|||||||
</ogc:Filter>
|
</ogc:Filter>
|
||||||
</wfs:Query>
|
</wfs:Query>
|
||||||
--></div>
|
--></div>
|
||||||
|
<div id="getfeature0"><!--
|
||||||
|
<wfs:GetFeature service="WFS" version="1.0.0" xmlns:topp="http://www.openplans.org/topp"
|
||||||
|
xmlns:wfs="http://www.opengis.net/wfs"
|
||||||
|
xmlns:ogc="http://www.opengis.net/ogc"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd">
|
||||||
|
<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
|
||||||
|
<ogc:PropertyName>STATE_NAME</ogc:PropertyName>
|
||||||
|
<ogc:PropertyName>STATE_FIPS</ogc:PropertyName>
|
||||||
|
<ogc:PropertyName>STATE_ABBR</ogc:PropertyName>
|
||||||
|
</wfs:Query>
|
||||||
|
</wfs:GetFeature>
|
||||||
|
--></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -32,27 +32,38 @@
|
|||||||
geometryName: "the_geom"
|
geometryName: "the_geom"
|
||||||
});
|
});
|
||||||
|
|
||||||
t.plan(1);
|
var cases = [{
|
||||||
var snippets = {
|
id: "query0",
|
||||||
"Query": {
|
writer: "wfs:Query",
|
||||||
|
arg: {
|
||||||
filter: new OpenLayers.Filter.Spatial({
|
filter: new OpenLayers.Filter.Spatial({
|
||||||
type: OpenLayers.Filter.Spatial.BBOX,
|
type: OpenLayers.Filter.Spatial.BBOX,
|
||||||
value: new OpenLayers.Bounds (1,2,3,4)
|
value: new OpenLayers.Bounds (1,2,3,4)
|
||||||
})}
|
})
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
id: "getfeature0",
|
||||||
|
writer: "wfs:GetFeature",
|
||||||
|
arg: {
|
||||||
|
propertyNames: ["STATE_NAME", "STATE_FIPS", "STATE_ABBR"]
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
var arg;
|
t.plan(cases.length);
|
||||||
for(var snippet in snippets) {
|
|
||||||
arg = snippets[snippet]
|
var test, got, exp;
|
||||||
var expected = readXML(snippet);
|
for(var i=0; i<cases.length; ++i) {
|
||||||
var got = format.writers["wfs"][snippet].apply(format, [arg]);
|
test = cases[i];
|
||||||
t.xml_eq(got, expected, snippet + " request created correctly");
|
exp = readXML(test.id);
|
||||||
|
got = format.writeNode(test.writer, test.arg);
|
||||||
|
t.xml_eq(got, exp, test.id + ": correct request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var xmlFormat = new OpenLayers.Format.XML();
|
||||||
function readXML(id) {
|
function readXML(id) {
|
||||||
var xml = document.getElementById(id).firstChild.nodeValue;
|
var xml = document.getElementById(id).firstChild.nodeValue;
|
||||||
return new OpenLayers.Format.XML().read(xml).documentElement;
|
return xmlFormat.read(xml).documentElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -74,7 +85,7 @@
|
|||||||
</wfs:InsertResults>
|
</wfs:InsertResults>
|
||||||
</wfs:TransactionResponse>
|
</wfs:TransactionResponse>
|
||||||
--></div>
|
--></div>
|
||||||
<div id="Query"><!--
|
<div id="query0"><!--
|
||||||
<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
|
<wfs:Query 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:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||||
<ogc:BBOX>
|
<ogc:BBOX>
|
||||||
@@ -87,5 +98,18 @@
|
|||||||
</ogc:Filter>
|
</ogc:Filter>
|
||||||
</wfs:Query>
|
</wfs:Query>
|
||||||
--></div>
|
--></div>
|
||||||
|
<div id="getfeature0"><!--
|
||||||
|
<wfs:GetFeature service="WFS" version="1.1.0" xmlns:topp="http://www.openplans.org/topp"
|
||||||
|
xmlns:wfs="http://www.opengis.net/wfs"
|
||||||
|
xmlns:ogc="http://www.opengis.net/ogc"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
|
||||||
|
<wfs:Query xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
|
||||||
|
<wfs:PropertyName>STATE_NAME</wfs:PropertyName>
|
||||||
|
<wfs:PropertyName>STATE_FIPS</wfs:PropertyName>
|
||||||
|
<wfs:PropertyName>STATE_ABBR</wfs:PropertyName>
|
||||||
|
</wfs:Query>
|
||||||
|
</wfs:GetFeature>
|
||||||
|
--></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user