diff --git a/externs/geojson.js b/externs/geojson.js index 0b7c2c74ac..afa13c30f1 100644 --- a/externs/geojson.js +++ b/externs/geojson.js @@ -123,7 +123,7 @@ var GeoJSONFeature = function() {}; /** - * @type {GeoJSONGeometry} + * @type {GeoJSONGeometry|GeoJSONGeometryCollection} */ GeoJSONFeature.prototype.geometry; diff --git a/src/ol/format/geojsonformat.js b/src/ol/format/geojsonformat.js index 592c55930b..eb6a5567b5 100644 --- a/src/ol/format/geojsonformat.js +++ b/src/ol/format/geojsonformat.js @@ -541,6 +541,8 @@ ol.format.GeoJSON.prototype.writeFeatureObject = function( if (goog.isDefAndNotNull(geometry)) { object['geometry'] = ol.format.GeoJSON.writeGeometry_(geometry, opt_options); + } else { + object['geometry'] = null; } var properties = feature.getProperties(); goog.object.remove(properties, feature.getGeometryName()); diff --git a/test/spec/ol/format/geojsonformat.test.js b/test/spec/ol/format/geojsonformat.test.js index b4cc9cf174..79f18336d6 100644 --- a/test/spec/ol/format/geojsonformat.test.js +++ b/test/spec/ol/format/geojsonformat.test.js @@ -530,6 +530,12 @@ describe('ol.format.GeoJSON', function() { expect(geojson.properties).to.eql(null); }); + it('writes out a feature without geometry correctly', function() { + var feature = new ol.Feature(); + var geojson = format.writeFeatureObject(feature); + expect(geojson.geometry).to.eql(null); + }); + }); describe('#writeGeometry', function() {