GeometryCollection as individual features
This commit is contained in:
@@ -26,7 +26,7 @@ TopoJSONTopology.prototype.transform;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Object.<string, TopoJSONGeometry>}
|
* @type {Object.<string, (TopoJSONGeometry|TopoJSONGeometryCollection)>}
|
||||||
*/
|
*/
|
||||||
TopoJSONTopology.prototype.objects;
|
TopoJSONTopology.prototype.objects;
|
||||||
|
|
||||||
@@ -76,6 +76,19 @@ TopoJSONGeometry.prototype.id;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
var TopoJSONGeometryCollection = function() {};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Array.<TopoJSONGeometry>}
|
||||||
|
*/
|
||||||
|
TopoJSONGeometryCollection.prototype.geometries;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {TopoJSONGeometry}
|
* @extends {TopoJSONGeometry}
|
||||||
|
|||||||
@@ -144,6 +144,31 @@ ol.parser.TopoJSON.prototype.readFeatureFromGeometry_ = function(object, arcs,
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create features from a TopoJSON GeometryCollection object.
|
||||||
|
*
|
||||||
|
* @param {TopoJSONGeometryCollection} collection TopoJSON GeometryCollection
|
||||||
|
* object.
|
||||||
|
* @param {Array.<ol.geom.VertexArray>} arcs Array of arcs.
|
||||||
|
* @param {Array.<number>} scale Scale for each dimension.
|
||||||
|
* @param {Array.<number>} translate Translation for each dimension.
|
||||||
|
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||||
|
* @return {Array.<ol.Feature>} Array of features.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.parser.TopoJSON.prototype.readFeaturesFromGeometryCollection_ = function(
|
||||||
|
collection, arcs, scale, translate, opt_options) {
|
||||||
|
var geometries = collection.geometries;
|
||||||
|
var num = geometries.length;
|
||||||
|
var features = new Array(num);
|
||||||
|
for (var i = 0; i < num; ++i) {
|
||||||
|
features[i] = this.readFeatureFromGeometry_(geometries[i], arcs, scale,
|
||||||
|
translate, opt_options);
|
||||||
|
}
|
||||||
|
return features;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {TopoJSONTopology} topology TopoJSON object.
|
* @param {TopoJSONTopology} topology TopoJSON object.
|
||||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||||
@@ -160,8 +185,15 @@ ol.parser.TopoJSON.prototype.readFeaturesFromTopology_ = function(
|
|||||||
var objects = topology.objects;
|
var objects = topology.objects;
|
||||||
var features = [];
|
var features = [];
|
||||||
for (var key in objects) {
|
for (var key in objects) {
|
||||||
features.push(this.readFeatureFromGeometry_(objects[key], arcs, scale,
|
if (objects[key].type === 'GeometryCollection') {
|
||||||
translate, opt_options));
|
features.push.apply(features, this.readFeaturesFromGeometryCollection_(
|
||||||
|
/** @type {TopoJSONGeometryCollection} */ (objects[key]),
|
||||||
|
arcs, scale, translate, opt_options));
|
||||||
|
} else {
|
||||||
|
features.push(this.readFeatureFromGeometry_(
|
||||||
|
/** @type {TopoJSONGeometry} */ (objects[key]),
|
||||||
|
arcs, scale, translate, opt_options));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return features;
|
return features;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user