diff --git a/src/ol/format/gmlformat.js b/src/ol/format/gmlformat.js index d235fc3ac5..8df6e5f05a 100644 --- a/src/ol/format/gmlformat.js +++ b/src/ol/format/gmlformat.js @@ -119,14 +119,20 @@ ol.format.GML.schemaLocation_ = 'http://www.opengis.net/gml ' + ol.format.GML.readFeatures_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); var localName = ol.xml.getLocalName(node); - var context = objectStack[0]; - goog.asserts.assert(goog.isObject(context)); - var featureType = goog.object.get(context, 'featureType'); var features; if (localName == 'FeatureCollection') { features = ol.xml.pushParseAndPop(null, ol.format.GML.FEATURE_COLLECTION_PARSERS, 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'); + if (!goog.isDef(featureType) && !goog.isNull(node.firstElementChild)) { + var member = node.firstElementChild; + featureType = member.nodeName.split(':').pop(); + goog.object.set(context, 'featureType', featureType); + goog.object.set(context, 'featureNS', member.namespaceURI); + } var parsers = {}; var parsersNS = {}; parsers[featureType] = (localName == 'featureMembers') ? diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index e96d571ae7..143e846ade 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -768,6 +768,58 @@ describe('ol.format.GML', function() { }); }); + describe('when parsing TOPP states WFS with autoconfigure', function() { + var features, text, gmlFormat; + before(function(done) { + afterLoadText('spec/ol/format/gml/topp-states-wfs.xml', function(xml) { + try { + text = xml; + gmlFormat = new ol.format.GML(); + features = gmlFormat.readFeatures(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + + it('creates 3 features', function() { + expect(features).to.have.length(3); + }); + + it('creates the right id for the feature', function() { + expect(features[0].getId()).to.equal('states.1'); + }); + + it('can reuse the parser for a different featureNS', function() { + var text = + '' + + ' ' + + ' Aflu' + + ' ' + + ' ' + + ' 34.12 2.09' + + ' ' + + ' ' + + ' 84683' + + ' ' + + ''; + features = gmlFormat.readFeatures(text); + expect(features).to.have.length(1); + expect(features[0].get('population')).to.equal('84683'); + }); + + it('can read an empty collection', function() { + var text = + '' + + ''; + features = gmlFormat.readFeatures(text); + expect(features).to.have.length(0); + }); + + }); + describe('when parsing TOPP states GML', function() { var features, text, gmlFormat;