diff --git a/src/ol/parser/ogc/filterparser_v1.js b/src/ol/parser/ogc/filterparser_v1.js index f0a21995ab..38bd33d2c4 100644 --- a/src/ol/parser/ogc/filterparser_v1.js +++ b/src/ol/parser/ogc/filterparser_v1.js @@ -580,6 +580,14 @@ ol.parser.ogc.Filter_v1.prototype.aggregateLogical_ = function(filters, }; +/** + * @return {ol.parser.ogc.GML_v2|ol.parser.ogc.GML_v3} + */ +ol.parser.ogc.Filter_v1.prototype.getGmlParser = function() { + return this.gml_; +}; + + /** * @param {ol.parser.ogc.GML_v2|ol.parser.ogc.GML_v3} gml The GML parser to * use. diff --git a/src/ol/parser/ogc/wfsparser.js b/src/ol/parser/ogc/wfsparser.js index 68e3141326..33625798bd 100644 --- a/src/ol/parser/ogc/wfsparser.js +++ b/src/ol/parser/ogc/wfsparser.js @@ -19,8 +19,7 @@ ol.ENABLE_WFS_1_1_0 = true; /** * @constructor - * @param {ol.parser.WFSOptions=} opt_options - * Optional configuration object. + * @param {Object=} opt_options Options which will be set on this object. * @extends {ol.parser.ogc.Versioned} */ ol.parser.ogc.WFS = function(opt_options) { diff --git a/src/ol/parser/ogc/wfsparser_v1.js b/src/ol/parser/ogc/wfsparser_v1.js index 531287c5ab..73b12f4ff3 100644 --- a/src/ol/parser/ogc/wfsparser_v1.js +++ b/src/ol/parser/ogc/wfsparser_v1.js @@ -6,16 +6,9 @@ goog.require('ol.parser.XML'); /** * @constructor - * @param {ol.parser.WFSOptions=} opt_options - * Optional configuration object. * @extends {ol.parser.XML} */ -ol.parser.ogc.WFS_v1 = function(opt_options) { - if (goog.isDef(opt_options)) { - this.featureTypes = opt_options.featureTypes; - this.featurePrefix = opt_options.featurePrefix; - this.featureNS = opt_options.featureNS; - } +ol.parser.ogc.WFS_v1 = function() { this.defaultNamespaceURI = 'http://www.opengis.net/wfs'; // TODO set errorProperty this.readers = {}; @@ -42,8 +35,8 @@ ol.parser.ogc.WFS_v1 = function(opt_options) { node.setAttribute('maxFeatures', options.maxFeatures); } } - for (var i = 0, ii = this.featureTypes.length; i < ii; i++) { - options.featureType = this.featureTypes[i]; + for (var i = 0, ii = options.featureTypes.length; i < ii; i++) { + options.featureType = options.featureTypes[i]; this.writeNode('Query', options, null, node); } this.setAttributeNS( @@ -57,6 +50,14 @@ ol.parser.ogc.WFS_v1 = function(opt_options) { goog.inherits(ol.parser.ogc.WFS_v1, ol.parser.XML); +/** + * @return {ol.parser.ogc.Filter_v1_0_0|ol.parser.ogc.Filter_v1_1_0} + */ +ol.parser.ogc.WFS_v1.prototype.getFilterParser = function() { + return this.filter_; +}; + + /** * @param {ol.parser.ogc.Filter_v1_0_0|ol.parser.ogc.Filter_v1_1_0} filter The * Filter parser to use. diff --git a/src/ol/parser/ogc/wfsparser_v1_0_0.js b/src/ol/parser/ogc/wfsparser_v1_0_0.js index df2e93f691..1fc20a5bb4 100644 --- a/src/ol/parser/ogc/wfsparser_v1_0_0.js +++ b/src/ol/parser/ogc/wfsparser_v1_0_0.js @@ -9,12 +9,10 @@ goog.require('ol.parser.ogc.WFS_v1'); /** * @constructor - * @param {ol.parser.WFSOptions=} opt_options - * Optional configuration object. * @extends {ol.parser.ogc.WFS_v1} */ -ol.parser.ogc.WFS_v1_0_0 = function(opt_options) { - goog.base(this, opt_options); +ol.parser.ogc.WFS_v1_0_0 = function() { + goog.base(this); this.version = '1.0.0'; this.schemaLocation = this.defaultNamespaceURI + ' ' + 'http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd'; @@ -43,23 +41,15 @@ ol.parser.ogc.WFS_v1_0_0 = function(opt_options) { }); goog.object.extend(this.writers[this.defaultNamespaceURI], { 'Query': function(options) { - // TODO see if we really need properties on the instance - /*goog.object.extend(options, { - featureNS: this.featureNS, - featurePrefix: this.featurePrefix, - featureType: this.featureType, - srsName: this.srsName, - srsNameInQuery: this.srsNameInQuery - });*/ - var prefix = goog.isDef(this.featurePrefix) ? this.featurePrefix + + var prefix = goog.isDef(options.featurePrefix) ? options.featurePrefix + ':' : ''; var node = this.createElementNS('wfs:Query'); node.setAttribute('typeName', prefix + options.featureType); if (goog.isDef(options.srsNameInQuery) && goog.isDef(options.srsName)) { node.setAttribute('srsName', options.srsName); } - if (goog.isDef(this.featureNS)) { - node.setAttribute('xmlns:' + this.featurePrefix, this.featureNS); + if (goog.isDef(options.featureNS)) { + node.setAttribute('xmlns:' + options.featurePrefix, options.featureNS); } if (goog.isDef(options.propertyNames)) { for (var i = 0, ii = options.propertyNames.length; i < ii; i++) { diff --git a/src/ol/parser/ogc/wfsparser_v1_1_0.js b/src/ol/parser/ogc/wfsparser_v1_1_0.js index e788cd4b5b..4889ccf1aa 100644 --- a/src/ol/parser/ogc/wfsparser_v1_1_0.js +++ b/src/ol/parser/ogc/wfsparser_v1_1_0.js @@ -9,12 +9,10 @@ goog.require('ol.parser.ogc.WFS_v1'); /** * @constructor -* @param {ol.parser.WFSOptions=} opt_options - * Optional configuration object. * @extends {ol.parser.ogc.WFS_v1} */ -ol.parser.ogc.WFS_v1_1_0 = function(opt_options) { - goog.base(this, opt_options); +ol.parser.ogc.WFS_v1_1_0 = function() { + goog.base(this); this.version = '1.1.0'; this.schemaLocation = this.defaultNamespaceURI + ' ' + 'http://schemas.opengis.net/wfs/1.1.0/wfs.xsd'; @@ -62,19 +60,13 @@ ol.parser.ogc.WFS_v1_1_0 = function(opt_options) { return node; }, 'Query': function(options) { - goog.object.extend(options, { - featureNS: this.featureNS, - featurePrefix: this.featurePrefix, - featureType: this.featureType, - srsName: this.srsName - }); - var prefix = goog.isDef(options.featurePrefix) ? options.prefix + ':' : - ''; + var prefix = goog.isDef(options.featurePrefix) ? options.featurePrefix + + ':' : ''; var node = this.createElementNS('wfs:Query'); node.setAttribute('typeName', prefix + options.featureType); node.setAttribute('srsName', options.srsName); if (goog.isDef(options.featureNS)) { - node.setAttribute('xmlns:' + options.prefix, options.featureNS); + node.setAttribute('xmlns:' + options.featurePrefix, options.featureNS); } if (goog.isDef(options.propertyNames)) { for (var i = 0, ii = options.propertyNames.length; i < ii; i++) { diff --git a/test/spec/ol/parser/ogc/wfs_v1_0_0.test.js b/test/spec/ol/parser/ogc/wfs_v1_0_0.test.js index c611aab39e..bab4dd44dc 100644 --- a/test/spec/ol/parser/ogc/wfs_v1_0_0.test.js +++ b/test/spec/ol/parser/ogc/wfs_v1_0_0.test.js @@ -22,8 +22,7 @@ describe('ol.parser.ogc.WFS_v1_0_0', function() { it('handles writing Query with BBOX Filter', function(done) { var url = 'spec/ol/parser/ogc/xml/wfs_v1_0_0/query0.xml'; afterLoadXml(url, function(xml) { - var p = new ol.parser.ogc.WFS_v1_0_0({featureTypes: ['states'], - featurePrefix: 'topp', featureNS: 'http://www.openplans.org/topp'}); + var p = new ol.parser.ogc.WFS_v1_0_0(); var filter = new ol.expr.Call( new ol.expr.Identifier(ol.expr.functions.EXTENT), [new ol.expr.Literal(1), new ol.expr.Literal(2), @@ -31,7 +30,12 @@ describe('ol.parser.ogc.WFS_v1_0_0', function() { undefined, new ol.expr.Identifier('the_geom')]); var output = p.writers[p.defaultNamespaceURI]['Query'].apply( - p, [{filter: filter, featureType: 'states'}]); + p, [{ + filter: filter, + featureType: 'states', + featureNS: 'http://www.openplans.org/topp', + featurePrefix: 'topp' + }]); expect(goog.dom.xml.loadXml(p.serialize(output))).to.xmleql(xml); done(); }); @@ -40,12 +44,16 @@ describe('ol.parser.ogc.WFS_v1_0_0', function() { it('handles writing GetFeature with PropertyName', function(done) { var url = 'spec/ol/parser/ogc/xml/wfs_v1_0_0/getfeature0.xml'; afterLoadXml(url, function(xml) { - var p = new ol.parser.ogc.WFS_v1_0_0({featureTypes: ['states'], - featurePrefix: 'topp', featureNS: 'http://www.openplans.org/topp'}); + var p = new ol.parser.ogc.WFS_v1_0_0(); var output = p.writers[p.defaultNamespaceURI]['GetFeature'].apply( - p, [{propertyNames: [new ol.expr.Identifier('STATE_NAME'), - new ol.expr.Identifier('STATE_FIPS'), - new ol.expr.Identifier('STATE_ABBR')]}]); + p, [{ + 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(); }); diff --git a/test/spec/ol/parser/ogc/wfs_v1_1_0.test.js b/test/spec/ol/parser/ogc/wfs_v1_1_0.test.js index 5027f1d4f6..4ae4b1b672 100644 --- a/test/spec/ol/parser/ogc/wfs_v1_1_0.test.js +++ b/test/spec/ol/parser/ogc/wfs_v1_1_0.test.js @@ -44,10 +44,40 @@ describe('ol.parser.ogc.WFS_v1_1_0', function() { }); }); + it('handles writing Query with BBOX Filter', function(done) { + var url = 'spec/ol/parser/ogc/xml/wfs_v1_1_0/query0.xml'; + afterLoadXml(url, function(xml) { + var p = new ol.parser.ogc.WFS_v1_1_0(); + var srs = 'urn:ogc:def:crs:EPSG::4326'; + var filter = new ol.expr.Call( + new ol.expr.Identifier(ol.expr.functions.EXTENT), + [new ol.expr.Literal(1), new ol.expr.Literal(2), + new ol.expr.Literal(3), new ol.expr.Literal(4), + new ol.expr.Literal(srs), + new ol.expr.Identifier('the_geom')]); + p.getFilterParser().getGmlParser().axisOrientation = + ol.proj.get(srs).getAxisOrientation(); + var output = p.writers[p.defaultNamespaceURI]['Query'].apply( + p, [{ + srsName: srs, + filter: filter, + featureType: 'states', + featureNS: 'http://www.openplans.org/topp', + featurePrefix: 'topp' + }]); + expect(goog.dom.xml.loadXml(p.serialize(output))).to.xmleql(xml); + done(); + }); + }); + }); }); goog.require('goog.dom.xml'); +goog.require('ol.expr.Call'); +goog.require('ol.expr.Identifier'); +goog.require('ol.expr.Literal'); goog.require('ol.parser.ogc.WFS'); goog.require('ol.parser.ogc.WFS_v1_1_0'); +goog.require('ol.proj'); diff --git a/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/query0.xml b/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/query0.xml new file mode 100644 index 0000000000..30be0808f7 --- /dev/null +++ b/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/query0.xml @@ -0,0 +1,11 @@ + + + + the_geom + + 1 2 + 3 4 + + + +