From b05ead4056c169dbbe1b83c96455a5d99beb7403 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Sat, 27 Dec 2014 19:12:57 +0100 Subject: [PATCH] Allow multiple featureTypes through ol.format.WFS as well --- externs/olx.js | 4 +-- src/ol/format/gml/gmlbaseformat.js | 4 +-- src/ol/format/wfsformat.js | 2 +- test/spec/ol/format/wfsformat.test.js | 43 +++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index 25dcf58be3..dc8bcce415 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -1783,7 +1783,7 @@ olx.format.GPXOptions.prototype.readExtensions; /** * @typedef {{featureNS: string, - * featureType: string, + * featureType: (Array.|string|undefined), * gmlFormat: (ol.format.GMLBase|undefined), * schemaLocation: (string|undefined)}} * @api @@ -1801,7 +1801,7 @@ olx.format.WFSOptions.prototype.featureNS; /** * The feature type to parse. Only used for read operations. - * @type {string} + * @type {Array.|string|undefined} * @api stable */ olx.format.WFSOptions.prototype.featureType; diff --git a/src/ol/format/gml/gmlbaseformat.js b/src/ol/format/gml/gmlbaseformat.js index 555a28f052..751f02f588 100644 --- a/src/ol/format/gml/gmlbaseformat.js +++ b/src/ol/format/gml/gmlbaseformat.js @@ -106,7 +106,7 @@ ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) { } else if (localName == 'featureMembers' || localName == 'featureMember') { var context = objectStack[0]; goog.asserts.assert(goog.isObject(context)); - var featureType = goog.object.get(context, 'featureType'); + var featureType = context['featureType']; var i, ii, featureNS; if (!goog.isDef(featureType) && goog.isDefAndNotNull(node.childNodes)) { featureType = []; @@ -133,7 +133,7 @@ ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) { ol.xml.makeArrayPusher(this.readFeatureElement, this) : ol.xml.makeReplacer(this.readFeatureElement, this); } - parsersNS[goog.object.get(context, 'featureNS')] = parsers; + parsersNS[context['featureNS']] = parsers; features = ol.xml.pushParseAndPop([], parsersNS, node, objectStack); } if (!goog.isDef(features)) { diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 540d139506..bc1b3394da 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -31,7 +31,7 @@ ol.format.WFS = function(opt_options) { /** * @private - * @type {string} + * @type {Array.|string|undefined} */ this.featureType_ = options.featureType; diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index a13def7f39..db52d424c5 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -448,6 +448,49 @@ describe('ol.format.WFS', function() { }); + describe('when parsing multiple feature types', function() { + + var features; + before(function(done) { + afterLoadText('spec/ol/format/gml/multiple-typenames.xml', function(xml) { + try { + features = new ol.format.WFS({ + featureNS: 'http://localhost:8080/official', + featureType: ['planet_osm_polygon', 'planet_osm_line'] + }).readFeatures(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + + it('reads all features', function() { + expect(features.length).to.be(12); + }); + + }); + + describe('when parsing multiple feature types', function() { + + var features; + before(function(done) { + afterLoadText('spec/ol/format/gml/multiple-typenames.xml', function(xml) { + try { + features = new ol.format.WFS().readFeatures(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + + it('reads all features with autoconfigure', function() { + expect(features.length).to.be(12); + }); + + }); + });