Allow multiple featureTypes through ol.format.WFS as well

This commit is contained in:
Bart van den Eijnden
2014-12-27 19:12:57 +01:00
parent d0180f35e0
commit b05ead4056
4 changed files with 48 additions and 5 deletions

View File

@@ -1783,7 +1783,7 @@ olx.format.GPXOptions.prototype.readExtensions;
/**
* @typedef {{featureNS: string,
* featureType: string,
* featureType: (Array.<string>|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>|string|undefined}
* @api stable
*/
olx.format.WFSOptions.prototype.featureType;

View File

@@ -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)) {

View File

@@ -31,7 +31,7 @@ ol.format.WFS = function(opt_options) {
/**
* @private
* @type {string}
* @type {Array.<string>|string|undefined}
*/
this.featureType_ = options.featureType;

View File

@@ -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);
});
});
});