From b2c822c9caed0ca5057afe01a75c036855a102f9 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 19 Dec 2013 13:36:21 +0100 Subject: [PATCH] Clear null geometry features in ol.source.Vector#clear --- src/ol/source/vectorsource.js | 4 ++++ test/spec/ol/source/vectorsource.test.js | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ol/source/vectorsource.js b/src/ol/source/vectorsource.js index 9d6016973f..a69c70ca6d 100644 --- a/src/ol/source/vectorsource.js +++ b/src/ol/source/vectorsource.js @@ -130,6 +130,10 @@ ol.source.Vector.prototype.addFeaturesInternal = function(features) { ol.source.Vector.prototype.clear = function() { this.rBush_.forEach(this.removeFeatureInternal, this); this.rBush_.clear(); + goog.object.forEach( + this.nullGeometryFeatures_, this.removeFeatureInternal, this); + goog.object.clear(this.nullGeometryFeatures_); + goog.asserts.assert(goog.object.isEmpty(this.featureChangeKeys_)); this.dispatchChangeEvent(); }; diff --git a/test/spec/ol/source/vectorsource.test.js b/test/spec/ol/source/vectorsource.test.js index 7037c86bbc..975a793af6 100644 --- a/test/spec/ol/source/vectorsource.test.js +++ b/test/spec/ol/source/vectorsource.test.js @@ -66,7 +66,7 @@ describe('ol.source.Vector', function() { }); - describe('when populated with 10 random points', function() { + describe('when populated with 10 random points and a null', function() { var features; var vectorSource; @@ -77,6 +77,7 @@ describe('ol.source.Vector', function() { features[i] = new ol.Feature(new ol.geom.Point([Math.random(), Math.random()])); } + features.push(new ol.Feature(null)); vectorSource = new ol.source.Vector({ features: features }); @@ -95,7 +96,7 @@ describe('ol.source.Vector', function() { expect(changeSpy).to.be.called(); expect(changeSpy.callCount).to.be(1); expect(removeFeatureSpy).to.be.called(); - expect(removeFeatureSpy.callCount).to.be(10); + expect(removeFeatureSpy.callCount).to.be(features.length); }); });