Don't store private function into GeoJSON

This commit is contained in:
Frederic Junod
2017-12-19 15:43:58 +01:00
parent 1aa7313a7b
commit 9f63431539

View File

@@ -68,10 +68,9 @@ inherits(GeoJSON, JSONFeature);
/** /**
* @param {GeoJSONGeometry|GeoJSONGeometryCollection} object Object. * @param {GeoJSONGeometry|GeoJSONGeometryCollection} object Object.
* @param {olx.format.ReadOptions=} opt_options Read options. * @param {olx.format.ReadOptions=} opt_options Read options.
* @private
* @return {ol.geom.Geometry} Geometry. * @return {ol.geom.Geometry} Geometry.
*/ */
GeoJSON.readGeometry_ = function(object, opt_options) { function readGeometry(object, opt_options) {
if (!object) { if (!object) {
return null; return null;
} }
@@ -80,185 +79,169 @@ GeoJSON.readGeometry_ = function(object, opt_options) {
/** @type {ol.geom.Geometry} */ FeatureFormat.transformWithOptions( /** @type {ol.geom.Geometry} */ FeatureFormat.transformWithOptions(
geometryReader(object), false, opt_options) geometryReader(object), false, opt_options)
); );
}; }
/** /**
* @param {GeoJSONGeometryCollection} object Object. * @param {GeoJSONGeometryCollection} object Object.
* @param {olx.format.ReadOptions=} opt_options Read options. * @param {olx.format.ReadOptions=} opt_options Read options.
* @private
* @return {ol.geom.GeometryCollection} Geometry collection. * @return {ol.geom.GeometryCollection} Geometry collection.
*/ */
GeoJSON.readGeometryCollectionGeometry_ = function( function readGeometryCollectionGeometry(object, opt_options) {
object, opt_options) {
var geometries = object.geometries.map( var geometries = object.geometries.map(
/** /**
* @param {GeoJSONGeometry} geometry Geometry. * @param {GeoJSONGeometry} geometry Geometry.
* @return {ol.geom.Geometry} geometry Geometry. * @return {ol.geom.Geometry} geometry Geometry.
*/ */
function(geometry) { function(geometry) {
return GeoJSON.readGeometry_(geometry, opt_options); return readGeometry(geometry, opt_options);
}); });
return new GeometryCollection(geometries); return new GeometryCollection(geometries);
}; }
/** /**
* @param {GeoJSONGeometry} object Object. * @param {GeoJSONGeometry} object Object.
* @private
* @return {ol.geom.Point} Point. * @return {ol.geom.Point} Point.
*/ */
GeoJSON.readPointGeometry_ = function(object) { function readPointGeometry(object) {
return new Point(object.coordinates); return new Point(object.coordinates);
}; }
/** /**
* @param {GeoJSONGeometry} object Object. * @param {GeoJSONGeometry} object Object.
* @private
* @return {ol.geom.LineString} LineString. * @return {ol.geom.LineString} LineString.
*/ */
GeoJSON.readLineStringGeometry_ = function(object) { function readLineStringGeometry(object) {
return new LineString(object.coordinates); return new LineString(object.coordinates);
}; }
/** /**
* @param {GeoJSONGeometry} object Object. * @param {GeoJSONGeometry} object Object.
* @private
* @return {ol.geom.MultiLineString} MultiLineString. * @return {ol.geom.MultiLineString} MultiLineString.
*/ */
GeoJSON.readMultiLineStringGeometry_ = function(object) { function readMultiLineStringGeometry(object) {
return new MultiLineString(object.coordinates); return new MultiLineString(object.coordinates);
}; }
/** /**
* @param {GeoJSONGeometry} object Object. * @param {GeoJSONGeometry} object Object.
* @private
* @return {ol.geom.MultiPoint} MultiPoint. * @return {ol.geom.MultiPoint} MultiPoint.
*/ */
GeoJSON.readMultiPointGeometry_ = function(object) { function readMultiPointGeometry(object) {
return new MultiPoint(object.coordinates); return new MultiPoint(object.coordinates);
}; }
/** /**
* @param {GeoJSONGeometry} object Object. * @param {GeoJSONGeometry} object Object.
* @private
* @return {ol.geom.MultiPolygon} MultiPolygon. * @return {ol.geom.MultiPolygon} MultiPolygon.
*/ */
GeoJSON.readMultiPolygonGeometry_ = function(object) { function readMultiPolygonGeometry(object) {
return new MultiPolygon(object.coordinates); return new MultiPolygon(object.coordinates);
}; }
/** /**
* @param {GeoJSONGeometry} object Object. * @param {GeoJSONGeometry} object Object.
* @private
* @return {ol.geom.Polygon} Polygon. * @return {ol.geom.Polygon} Polygon.
*/ */
GeoJSON.readPolygonGeometry_ = function(object) { function readPolygonGeometry(object) {
return new Polygon(object.coordinates); return new Polygon(object.coordinates);
}; }
/** /**
* @param {ol.geom.Geometry} geometry Geometry. * @param {ol.geom.Geometry} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options. * @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {GeoJSONGeometry|GeoJSONGeometryCollection} GeoJSON geometry. * @return {GeoJSONGeometry|GeoJSONGeometryCollection} GeoJSON geometry.
*/ */
GeoJSON.writeGeometry_ = function(geometry, opt_options) { function writeGeometry(geometry, opt_options) {
var geometryWriter = GeoJSON.GEOMETRY_WRITERS_[geometry.getType()]; var geometryWriter = GeoJSON.GEOMETRY_WRITERS_[geometry.getType()];
return geometryWriter(/** @type {ol.geom.Geometry} */ ( return geometryWriter(/** @type {ol.geom.Geometry} */ (
FeatureFormat.transformWithOptions(geometry, true, opt_options)), FeatureFormat.transformWithOptions(geometry, true, opt_options)),
opt_options); opt_options);
}; }
/** /**
* @param {ol.geom.Geometry} geometry Geometry. * @param {ol.geom.Geometry} geometry Geometry.
* @private
* @return {GeoJSONGeometryCollection} Empty GeoJSON geometry collection. * @return {GeoJSONGeometryCollection} Empty GeoJSON geometry collection.
*/ */
GeoJSON.writeEmptyGeometryCollectionGeometry_ = function(geometry) { function writeEmptyGeometryCollectionGeometry(geometry) {
return /** @type {GeoJSONGeometryCollection} */ ({ return /** @type {GeoJSONGeometryCollection} */ ({
type: 'GeometryCollection', type: 'GeometryCollection',
geometries: [] geometries: []
}); });
}; }
/** /**
* @param {ol.geom.GeometryCollection} geometry Geometry. * @param {ol.geom.GeometryCollection} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options. * @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {GeoJSONGeometryCollection} GeoJSON geometry collection. * @return {GeoJSONGeometryCollection} GeoJSON geometry collection.
*/ */
GeoJSON.writeGeometryCollectionGeometry_ = function( function writeGeometryCollectionGeometry(geometry, opt_options) {
geometry, opt_options) {
var geometries = geometry.getGeometriesArray().map(function(geometry) { var geometries = geometry.getGeometriesArray().map(function(geometry) {
var options = _ol_obj_.assign({}, opt_options); var options = _ol_obj_.assign({}, opt_options);
delete options.featureProjection; delete options.featureProjection;
return GeoJSON.writeGeometry_(geometry, options); return writeGeometry(geometry, options);
}); });
return /** @type {GeoJSONGeometryCollection} */ ({ return /** @type {GeoJSONGeometryCollection} */ ({
type: 'GeometryCollection', type: 'GeometryCollection',
geometries: geometries geometries: geometries
}); });
}; }
/** /**
* @param {ol.geom.LineString} geometry Geometry. * @param {ol.geom.LineString} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options. * @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
GeoJSON.writeLineStringGeometry_ = function(geometry, opt_options) { function writeLineStringGeometry(geometry, opt_options) {
return /** @type {GeoJSONGeometry} */ ({ return /** @type {GeoJSONGeometry} */ ({
type: 'LineString', type: 'LineString',
coordinates: geometry.getCoordinates() coordinates: geometry.getCoordinates()
}); });
}; }
/** /**
* @param {ol.geom.MultiLineString} geometry Geometry. * @param {ol.geom.MultiLineString} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options. * @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
GeoJSON.writeMultiLineStringGeometry_ = function(geometry, opt_options) { function writeMultiLineStringGeometry(geometry, opt_options) {
return /** @type {GeoJSONGeometry} */ ({ return /** @type {GeoJSONGeometry} */ ({
type: 'MultiLineString', type: 'MultiLineString',
coordinates: geometry.getCoordinates() coordinates: geometry.getCoordinates()
}); });
}; }
/** /**
* @param {ol.geom.MultiPoint} geometry Geometry. * @param {ol.geom.MultiPoint} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options. * @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
GeoJSON.writeMultiPointGeometry_ = function(geometry, opt_options) { function writeMultiPointGeometry(geometry, opt_options) {
return /** @type {GeoJSONGeometry} */ ({ return /** @type {GeoJSONGeometry} */ ({
type: 'MultiPoint', type: 'MultiPoint',
coordinates: geometry.getCoordinates() coordinates: geometry.getCoordinates()
}); });
}; }
/** /**
* @param {ol.geom.MultiPolygon} geometry Geometry. * @param {ol.geom.MultiPolygon} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options. * @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
GeoJSON.writeMultiPolygonGeometry_ = function(geometry, opt_options) { function writeMultiPolygonGeometry(geometry, opt_options) {
var right; var right;
if (opt_options) { if (opt_options) {
right = opt_options.rightHanded; right = opt_options.rightHanded;
@@ -267,30 +250,28 @@ GeoJSON.writeMultiPolygonGeometry_ = function(geometry, opt_options) {
type: 'MultiPolygon', type: 'MultiPolygon',
coordinates: geometry.getCoordinates(right) coordinates: geometry.getCoordinates(right)
}); });
}; }
/** /**
* @param {ol.geom.Point} geometry Geometry. * @param {ol.geom.Point} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options. * @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
GeoJSON.writePointGeometry_ = function(geometry, opt_options) { function writePointGeometry(geometry, opt_options) {
return /** @type {GeoJSONGeometry} */ ({ return /** @type {GeoJSONGeometry} */ ({
type: 'Point', type: 'Point',
coordinates: geometry.getCoordinates() coordinates: geometry.getCoordinates()
}); });
}; }
/** /**
* @param {ol.geom.Polygon} geometry Geometry. * @param {ol.geom.Polygon} geometry Geometry.
* @param {olx.format.WriteOptions=} opt_options Write options. * @param {olx.format.WriteOptions=} opt_options Write options.
* @private
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
GeoJSON.writePolygonGeometry_ = function(geometry, opt_options) { function writePolygonGeometry(geometry, opt_options) {
var right; var right;
if (opt_options) { if (opt_options) {
right = opt_options.rightHanded; right = opt_options.rightHanded;
@@ -299,7 +280,7 @@ GeoJSON.writePolygonGeometry_ = function(geometry, opt_options) {
type: 'Polygon', type: 'Polygon',
coordinates: geometry.getCoordinates(right) coordinates: geometry.getCoordinates(right)
}); });
}; }
/** /**
@@ -308,13 +289,13 @@ GeoJSON.writePolygonGeometry_ = function(geometry, opt_options) {
* @type {Object.<string, function(GeoJSONObject): ol.geom.Geometry>} * @type {Object.<string, function(GeoJSONObject): ol.geom.Geometry>}
*/ */
GeoJSON.GEOMETRY_READERS_ = { GeoJSON.GEOMETRY_READERS_ = {
'Point': GeoJSON.readPointGeometry_, 'Point': readPointGeometry,
'LineString': GeoJSON.readLineStringGeometry_, 'LineString': readLineStringGeometry,
'Polygon': GeoJSON.readPolygonGeometry_, 'Polygon': readPolygonGeometry,
'MultiPoint': GeoJSON.readMultiPointGeometry_, 'MultiPoint': readMultiPointGeometry,
'MultiLineString': GeoJSON.readMultiLineStringGeometry_, 'MultiLineString': readMultiLineStringGeometry,
'MultiPolygon': GeoJSON.readMultiPolygonGeometry_, 'MultiPolygon': readMultiPolygonGeometry,
'GeometryCollection': GeoJSON.readGeometryCollectionGeometry_ 'GeometryCollection': readGeometryCollectionGeometry
}; };
@@ -324,14 +305,14 @@ GeoJSON.GEOMETRY_READERS_ = {
* @type {Object.<string, function(ol.geom.Geometry, olx.format.WriteOptions=): (GeoJSONGeometry|GeoJSONGeometryCollection)>} * @type {Object.<string, function(ol.geom.Geometry, olx.format.WriteOptions=): (GeoJSONGeometry|GeoJSONGeometryCollection)>}
*/ */
GeoJSON.GEOMETRY_WRITERS_ = { GeoJSON.GEOMETRY_WRITERS_ = {
'Point': GeoJSON.writePointGeometry_, 'Point': writePointGeometry,
'LineString': GeoJSON.writeLineStringGeometry_, 'LineString': writeLineStringGeometry,
'Polygon': GeoJSON.writePolygonGeometry_, 'Polygon': writePolygonGeometry,
'MultiPoint': GeoJSON.writeMultiPointGeometry_, 'MultiPoint': writeMultiPointGeometry,
'MultiLineString': GeoJSON.writeMultiLineStringGeometry_, 'MultiLineString': writeMultiLineStringGeometry,
'MultiPolygon': GeoJSON.writeMultiPolygonGeometry_, 'MultiPolygon': writeMultiPolygonGeometry,
'GeometryCollection': GeoJSON.writeGeometryCollectionGeometry_, 'GeometryCollection': writeGeometryCollectionGeometry,
'Circle': GeoJSON.writeEmptyGeometryCollectionGeometry_ 'Circle': writeEmptyGeometryCollectionGeometry
}; };
@@ -367,8 +348,7 @@ GeoJSON.prototype.readFeatures;
/** /**
* @inheritDoc * @inheritDoc
*/ */
GeoJSON.prototype.readFeatureFromObject = function( GeoJSON.prototype.readFeatureFromObject = function(object, opt_options) {
object, opt_options) {
/** /**
* @type {GeoJSONFeature} * @type {GeoJSONFeature}
*/ */
@@ -382,7 +362,7 @@ GeoJSON.prototype.readFeatureFromObject = function(
}); });
} }
var geometry = GeoJSON.readGeometry_(geoJSONFeature.geometry, opt_options); var geometry = readGeometry(geoJSONFeature.geometry, opt_options);
var feature = new _ol_Feature_(); var feature = new _ol_Feature_();
if (this.geometryName_) { if (this.geometryName_) {
feature.setGeometryName(this.geometryName_); feature.setGeometryName(this.geometryName_);
@@ -403,8 +383,7 @@ GeoJSON.prototype.readFeatureFromObject = function(
/** /**
* @inheritDoc * @inheritDoc
*/ */
GeoJSON.prototype.readFeaturesFromObject = function( GeoJSON.prototype.readFeaturesFromObject = function(object, opt_options) {
object, opt_options) {
var geoJSONObject = /** @type {GeoJSONObject} */ (object); var geoJSONObject = /** @type {GeoJSONObject} */ (object);
/** @type {Array.<ol.Feature>} */ /** @type {Array.<ol.Feature>} */
var features = null; var features = null;
@@ -440,10 +419,8 @@ GeoJSON.prototype.readGeometry;
/** /**
* @inheritDoc * @inheritDoc
*/ */
GeoJSON.prototype.readGeometryFromObject = function( GeoJSON.prototype.readGeometryFromObject = function(object, opt_options) {
object, opt_options) { return readGeometry(/** @type {GeoJSONGeometry} */ (object), opt_options);
return GeoJSON.readGeometry_(
/** @type {GeoJSONGeometry} */ (object), opt_options);
}; };
@@ -512,8 +489,7 @@ GeoJSON.prototype.writeFeatureObject = function(feature, opt_options) {
} }
var geometry = feature.getGeometry(); var geometry = feature.getGeometry();
if (geometry) { if (geometry) {
object.geometry = object.geometry = writeGeometry(geometry, opt_options);
GeoJSON.writeGeometry_(geometry, opt_options);
} else { } else {
object.geometry = null; object.geometry = null;
} }
@@ -584,9 +560,7 @@ GeoJSON.prototype.writeGeometry;
* @override * @override
* @api * @api
*/ */
GeoJSON.prototype.writeGeometryObject = function(geometry, GeoJSON.prototype.writeGeometryObject = function(geometry, opt_options) {
opt_options) { return writeGeometry(geometry, this.adaptOptions(opt_options));
return GeoJSON.writeGeometry_(geometry,
this.adaptOptions(opt_options));
}; };
export default GeoJSON; export default GeoJSON;