diff --git a/src/ol/format/gmlformat.js b/src/ol/format/gmlformat.js index 58959fcce5..7be66ae95a 100644 --- a/src/ol/format/gmlformat.js +++ b/src/ol/format/gmlformat.js @@ -5,6 +5,7 @@ goog.require('goog.asserts'); goog.require('goog.dom'); goog.require('goog.dom.NodeType'); goog.require('goog.dom.TagName'); +goog.require('goog.string'); goog.require('ol.Feature'); goog.require('ol.extent'); goog.require('ol.format.XML'); @@ -145,7 +146,11 @@ ol.format.GML.prototype.readFeature_ = function(node, objectStack) { if (n.childNodes.length === 0 || (n.childNodes.length === 1 && n.firstChild.nodeType === 3)) { - values[ol.xml.getLocalName(n)] = ol.xml.getAllTextContent(n, false); + var value = ol.xml.getAllTextContent(n, false); + if (goog.string.isEmpty(value)) { + value = undefined; + } + values[ol.xml.getLocalName(n)] = value; } else { geometryName = ol.xml.getLocalName(n); values[geometryName] = this.readGeometryFromNode(n); diff --git a/old/test/spec/ol/parser/ogc/xml/gml_v3/more-geoms.xml b/test/spec/ol/format/gml/more-geoms.xml similarity index 100% rename from old/test/spec/ol/parser/ogc/xml/gml_v3/more-geoms.xml rename to test/spec/ol/format/gml/more-geoms.xml diff --git a/old/test/spec/ol/parser/ogc/xml/gml_v3/repeated-name.xml b/test/spec/ol/format/gml/repeated-name.xml similarity index 100% rename from old/test/spec/ol/parser/ogc/xml/gml_v3/repeated-name.xml rename to test/spec/ol/format/gml/repeated-name.xml diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index 55ffa57423..9daad10943 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -543,6 +543,35 @@ describe('ol.format.GML', function() { }); + describe('when parsing empty attribute', function() { + it('generates undefined value', function() { + var text = + '' + + ' ' + + ' Aflu' + + ' ' + + ' ' + + ' 34.12 2.09' + + ' ' + + ' ' + + ' 84683' + + ' Algeria' + + ' place' + + ' Aflu' + + ' ' + + ' ' + + ''; + var config = { + 'featureNS': 'http://www.openplans.org/topp', + 'featureType': 'gnis_pop' + }; + var features = new ol.format.GML(config).readFeatures(text); + var feature = features[0]; + expect(feature.get('empty')).to.be(undefined); + }); + }); + describe('when parsing TOPP states GML', function() { var features; @@ -597,6 +626,57 @@ describe('ol.format.GML', function() { }); + describe('when parsing more than one geometry', function() { + + var features, feature; + before(function(done) { + afterLoadText('spec/ol/format/gml/more-geoms.xml', function(xml) { + try { + var config = { + 'featureNS': 'http://opengeo.org/#medford', + 'featureType': 'zoning' + }; + features = new ol.format.GML(config).readFeatures(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + + it('creates 2 geometries', function() { + var feature = features[0]; + expect(feature.get('center')).to.be.a(ol.geom.Point); + expect(feature.get('the_geom')).to.be.a(ol.geom.MultiPolygon); + }); + + }); + + describe('when parsing an attribute name equal to featureType', function() { + + var features, feature; + before(function(done) { + afterLoadText('spec/ol/format/gml/repeated-name.xml', function(xml) { + try { + var config = { + 'featureNS': 'http://opengeo.org/#medford', + 'featureType': 'zoning' + }; + features = new ol.format.GML(config).readFeatures(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + + it('creates the correct attribute value', function() { + var feature = features[0]; + expect(feature.get('zoning')).to.equal('I-L'); + }); + + }); + });