KML MultiGeometry may contain other MultiGeometry

As demonstrated in the tests, a MultiGeometry may contain other MultiGeometry nodes.  We can support this with heterogenous GeometryCollection instances - though these are not currently rendered.
This commit is contained in:
Tim Schaub
2013-06-26 12:31:08 -06:00
parent 30d947521d
commit 42aa94de21
3 changed files with 4723 additions and 5 deletions

View File

@@ -184,24 +184,25 @@ ol.parser.KML = function(opt_options) {
var buckets = goog.array.bucket(parts, function(val) {
return val.type;
});
// homogeneous collection
var obj = {};
if (goog.object.getCount(buckets) === 1) {
// homogeneous collection
var type = goog.object.getAnyKey(buckets);
switch (type) {
case ol.geom.GeometryType.POINT:
container.geometry = {
obj.geometry = {
type: ol.geom.GeometryType.MULTIPOINT,
parts: parts
};
break;
case ol.geom.GeometryType.LINESTRING:
container.geometry = {
obj.geometry = {
type: ol.geom.GeometryType.MULTILINESTRING,
parts: parts
};
break;
case ol.geom.GeometryType.POLYGON:
container.geometry = {
obj.geometry = {
type: ol.geom.GeometryType.MULTIPOLYGON,
parts: parts
};
@@ -210,11 +211,18 @@ ol.parser.KML = function(opt_options) {
break;
}
} else {
container.geometry = {
// mixed collection
obj.geometry = {
type: ol.geom.GeometryType.GEOMETRYCOLLECTION,
parts: parts
};
}
if (goog.isArray(container)) {
// MultiGeometry nested inside another
container.push(obj.geometry);
} else {
container.geometry = obj.geometry;
}
},
'Point': function(node, container) {
var coordinates = [];