Support GeoJSON as parsed object
With this change, we can programmatically create GeoJSONFeatureCollection objects programmatically, without reading a GeoJSON file.
This commit is contained in:
@@ -323,6 +323,10 @@ ol.layer.Vector.prototype.parseFeatures = function(data, parser, projection) {
|
|||||||
goog.asserts.assert(typeof parser.readFeaturesFromString === 'function',
|
goog.asserts.assert(typeof parser.readFeaturesFromString === 'function',
|
||||||
'Expected a parser with readFeaturesFromString method.');
|
'Expected a parser with readFeaturesFromString method.');
|
||||||
features = parser.readFeaturesFromString(data, {callback: callback});
|
features = parser.readFeaturesFromString(data, {callback: callback});
|
||||||
|
} else if (typeof data === 'object') {
|
||||||
|
goog.asserts.assert(typeof parser.readFeaturesFromObject === 'function',
|
||||||
|
'Expected a parser with a readFeaturesFromObject method.');
|
||||||
|
features = parser.readFeaturesFromObject(data, {callback: callback});
|
||||||
} else {
|
} else {
|
||||||
// TODO: parse more data types
|
// TODO: parse more data types
|
||||||
throw new Error('Data type not supported: ' + data);
|
throw new Error('Data type not supported: ' + data);
|
||||||
|
|||||||
@@ -51,6 +51,19 @@ 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 {Array.<ol.Feature>} Array of features.
|
||||||
|
*/
|
||||||
|
ol.parser.GeoJSON.prototype.readFeaturesFromObject =
|
||||||
|
function(object, opt_options) {
|
||||||
|
return this.parseFeatureCollection_(object, opt_options);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {GeoJSONObject} json GeoJSON object.
|
* @param {GeoJSONObject} json GeoJSON object.
|
||||||
* @return {ol.Feature|Array.<ol.Feature>|
|
* @return {ol.Feature|Array.<ol.Feature>|
|
||||||
|
|||||||
Reference in New Issue
Block a user