Support multiple feature types in GML format

This commit is contained in:
Bart van den Eijnden
2014-12-19 13:07:40 +01:00
parent 7527eddbaf
commit 3a7905f2fd
4 changed files with 102 additions and 12 deletions

View File

@@ -1679,8 +1679,8 @@ olx.format.KMLOptions.prototype.defaultStyle;
/**
* @typedef {{featureNS: string,
* featureType: string,
* @typedef {{featureNS: (string|undefined),
* featureType: (Array.<string>|string|undefined),
* srsName: string,
* surface: (boolean|undefined),
* curve: (boolean|undefined),
@@ -1693,16 +1693,16 @@ olx.format.GMLOptions;
/**
* Feature namespace.
* @type {string}
* Feature namespace. If not defined will be derived from GML.
* @type {string|undefined}
* @api stable
*/
olx.format.GMLOptions.prototype.featureNS;
/**
* Feature type to parse.
* @type {string}
* Feature type(s) to parse.
* @type {Array.<string>|string|undefined}
* @api stable
*/
olx.format.GMLOptions.prototype.featureType;

View File

@@ -45,13 +45,13 @@ ol.format.GMLBase = function(opt_options) {
/**
* @protected
* @type {string}
* @type {Array.<string>|string|undefined}
*/
this.featureType = options.featureType;
/**
* @protected
* @type {string}
* @type {string|undefined}
*/
this.featureNS = options.featureNS;
@@ -115,10 +115,13 @@ ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) {
}
var parsers = {};
var parsersNS = {};
parsers[featureType] = (localName == 'featureMembers') ?
ol.xml.makeArrayPusher(this.readFeatureElement, this) :
ol.xml.makeReplacer(this.readFeatureElement, this);
parsersNS[context['featureNS']] = parsers;
var featureTypes = goog.isArray(featureType) ? featureType : [featureType];
for (var i = 0, ii = featureTypes.length; i < ii; ++i) {
parsers[featureTypes[i]] = (localName == 'featureMembers') ?
ol.xml.makeArrayPusher(this.readFeatureElement, this) :
ol.xml.makeReplacer(this.readFeatureElement, this);
}
parsersNS[goog.object.get(context, 'featureNS')] = parsers;
features = ol.xml.pushParseAndPop([], parsersNS, node, objectStack);
}
if (!goog.isDef(features)) {

View File

@@ -0,0 +1,44 @@
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml"
xmlns:official="http://localhost:8080/official" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" numberOfFeatures="12"
timeStamp="2014-11-03T21:04:28.345Z">
<gml:featureMembers>
<official:planet_osm_line gml:id="planet_osm_line.fid-53719711_14976c6c1aa_6795">
<official:osm_id>3822829</official:osm_id>
</official:planet_osm_line>
<official:planet_osm_line gml:id="planet_osm_line.fid-53719711_14976c6c1aa_6796">
<official:osm_id>3820888</official:osm_id>
</official:planet_osm_line>
<official:planet_osm_line gml:id="planet_osm_line.fid-53719711_14976c6c1aa_6797">
<official:osm_id>296916318</official:osm_id>
</official:planet_osm_line>
<official:planet_osm_polygon gml:id="planet_osm_polygon.fid-53719711_14976c6c1aa_6798">
<official:osm_id>37244</official:osm_id>
</official:planet_osm_polygon>
<official:planet_osm_polygon gml:id="planet_osm_polygon.fid-53719711_14976c6c1aa_6799">
<official:osm_id>1641478</official:osm_id>
</official:planet_osm_polygon>
<official:planet_osm_polygon gml:id="planet_osm_polygon.fid-53719711_14976c6c1aa_679a">
<official:osm_id>1244004</official:osm_id>
</official:planet_osm_polygon>
<official:planet_osm_polygon gml:id="planet_osm_polygon.fid-53719711_14976c6c1aa_679b">
<official:osm_id>22259</official:osm_id>
</official:planet_osm_polygon>
<official:planet_osm_polygon gml:id="planet_osm_polygon.fid-53719711_14976c6c1aa_679c">
<official:osm_id>1606103</official:osm_id>
</official:planet_osm_polygon>
<official:planet_osm_polygon gml:id="planet_osm_polygon.fid-53719711_14976c6c1aa_679d">
<official:osm_id>3217145</official:osm_id>
</official:planet_osm_polygon>
<official:planet_osm_polygon gml:id="planet_osm_polygon.fid-53719711_14976c6c1aa_679e">
<official:osm_id>3228576</official:osm_id>
</official:planet_osm_polygon>
<official:planet_osm_polygon gml:id="planet_osm_polygon.fid-53719711_14976c6c1aa_679f">
<official:osm_id>936994</official:osm_id>
</official:planet_osm_polygon>
<official:planet_osm_polygon gml:id="planet_osm_polygon.fid-53719711_14976c6c1aa_67a0">
<official:osm_id>936990</official:osm_id>
</official:planet_osm_polygon>
</gml:featureMembers>
</wfs:FeatureCollection>

View File

@@ -1107,6 +1107,49 @@ describe('ol.format.GML3', 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.GML({
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.GML().readFeatures(xml);
} catch (e) {
done(e);
}
done();
});
});
it('reads all features with autoconfigure', function() {
expect(features.length).to.be(12);
});
});
});