write out GetFeature in WFS 1.1

This commit is contained in:
Bart van den Eijnden
2013-10-23 14:54:21 +02:00
parent 4df848fae0
commit a77632a88c
5 changed files with 62 additions and 17 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ ol.parser.ogc.WFS_v1 = function() {
this.setAttributeNS( this.setAttributeNS(
node, 'http://www.w3.org/2001/XMLSchema-instance', node, 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation', this.schemaLocation); 'xsi:schemaLocation', this.schemaLocation);
return node; return {node: node, options: options};
} }
}; };
goog.base(this); goog.base(this);
+7
View File
@@ -1,6 +1,7 @@
goog.provide('ol.parser.ogc.WFS_v1_0_0'); goog.provide('ol.parser.ogc.WFS_v1_0_0');
goog.require('goog.array'); goog.require('goog.array');
goog.require('goog.functions');
goog.require('goog.object'); goog.require('goog.object');
goog.require('ol.parser.ogc.Filter_v1_0_0'); goog.require('ol.parser.ogc.Filter_v1_0_0');
goog.require('ol.parser.ogc.WFS_v1'); goog.require('ol.parser.ogc.WFS_v1');
@@ -40,6 +41,12 @@ ol.parser.ogc.WFS_v1_0_0 = function() {
} }
}); });
goog.object.extend(this.writers[this.defaultNamespaceURI], { goog.object.extend(this.writers[this.defaultNamespaceURI], {
'GetFeature': goog.functions.compose(
function(obj) {
return obj.node;
},
this.writers['http://www.opengis.net/wfs']['GetFeature']
),
'Query': function(options) { 'Query': function(options) {
var prefix = goog.isDef(options.featurePrefix) ? options.featurePrefix + var prefix = goog.isDef(options.featurePrefix) ? options.featurePrefix +
':' : ''; ':' : '';
+22 -16
View File
@@ -1,7 +1,9 @@
goog.provide('ol.parser.ogc.WFS_v1_1_0'); goog.provide('ol.parser.ogc.WFS_v1_1_0');
goog.require('goog.asserts');
goog.require('goog.functions'); goog.require('goog.functions');
goog.require('goog.object'); goog.require('goog.object');
goog.require('ol.expr.Identifier');
goog.require('ol.parser.ogc.Filter_v1_1_0'); goog.require('ol.parser.ogc.Filter_v1_1_0');
goog.require('ol.parser.ogc.WFS_v1'); goog.require('ol.parser.ogc.WFS_v1');
@@ -47,18 +49,23 @@ ol.parser.ogc.WFS_v1_1_0 = function() {
} }
}); });
goog.object.extend(this.writers[this.defaultNamespaceURI], { goog.object.extend(this.writers[this.defaultNamespaceURI], {
'GetFeature': function(options) { 'GetFeature': goog.functions.compose(
var node = this.writers['http://www.opengis.net/wfs']['GetFeature']. function(obj) {
apply(this, arguments); var options = obj.options;
if (goog.isDef(options)) { var node = obj.node;
node.setAttribute('resultType', options.resultType); if (goog.isDef(options)) {
if (goog.isDef(options.startIndex)) { node.setAttribute('resultType', options.resultType);
node.setAttribute('startIndex', options.startIndex); if (goog.isDef(options.startIndex)) {
} node.setAttribute('startIndex', options.startIndex);
node.setAttribute('count', options.count); }
} if (goog.isDef(options.count)) {
return node; node.setAttribute('count', options.count);
}, }
}
return node;
},
this.writers['http://www.opengis.net/wfs']['GetFeature']
),
'Query': function(options) { 'Query': function(options) {
var prefix = goog.isDef(options.featurePrefix) ? options.featurePrefix + var prefix = goog.isDef(options.featurePrefix) ? options.featurePrefix +
':' : ''; ':' : '';
@@ -70,9 +77,7 @@ ol.parser.ogc.WFS_v1_1_0 = function() {
} }
if (goog.isDef(options.propertyNames)) { if (goog.isDef(options.propertyNames)) {
for (var i = 0, ii = options.propertyNames.length; i < ii; i++) { for (var i = 0, ii = options.propertyNames.length; i < ii; i++) {
this.writeNode('wfs:PropertyName', { this.writeNode('PropertyName', options.propertyNames[i], null, node);
property: options.propertyNames[i]
}, null, node);
} }
} }
if (goog.isDef(options.filter)) { if (goog.isDef(options.filter)) {
@@ -82,8 +87,9 @@ ol.parser.ogc.WFS_v1_1_0 = function() {
return node; return node;
}, },
'PropertyName': function(obj) { 'PropertyName': function(obj) {
goog.asserts.assertInstanceof(obj, ol.expr.Identifier);
var node = this.createElementNS('wfs:PropertyName'); var node = this.createElementNS('wfs:PropertyName');
node.appendChild(this.createTextNode(obj.property)); node.appendChild(this.createTextNode(obj.getName()));
return node; return node;
} }
}); });
@@ -68,6 +68,27 @@ describe('ol.parser.ogc.WFS_v1_1_0', function() {
expect(goog.dom.xml.loadXml(p.serialize(output))).to.xmleql(xml); expect(goog.dom.xml.loadXml(p.serialize(output))).to.xmleql(xml);
done(); done();
}); });
});
it('handles writing GetFeature with PropertyName', function(done) {
var url = 'spec/ol/parser/ogc/xml/wfs_v1_1_0/getfeature0.xml';
afterLoadXml(url, function(xml) {
var p = new ol.parser.ogc.WFS_v1_1_0();
var output = p.writers[p.defaultNamespaceURI]['GetFeature'].apply(
p, [{
resultType: 'hits',
srsName: 'urn:ogc:def:crs:EPSG::4326',
propertyNames: [new ol.expr.Identifier('STATE_NAME'),
new ol.expr.Identifier('STATE_FIPS'),
new ol.expr.Identifier('STATE_ABBR')],
featureNS: 'http://www.openplans.org/topp',
featurePrefix: 'topp',
featureTypes: ['states']
}]);
expect(goog.dom.xml.loadXml(p.serialize(output))).to.xmleql(xml);
done();
});
}); });
}); });
@@ -0,0 +1,11 @@
<wfs:GetFeature service="WFS" version="1.1.0" resultType="hits" 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" srsName="urn:ogc:def:crs:EPSG::4326" 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>