diff --git a/src/ol/geom/Collection.js b/src/ol/geom/Collection.js index 28e4cd356e..5bcb9b2a98 100644 --- a/src/ol/geom/Collection.js +++ b/src/ol/geom/Collection.js @@ -28,7 +28,12 @@ ol.geom.Collection = function(components) { * @private * @type {Array.} */ - this.typeWhitelist_ = []; + this.typeWhitelist_ = [ + ol.geom.MultiPoint, + ol.geom.MultiLineString + // TODO uncomment when implemented + // ,ol.geom.MultiPolygon + ]; /** * @private diff --git a/test/spec/api/geom/collection.test.js b/test/spec/api/geom/collection.test.js index fffce6fe40..69c2c67fd3 100644 --- a/test/spec/api/geom/collection.test.js +++ b/test/spec/api/geom/collection.test.js @@ -51,6 +51,28 @@ describe("ol.geom.collection", function() { expect( firstComponent.x() + ',' + firstComponent.y() ).toBe( '24,7' ); }); + it("cannot add 'ol.geom.collection'", function(){ + expect(function(){ + c.add( + ol.geom.collection([ + ol.geom.point([5,25]), + ol.geom.point([6,36]) + ]) + ); + }).toThrow(); + }); + + it("allows 'ol.geom.multi*' (even though these are technically of ol.geom.collections)", function(){ + expect(function(){ + c.add( + ol.geom.multipoint([ + ol.geom.point([5,25]), + ol.geom.point([6,36]) + ]) + ); + }).not.toThrow(); + }); + it("the index is functional", function(){ var p = ol.geom.point([24,7]); c.add(p, 1); diff --git a/test/spec/ol/geom/Collection.test.js b/test/spec/ol/geom/Collection.test.js index fd5e63ec93..a30d9098b6 100644 --- a/test/spec/ol/geom/Collection.test.js +++ b/test/spec/ol/geom/Collection.test.js @@ -113,6 +113,17 @@ describe("ol.geom.Collection", function() { }).toThrow(); }); + it("allows instances of 'ol.geom.Multi*' (even though these are subclasses of ol.geom.Collection)", function(){ + expect(function(){ + c.addComponent( + new ol.geom.MultiPoint([ + new ol.geom.Point(5,25), + new ol.geom.Point(6,36) + ]) + ); + }).not.toThrow(); + }); + it("has a method to remove components", function() { c.setComponents([ new ol.geom.Point(0,10),