diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index bede4019cc..3f09348a5b 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -747,8 +747,10 @@ ol.format.WFS.prototype.readProjectionFromDocument = function(doc) { ol.format.WFS.prototype.readProjectionFromNode = function(node) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'FeatureCollection'); - node = node.firstElementChild.firstElementChild; - if (goog.isDefAndNotNull(node)) { + + if (goog.isDefAndNotNull(node.firstElementChild) && + goog.isDefAndNotNull(node.firstElementChild.firstElementChild)) { + node = node.firstElementChild.firstElementChild; for (var n = node.firstElementChild; !goog.isNull(n); n = n.nextElementSibling) { if (!(n.childNodes.length === 0 || @@ -760,5 +762,6 @@ ol.format.WFS.prototype.readProjectionFromNode = function(node) { } } } + return null; }; diff --git a/test/spec/ol/format/wfs/EmptyFeatureCollection.xml b/test/spec/ol/format/wfs/EmptyFeatureCollection.xml new file mode 100644 index 0000000000..631df2bd91 --- /dev/null +++ b/test/spec/ol/format/wfs/EmptyFeatureCollection.xml @@ -0,0 +1,9 @@ + + + diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index 09a3f6efb5..a13def7f39 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -89,6 +89,21 @@ describe('ol.format.WFS', function() { }); + describe('when parsing FeatureCollection', function() { + var xml; + before(function(done) { + afterLoadText('spec/ol/format/wfs/EmptyFeatureCollection.xml', + function(_xml) { + xml = _xml; + done(); + }); + }); + it('returns an empty array of features when none exist', function() { + var result = new ol.format.WFS().readFeatures(xml); + expect(result).to.have.length(0); + }); + }); + describe('when parsing FeatureCollection', function() { var response; before(function(done) {