Permalink
Browse files

GeometryCollections are now maintained

  • Loading branch information...
1 parent 81849ad commit 48a38e411fa2e64f527ca36572db93e3343d4da8 @tnightingale committed Nov 3, 2012
Showing with 27 additions and 1 deletion.
  1. +27 −1 src/layer/FeatureGroup.js
@@ -17,7 +17,33 @@ L.FeatureGroup.include({
};
},
+ // TODO: Refactor this so we don't require two passes.
+ isCollection: function () {
+ var is_collection = false,
+ geoms = [];
+
+ this.eachLayer(function (layer) {
+ if (!is_collection && layer.toGeometry().type !== "Point") {
+ is_collection = true;
+ }
+ });
+
+ return is_collection;
+ },
+
toGeoJSON: function () {
- return L.GeoJSONUtil.feature(this.toGeometry());
+ if (this.isCollection()) {
+ var geoms = [];
+ this.eachLayer(function (layer) {
+ geoms.push(layer.toGeometry());
+ });
+ return {
+ type: "GeometryCollection",
+ geometries: geoms
+ };
+ }
+ else {
+ return L.GeoJSONUtil.feature(this.toGeometry());
+ }
}
});

0 comments on commit 48a38e4

Please sign in to comment.