diff --git a/src/ol/structs/rbush.js b/src/ol/structs/rbush.js index e7092bc516..f7c650aa8c 100644 --- a/src/ol/structs/rbush.js +++ b/src/ol/structs/rbush.js @@ -65,6 +65,36 @@ ol.structs.RBush.prototype.insert = function(extent, value) { }; +/** + * Bulk-insert values into the RBush. + * @param {Array.} extents Extents. + * @param {Array.} values Values. + */ +ol.structs.RBush.prototype.load = function(extents, values) { + if (goog.DEBUG && this.readers_) { + throw new Error('Can not insert values while reading'); + } + goog.asserts.assert(extents.length === values.length); + + var items = []; + for (var i = 0, l = values.length; i < l; i++) { + var extent = extents[i]; + var value = values[i]; + + var item = [ + extent[0], + extent[1], + extent[2], + extent[3], + value + ]; + items.push(item); + goog.object.add(this.items_, goog.getUid(value).toString(), item); + } + this.rbush_.load(items); +}; + + /** * Remove a value from the RBush. * @param {T} value Value.