Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support GeoJSON as parsed object

With this change, we can programmatically create
GeoJSONFeatureCollection objects programmatically, without
reading a GeoJSON file.
  • Loading branch information...
commit 389b8d14d7aa8e0508782a6f9780981c64a1972f 1 parent 7f62b26
@ahocevar ahocevar authored
Showing with 17 additions and 0 deletions.
  1. +4 −0 src/ol/layer/vectorlayer.js
  2. +13 −0 src/ol/parser/geojson.js
View
4 src/ol/layer/vectorlayer.js
@@ -323,6 +323,10 @@ ol.layer.Vector.prototype.parseFeatures = function(data, parser, projection) {
goog.asserts.assert(typeof parser.readFeaturesFromString === 'function',
'Expected a parser with readFeaturesFromString method.');
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 {
// TODO: parse more data types
throw new Error('Data type not supported: ' + data);
View
13 src/ol/parser/geojson.js
@@ -52,6 +52,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.
* @return {ol.Feature|Array.<ol.Feature>|
* ol.geom.Geometry|Array.<ol.geom.Geometry>} Parsed geometry or array
Please sign in to comment.
Something went wrong with that request. Please try again.