diff --git a/src/ol/structs/rbush.js b/src/ol/structs/rbush.js index 25437e1056..349631748f 100644 --- a/src/ol/structs/rbush.js +++ b/src/ol/structs/rbush.js @@ -555,6 +555,7 @@ ol.structs.RBush.prototype.insert = function(extent, value) { var key = this.getKey_(value); goog.asserts.assert(!this.valueExtent_.hasOwnProperty(key)); this.insert_(extent, value, this.root_.height - 1); + this.valueExtent_[key] = ol.extent.clone(extent); }; @@ -582,8 +583,6 @@ ol.structs.RBush.prototype.insert_ = function(extent, value, level) { for (; i >= 0; --i) { ol.extent.extend(path[i].extent, extent); } - var key = this.getKey_(value); - this.valueExtent_[key] = ol.extent.clone(extent); return node; }; @@ -715,6 +714,6 @@ ol.structs.RBush.prototype.update = function(extent, value) { if (!ol.extent.equals(currentExtent, extent)) { this.remove_(currentExtent, value); this.insert_(extent, value, this.root_.height - 1); - ol.extent.clone(extent, currentExtent); + this.valueExtent_[key] = ol.extent.clone(extent, currentExtent); } }; diff --git a/test/spec/ol/structs/rbush.test.js b/test/spec/ol/structs/rbush.test.js index 044811e6eb..bb2f78c62f 100644 --- a/test/spec/ol/structs/rbush.test.js +++ b/test/spec/ol/structs/rbush.test.js @@ -28,6 +28,24 @@ describe('ol.structs.RBush', function() { }); + describe('with a single object', function() { + + var obj; + beforeEach(function() { + obj = {}; + rBush.insert([0, 0, 1, 1], obj); + }); + + it('can update the object', function() { + expect(rBush.getAllInExtent([0, 0, 1, 1])).to.eql([obj]); + rBush.update([2, 2, 3, 3], obj); + expect(rBush.getAllInExtent([0, 0, 1, 1])).to.be.empty(); + expect(rBush.getAll()).to.eql([obj]); + expect(rBush.getAllInExtent([2, 2, 3, 3])).to.eql([obj]); + }); + + }); + describe('with a few objects', function() { var objs;