Remove use of shared structures in feature parsers
This commit is contained in:
@@ -12,9 +12,7 @@ goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.geom.SharedVertices');
|
||||
goog.require('ol.parser.Parser');
|
||||
goog.require('ol.parser.ReadFeaturesOptions');
|
||||
goog.require('ol.parser.ReadFeaturesResult');
|
||||
goog.require('ol.parser.StringFeatureParser');
|
||||
|
||||
@@ -60,13 +58,11 @@ ol.parser.GeoJSON.read = function(str) {
|
||||
/**
|
||||
* Parse a GeoJSON feature collection.
|
||||
* @param {string} str GeoJSON feature collection.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.readFeaturesFromString =
|
||||
function(str, opt_options) {
|
||||
ol.parser.GeoJSON.prototype.readFeaturesFromString = function(str) {
|
||||
var json = /** @type {GeoJSONFeatureCollection} */ (JSON.parse(str));
|
||||
return this.parseAsFeatureCollection_(json, opt_options);
|
||||
return this.parseAsFeatureCollection_(json);
|
||||
};
|
||||
|
||||
|
||||
@@ -74,43 +70,38 @@ ol.parser.GeoJSON.prototype.readFeaturesFromString =
|
||||
* Parse a GeoJSON feature collection from decoded JSON.
|
||||
* @param {GeoJSONFeatureCollection} object GeoJSON feature collection decoded
|
||||
* from JSON.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.readFeaturesFromObject =
|
||||
function(object, opt_options) {
|
||||
return this.parseAsFeatureCollection_(object, opt_options);
|
||||
ol.parser.GeoJSON.prototype.readFeaturesFromObject = function(object) {
|
||||
return this.parseAsFeatureCollection_(object);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse any GeoJSON object. Note that this method should not be called
|
||||
* recursively due to the shared vertex creation.
|
||||
* Parse any GeoJSON object.
|
||||
*
|
||||
* @param {GeoJSONObject} json GeoJSON object.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {ol.Feature|Array.<ol.Feature>|
|
||||
* ol.geom.Geometry|Array.<ol.geom.Geometry>} Parsed geometry or array
|
||||
* of geometries.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parse_ = function(json, opt_options) {
|
||||
ol.parser.GeoJSON.prototype.parse_ = function(json) {
|
||||
var result;
|
||||
if (json.type === 'FeatureCollection') {
|
||||
result = this.parseFeatureCollection_(
|
||||
/** @type {GeoJSONFeatureCollection} */ (json), opt_options);
|
||||
/** @type {GeoJSONFeatureCollection} */ (json));
|
||||
} else if (json.type === 'Feature') {
|
||||
result = this.parseFeature_(
|
||||
/** @type {GeoJSONFeature} */ (json), opt_options);
|
||||
/** @type {GeoJSONFeature} */ (json));
|
||||
} else if (json.type === 'GeometryCollection') {
|
||||
result = this.parseGeometryCollection_(
|
||||
/** @type {GeoJSONGeometryCollection} */ (json), opt_options);
|
||||
/** @type {GeoJSONGeometryCollection} */ (json));
|
||||
} else {
|
||||
// we've been called with a geometry or an unknown object
|
||||
// create a feature to get shared vertices handling
|
||||
var feature = this.parseFeature_(
|
||||
/** @type {GeoJSONFeature} */ ({type: 'Feature', geometry: json}),
|
||||
opt_options);
|
||||
/** @type {GeoJSONFeature} */ ({type: 'Feature', geometry: json}));
|
||||
result = feature.getGeometry();
|
||||
}
|
||||
return result;
|
||||
@@ -119,14 +110,12 @@ ol.parser.GeoJSON.prototype.parse_ = function(json, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {GeoJSONObject} json GeoJSON object.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {ol.parser.ReadFeaturesResult} Parsed object coerced into array of
|
||||
* features.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseAsFeatureCollection_ = function(json,
|
||||
opt_options) {
|
||||
var obj = this.parse_(json, opt_options);
|
||||
ol.parser.GeoJSON.prototype.parseAsFeatureCollection_ = function(json) {
|
||||
var obj = this.parse_(json);
|
||||
var features = [];
|
||||
var feature;
|
||||
if (obj instanceof ol.Feature) {
|
||||
@@ -164,45 +153,36 @@ ol.parser.GeoJSON.prototype.parseAsFeatureCollection_ = function(json,
|
||||
|
||||
/**
|
||||
* @param {GeoJSONFeature} json GeoJSON feature.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Read options.
|
||||
* @return {ol.Feature} Parsed feature.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseFeature_ = function(json, opt_options) {
|
||||
ol.parser.GeoJSON.prototype.parseFeature_ = function(json) {
|
||||
var geomJson = json.geometry,
|
||||
geometry = null,
|
||||
options = opt_options || {};
|
||||
geometry = null;
|
||||
var feature = new ol.Feature(json.properties);
|
||||
if (goog.isDef(json.id)) {
|
||||
feature.setId(json.id);
|
||||
}
|
||||
if (geomJson) {
|
||||
var type = geomJson.type;
|
||||
var callback = options.callback;
|
||||
var sharedVertices;
|
||||
if (callback) {
|
||||
goog.asserts.assert(type in ol.parser.GeoJSON.GeometryType,
|
||||
'Bad geometry type: ' + type);
|
||||
sharedVertices = callback(feature, ol.parser.GeoJSON.GeometryType[type]);
|
||||
}
|
||||
switch (type) {
|
||||
case 'Point':
|
||||
geometry = this.parsePoint_(geomJson, sharedVertices);
|
||||
geometry = this.parsePoint_(geomJson);
|
||||
break;
|
||||
case 'LineString':
|
||||
geometry = this.parseLineString_(geomJson, sharedVertices);
|
||||
geometry = this.parseLineString_(geomJson);
|
||||
break;
|
||||
case 'Polygon':
|
||||
geometry = this.parsePolygon_(geomJson, sharedVertices);
|
||||
geometry = this.parsePolygon_(geomJson);
|
||||
break;
|
||||
case 'MultiPoint':
|
||||
geometry = this.parseMultiPoint_(geomJson, sharedVertices);
|
||||
geometry = this.parseMultiPoint_(geomJson);
|
||||
break;
|
||||
case 'MultiLineString':
|
||||
geometry = this.parseMultiLineString_(geomJson, sharedVertices);
|
||||
geometry = this.parseMultiLineString_(geomJson);
|
||||
break;
|
||||
case 'MultiPolygon':
|
||||
geometry = this.parseMultiPolygon_(geomJson, sharedVertices);
|
||||
geometry = this.parseMultiPolygon_(geomJson);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Bad geometry type: ' + type);
|
||||
@@ -215,20 +195,17 @@ ol.parser.GeoJSON.prototype.parseFeature_ = function(json, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {GeoJSONFeatureCollection} json GeoJSON feature collection.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Read options.
|
||||
* @return {Array.<ol.Feature>} Parsed array of features.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseFeatureCollection_ = function(
|
||||
json, opt_options) {
|
||||
ol.parser.GeoJSON.prototype.parseFeatureCollection_ = function(json) {
|
||||
var features = json.features,
|
||||
len = features.length,
|
||||
result = new Array(len),
|
||||
i;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
result[i] = this.parseFeature_(
|
||||
/** @type {GeoJSONFeature} */ (features[i]), opt_options);
|
||||
result[i] = this.parseFeature_(/** @type {GeoJSONFeature} */ (features[i]));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@@ -236,20 +213,17 @@ ol.parser.GeoJSON.prototype.parseFeatureCollection_ = function(
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometryCollection} json GeoJSON geometry collection.
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Read options.
|
||||
* @return {Array.<ol.geom.Geometry>} Parsed array of geometries.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseGeometryCollection_ = function(json,
|
||||
opt_options) {
|
||||
ol.parser.GeoJSON.prototype.parseGeometryCollection_ = function(json) {
|
||||
var geometries = json.geometries,
|
||||
len = geometries.length,
|
||||
result = new Array(len),
|
||||
i;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
result[i] = this.parse_(/** @type {GeoJSONGeometry} */ (geometries[i]),
|
||||
opt_options);
|
||||
result[i] = this.parse_(/** @type {GeoJSONGeometry} */ (geometries[i]));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@@ -257,68 +231,61 @@ ol.parser.GeoJSON.prototype.parseGeometryCollection_ = function(json,
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} json GeoJSON linestring.
|
||||
* @param {ol.geom.SharedVertices=} opt_vertices Shared vertices.
|
||||
* @return {ol.geom.LineString} Parsed linestring.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseLineString_ = function(json, opt_vertices) {
|
||||
return new ol.geom.LineString(json.coordinates, opt_vertices);
|
||||
ol.parser.GeoJSON.prototype.parseLineString_ = function(json) {
|
||||
return new ol.geom.LineString(json.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} json GeoJSON multi-linestring.
|
||||
* @param {ol.geom.SharedVertices=} opt_vertices Shared vertices.
|
||||
* @return {ol.geom.MultiLineString} Parsed multi-linestring.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseMultiLineString_ = function(
|
||||
json, opt_vertices) {
|
||||
return new ol.geom.MultiLineString(json.coordinates, opt_vertices);
|
||||
ol.parser.GeoJSON.prototype.parseMultiLineString_ = function(json) {
|
||||
return new ol.geom.MultiLineString(json.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} json GeoJSON multi-point.
|
||||
* @param {ol.geom.SharedVertices=} opt_vertices Shared vertices.
|
||||
* @return {ol.geom.MultiPoint} Parsed multi-point.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseMultiPoint_ = function(json, opt_vertices) {
|
||||
return new ol.geom.MultiPoint(json.coordinates, opt_vertices);
|
||||
ol.parser.GeoJSON.prototype.parseMultiPoint_ = function(json) {
|
||||
return new ol.geom.MultiPoint(json.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} json GeoJSON multi-polygon.
|
||||
* @param {ol.geom.SharedVertices=} opt_vertices Shared vertices.
|
||||
* @return {ol.geom.MultiPolygon} Parsed multi-polygon.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseMultiPolygon_ = function(json, opt_vertices) {
|
||||
return new ol.geom.MultiPolygon(json.coordinates, opt_vertices);
|
||||
ol.parser.GeoJSON.prototype.parseMultiPolygon_ = function(json) {
|
||||
return new ol.geom.MultiPolygon(json.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} json GeoJSON point.
|
||||
* @param {ol.geom.SharedVertices=} opt_vertices Shared vertices.
|
||||
* @return {ol.geom.Point} Parsed point.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parsePoint_ = function(json, opt_vertices) {
|
||||
return new ol.geom.Point(json.coordinates, opt_vertices);
|
||||
ol.parser.GeoJSON.prototype.parsePoint_ = function(json) {
|
||||
return new ol.geom.Point(json.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} json GeoJSON polygon.
|
||||
* @param {ol.geom.SharedVertices=} opt_vertices Shared vertices.
|
||||
* @return {ol.geom.Polygon} Parsed polygon.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parsePolygon_ = function(json, opt_vertices) {
|
||||
return new ol.geom.Polygon(json.coordinates, opt_vertices);
|
||||
ol.parser.GeoJSON.prototype.parsePolygon_ = function(json) {
|
||||
return new ol.geom.Polygon(json.coordinates);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user