Merge pull request #3784 from fredj/geojson_geometry

Always write the GeoJSONFeature geometry property
This commit is contained in:
Frédéric Junod
2015-06-11 10:20:02 +02:00
3 changed files with 9 additions and 1 deletions

View File

@@ -123,7 +123,7 @@ var GeoJSONFeature = function() {};
/** /**
* @type {GeoJSONGeometry} * @type {GeoJSONGeometry|GeoJSONGeometryCollection}
*/ */
GeoJSONFeature.prototype.geometry; GeoJSONFeature.prototype.geometry;

View File

@@ -541,6 +541,8 @@ ol.format.GeoJSON.prototype.writeFeatureObject = function(
if (goog.isDefAndNotNull(geometry)) { if (goog.isDefAndNotNull(geometry)) {
object['geometry'] = object['geometry'] =
ol.format.GeoJSON.writeGeometry_(geometry, opt_options); ol.format.GeoJSON.writeGeometry_(geometry, opt_options);
} else {
object['geometry'] = null;
} }
var properties = feature.getProperties(); var properties = feature.getProperties();
goog.object.remove(properties, feature.getGeometryName()); goog.object.remove(properties, feature.getGeometryName());

View File

@@ -530,6 +530,12 @@ describe('ol.format.GeoJSON', function() {
expect(geojson.properties).to.eql(null); 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() { describe('#writeGeometry', function() {