Only update the rbush item if the extent has changed

This commit is contained in:
Frederic Junod
2015-01-14 10:40:56 +01:00
parent 017ff47bf8
commit baf424f99c
2 changed files with 20 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.object');
goog.require('ol.ext.rbush');
goog.require('ol.extent');
@@ -123,8 +124,17 @@ ol.structs.RBush.prototype.remove = function(value) {
* @param {T} value Value.
*/
ol.structs.RBush.prototype.update = function(extent, value) {
this.remove(value);
this.insert(extent, value);
var uid = goog.getUid(value);
goog.asserts.assert(goog.object.containsKey(this.items_, uid));
var item = this.items_[uid];
if (!ol.extent.equals(item.slice(0, 4), extent)) {
if (goog.DEBUG && this.readers_) {
throw new Error('Can not update extent while reading');
}
this.remove(value);
this.insert(extent, value);
}
};