Support multiple feature types in GML format
This commit is contained in:
@@ -1679,8 +1679,8 @@ olx.format.KMLOptions.prototype.defaultStyle;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{featureNS: string,
|
* @typedef {{featureNS: (string|undefined),
|
||||||
* featureType: string,
|
* featureType: (Array.<string>|string|undefined),
|
||||||
* srsName: string,
|
* srsName: string,
|
||||||
* surface: (boolean|undefined),
|
* surface: (boolean|undefined),
|
||||||
* curve: (boolean|undefined),
|
* curve: (boolean|undefined),
|
||||||
@@ -1693,16 +1693,16 @@ olx.format.GMLOptions;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Feature namespace.
|
* Feature namespace. If not defined will be derived from GML.
|
||||||
* @type {string}
|
* @type {string|undefined}
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
olx.format.GMLOptions.prototype.featureNS;
|
olx.format.GMLOptions.prototype.featureNS;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Feature type to parse.
|
* Feature type(s) to parse.
|
||||||
* @type {string}
|
* @type {Array.<string>|string|undefined}
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
olx.format.GMLOptions.prototype.featureType;
|
olx.format.GMLOptions.prototype.featureType;
|
||||||
|
|||||||
@@ -45,13 +45,13 @@ ol.format.GMLBase = function(opt_options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @type {string}
|
* @type {Array.<string>|string|undefined}
|
||||||
*/
|
*/
|
||||||
this.featureType = options.featureType;
|
this.featureType = options.featureType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @type {string}
|
* @type {string|undefined}
|
||||||
*/
|
*/
|
||||||
this.featureNS = options.featureNS;
|
this.featureNS = options.featureNS;
|
||||||
|
|
||||||
@@ -115,10 +115,13 @@ ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) {
|
|||||||
}
|
}
|
||||||
var parsers = {};
|
var parsers = {};
|
||||||
var parsersNS = {};
|
var parsersNS = {};
|
||||||
parsers[featureType] = (localName == 'featureMembers') ?
|
var featureTypes = goog.isArray(featureType) ? featureType : [featureType];
|
||||||
ol.xml.makeArrayPusher(this.readFeatureElement, this) :
|
for (var i = 0, ii = featureTypes.length; i < ii; ++i) {
|
||||||
ol.xml.makeReplacer(this.readFeatureElement, this);
|
parsers[featureTypes[i]] = (localName == 'featureMembers') ?
|
||||||
parsersNS[context['featureNS']] = parsers;
|
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);
|
features = ol.xml.pushParseAndPop([], parsersNS, node, objectStack);
|
||||||
}
|
}
|
||||||
if (!goog.isDef(features)) {
|
if (!goog.isDef(features)) {
|
||||||
|
|||||||
44
test/spec/ol/format/gml/multiple-typenames.xml
Normal file
44
test/spec/ol/format/gml/multiple-typenames.xml
Normal 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>
|
||||||
@@ -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);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user