From d9c5102bcd5c0f8231708a611ffb36e8e5f7ebaf Mon Sep 17 00:00:00 2001 From: Antoine Abt Date: Fri, 14 Feb 2014 15:02:49 +0100 Subject: [PATCH 1/2] Add failing test for feature with null geometries --- test/spec/ol/format/geojsonformat.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/spec/ol/format/geojsonformat.test.js b/test/spec/ol/format/geojsonformat.test.js index 28d6b39f47..52cfb3fc69 100644 --- a/test/spec/ol/format/geojsonformat.test.js +++ b/test/spec/ol/format/geojsonformat.test.js @@ -19,6 +19,14 @@ describe('ol.format.GeoJSON', function() { } }; + var nullGeometryGeoJSON = { + 'type': 'Feature', + 'geometry': null, + 'properties': { + 'prop0': 'value0' + } + }; + var lineStringGeoJSON = { 'type': 'Feature', 'geometry': { @@ -150,6 +158,14 @@ describe('ol.format.GeoJSON', function() { expect(feature.get('prop1')).to.eql({'this': 'that'}); }); + it('can read a feature with null geometry', function() { + var feature = format.readFeature(nullGeometryGeoJSON); + expect(feature).to.be.an(ol.Feature); + var geometry = feature.getGeometry(); + expect(geometry).to.eql(null); + expect(feature.get('prop0')).to.be('value0'); + }); + it('can read a feature collection', function() { var features = format.readFeatures(featureCollectionGeoJSON); expect(features).to.have.length(3); From 24ee4cb742da7f5fb2437a6c0cb5d0b84647b9ac Mon Sep 17 00:00:00 2001 From: Antoine Abt Date: Fri, 14 Feb 2014 15:12:16 +0100 Subject: [PATCH 2/2] [GeoJSON] Add support for feature with null geometries --- src/ol/format/geojsonformat.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ol/format/geojsonformat.js b/src/ol/format/geojsonformat.js index c5b03db581..1d3d7da2bf 100644 --- a/src/ol/format/geojsonformat.js +++ b/src/ol/format/geojsonformat.js @@ -57,6 +57,9 @@ ol.format.GeoJSON.EXTENSIONS_ = ['.geojson']; * @return {ol.geom.Geometry} Geometry. */ ol.format.GeoJSON.readGeometry_ = function(object) { + if (goog.isNull(object)) { + return null; + } var geometryReader = ol.format.GeoJSON.GEOMETRY_READERS_[object.type]; goog.asserts.assert(goog.isDef(geometryReader)); return geometryReader(object);