diff --git a/src/ol/format/geojsonformat.js b/src/ol/format/geojsonformat.js index 52939de19f..16a43745e6 100644 --- a/src/ol/format/geojsonformat.js +++ b/src/ol/format/geojsonformat.js @@ -530,7 +530,7 @@ ol.format.GeoJSON.prototype.writeFeatureObject = function( 'type': 'Feature' }; var id = feature.getId(); - if (id) { + if (id !== undefined) { object['id'] = id; } var geometry = feature.getGeometry(); diff --git a/test/spec/ol/format/geojsonformat.test.js b/test/spec/ol/format/geojsonformat.test.js index 655bef9ee8..c36bbe2c91 100644 --- a/test/spec/ol/format/geojsonformat.test.js +++ b/test/spec/ol/format/geojsonformat.test.js @@ -551,6 +551,12 @@ describe('ol.format.GeoJSON', function() { expect(geojson.geometry).to.eql(null); }); + it('writes out a feature with id equal to 0 correctly', function() { + var feature = new ol.Feature(); + feature.setId(0); + var geojson = format.writeFeatureObject(feature); + expect(geojson.id).to.eql(0); + }); }); describe('#writeGeometry', function() {