Remove type filter hack from ol.structs.RTree
This commit is contained in:
+12
-25
@@ -35,8 +35,7 @@ goog.require('ol.extent');
|
|||||||
* @typedef {{extent: ol.Extent,
|
* @typedef {{extent: ol.Extent,
|
||||||
* leaf: (Object|undefined),
|
* leaf: (Object|undefined),
|
||||||
* nodes: (Array.<ol.structs.RTreeNode>|undefined),
|
* nodes: (Array.<ol.structs.RTreeNode>|undefined),
|
||||||
* target: (Object|undefined),
|
* target: (Object|undefined)}}
|
||||||
* type: (string|number|undefined)}}
|
|
||||||
*/
|
*/
|
||||||
ol.structs.RTreeNode;
|
ol.structs.RTreeNode;
|
||||||
|
|
||||||
@@ -186,15 +185,10 @@ ol.structs.RTree.prototype.chooseLeafSubtree_ = function(rect, root) {
|
|||||||
*
|
*
|
||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
* @param {Object} obj Object to insert.
|
* @param {Object} obj Object to insert.
|
||||||
* @param {string|number=} opt_type Optional type to store along with the
|
|
||||||
* object.
|
|
||||||
*/
|
*/
|
||||||
ol.structs.RTree.prototype.insert = function(extent, obj, opt_type) {
|
ol.structs.RTree.prototype.insert = function(extent, obj) {
|
||||||
var node = /** @type {ol.structs.RTreeNode} */
|
var node = /** @type {ol.structs.RTreeNode} */
|
||||||
({extent: extent, leaf: obj});
|
({extent: extent, leaf: obj});
|
||||||
if (goog.isDef(opt_type)) {
|
|
||||||
node.type = opt_type;
|
|
||||||
}
|
|
||||||
this.insertSubtree_(node, this.rootTree_);
|
this.insertSubtree_(node, this.rootTree_);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -555,15 +549,13 @@ ol.structs.RTree.prototype.removeSubtree_ = function(rect, obj, root) {
|
|||||||
* Non-recursive search function
|
* Non-recursive search function
|
||||||
*
|
*
|
||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
* @param {string|number=} opt_type Optional type of the objects we want to
|
|
||||||
* find.
|
|
||||||
* @return {Array} Result.
|
* @return {Array} Result.
|
||||||
* @this {ol.structs.RTree}
|
* @this {ol.structs.RTree}
|
||||||
*/
|
*/
|
||||||
ol.structs.RTree.prototype.search = function(extent, opt_type) {
|
ol.structs.RTree.prototype.search = function(extent) {
|
||||||
var rect = /** @type {ol.structs.RTreeNode} */ ({extent: extent});
|
var rect = /** @type {ol.structs.RTreeNode} */ ({extent: extent});
|
||||||
return /** @type {Array} */ (
|
return /** @type {Array} */ (
|
||||||
this.searchSubtree_(rect, false, [], this.rootTree_, opt_type));
|
this.searchSubtree_(rect, false, [], this.rootTree_));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -571,15 +563,13 @@ ol.structs.RTree.prototype.search = function(extent, opt_type) {
|
|||||||
* Non-recursive search function
|
* Non-recursive search function
|
||||||
*
|
*
|
||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
* @param {string|number=} opt_type Optional type of the objects we want to
|
|
||||||
* find.
|
|
||||||
* @return {Object} Result. Keys are UIDs of the values.
|
* @return {Object} Result. Keys are UIDs of the values.
|
||||||
* @this {ol.structs.RTree}
|
* @this {ol.structs.RTree}
|
||||||
*/
|
*/
|
||||||
ol.structs.RTree.prototype.searchReturningObject = function(extent, opt_type) {
|
ol.structs.RTree.prototype.searchReturningObject = function(extent) {
|
||||||
var rect = /** @type {ol.structs.RTreeNode} */ ({extent: extent});
|
var rect = /** @type {ol.structs.RTreeNode} */ ({extent: extent});
|
||||||
return /** @type {Object} */ (
|
return /** @type {Object} */ (
|
||||||
this.searchSubtree_(rect, false, [], this.rootTree_, opt_type, true));
|
this.searchSubtree_(rect, false, [], this.rootTree_, true));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -590,14 +580,13 @@ ol.structs.RTree.prototype.searchReturningObject = function(extent, opt_type) {
|
|||||||
* @param {boolean} returnNode Do we return nodes?
|
* @param {boolean} returnNode Do we return nodes?
|
||||||
* @param {Array|Object} result Result.
|
* @param {Array|Object} result Result.
|
||||||
* @param {ol.structs.RTreeNode} root Root.
|
* @param {ol.structs.RTreeNode} root Root.
|
||||||
* @param {string|number=} opt_type Optional type to search for.
|
|
||||||
* @param {boolean=} opt_resultAsObject If set, result will be an object keyed
|
* @param {boolean=} opt_resultAsObject If set, result will be an object keyed
|
||||||
* by UID.
|
* by UID.
|
||||||
* @private
|
* @private
|
||||||
* @return {Array|Object} Result.
|
* @return {Array|Object} Result.
|
||||||
*/
|
*/
|
||||||
ol.structs.RTree.prototype.searchSubtree_ = function(
|
ol.structs.RTree.prototype.searchSubtree_ = function(
|
||||||
rect, returnNode, result, root, opt_type, opt_resultAsObject) {
|
rect, returnNode, result, root, opt_resultAsObject) {
|
||||||
var resultObject = {};
|
var resultObject = {};
|
||||||
var hitStack = []; // Contains the elements that overlap
|
var hitStack = []; // Contains the elements that overlap
|
||||||
|
|
||||||
@@ -619,13 +608,11 @@ ol.structs.RTree.prototype.searchSubtree_ = function(
|
|||||||
if (!returnNode) {
|
if (!returnNode) {
|
||||||
// TODO keep track of type on all nodes so we don't have to
|
// TODO keep track of type on all nodes so we don't have to
|
||||||
// walk all the way in to the leaf to know that we don't need it
|
// walk all the way in to the leaf to know that we don't need it
|
||||||
if (!goog.isDef(opt_type) || lTree.type == opt_type) {
|
var obj = lTree.leaf;
|
||||||
var obj = lTree.leaf;
|
if (goog.isDef(opt_resultAsObject)) {
|
||||||
if (goog.isDef(opt_resultAsObject)) {
|
resultObject[goog.getUid(obj).toString()] = obj;
|
||||||
resultObject[goog.getUid(obj).toString()] = obj;
|
} else {
|
||||||
} else {
|
result.push(obj);
|
||||||
result.push(obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.push(lTree);
|
result.push(lTree);
|
||||||
|
|||||||
@@ -98,17 +98,6 @@ describe('ol.structs.RTree', function() {
|
|||||||
expect(goog.object.getCount(rTree.search([5, 5, 6, 6]))).to.be(0);
|
expect(goog.object.getCount(rTree.search([5, 5, 6, 6]))).to.be(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('filters by type', function() {
|
|
||||||
rTree.insert([2, 2, 3, 3], 7, 'type1');
|
|
||||||
|
|
||||||
var result;
|
|
||||||
result = rTree.search([1, 2, 4, 4], 'type1');
|
|
||||||
expect(result).to.contain(7);
|
|
||||||
expect(result.length).to.be(1);
|
|
||||||
result = rTree.search([1, 2, 4, 4]);
|
|
||||||
expect(result.length).to.be(3);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can return objects instead of arrays', function() {
|
it('can return objects instead of arrays', function() {
|
||||||
var obj = {foo: 'bar'};
|
var obj = {foo: 'bar'};
|
||||||
rTree.insert([5, 5, 5, 5], obj);
|
rTree.insert([5, 5, 5, 5], obj);
|
||||||
|
|||||||
Reference in New Issue
Block a user