diff --git a/src/ol/format/geojsonformat.js b/src/ol/format/geojsonformat.js index d703970609..b9f3b59886 100644 --- a/src/ol/format/geojsonformat.js +++ b/src/ol/format/geojsonformat.js @@ -153,6 +153,19 @@ ol.format.GeoJSON.writeGeometry_ = function(geometry) { }; +/** + * @param {ol.geom.Geometry} geometry Geometry. + * @private + * @return {GeoJSONGeometryCollection} Empty GeoJSON geometry collection. + */ +ol.format.GeoJSON.writeEmptyGeometryCollectionGeometry_ = function(geometry) { + return /** @type {GeoJSONGeometryCollection} */ ({ + 'type': 'GeometryCollection', + 'geometries': [] + }); +}; + + /** * @param {ol.geom.Geometry} geometry Geometry. * @private @@ -283,7 +296,8 @@ ol.format.GeoJSON.GEOMETRY_WRITERS_ = { 'MultiPoint': ol.format.GeoJSON.writeMultiPointGeometry_, 'MultiLineString': ol.format.GeoJSON.writeMultiLineStringGeometry_, 'MultiPolygon': ol.format.GeoJSON.writeMultiPolygonGeometry_, - 'GeometryCollection': ol.format.GeoJSON.writeGeometryCollectionGeometry_ + 'GeometryCollection': ol.format.GeoJSON.writeGeometryCollectionGeometry_, + 'Circle': ol.format.GeoJSON.writeEmptyGeometryCollectionGeometry_ }; diff --git a/test/spec/ol/format/geojsonformat.test.js b/test/spec/ol/format/geojsonformat.test.js index a6792d834f..d9248b6661 100644 --- a/test/spec/ol/format/geojsonformat.test.js +++ b/test/spec/ol/format/geojsonformat.test.js @@ -458,6 +458,16 @@ describe('ol.format.GeoJSON', function() { expect(geometries[i].getCoordinates()). to.eql(gotGeometries[i].getCoordinates()); } + + }); + + it('encodes a circle as an empty geometry collection', function() { + var circle = new ol.geom.Circle([0, 0], 1); + var geojson = format.writeGeometry(circle); + expect(geojson).to.eql({ + 'type': 'GeometryCollection', + 'geometries': [] + }); }); }); @@ -468,6 +478,7 @@ describe('ol.format.GeoJSON', function() { goog.require('ol.Feature'); goog.require('ol.extent'); goog.require('ol.format.GeoJSON'); +goog.require('ol.geom.Circle'); goog.require('ol.geom.GeometryCollection'); goog.require('ol.geom.LineString'); goog.require('ol.geom.LinearRing');