From 4d03c0bfaa29a9851a746e380fe5bdaffdf3d1c9 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 12 Dec 2013 17:03:40 +0100 Subject: [PATCH 1/5] Show an issue with ol.structs.RBush Note that the same test passes in the original implementation. --- test/spec/ol/structs/rbush.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/spec/ol/structs/rbush.test.js b/test/spec/ol/structs/rbush.test.js index 250aa374b5..757a6b287f 100644 --- a/test/spec/ol/structs/rbush.test.js +++ b/test/spec/ol/structs/rbush.test.js @@ -32,13 +32,18 @@ describe('ol.structs.RBush', function() { var objs; beforeEach(function() { - objs = [{}, {}, {}, {}, {}, {}]; + objs = [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]; rBush.insert([0, 0, 1, 1], objs[0]); rBush.insert([1, 1, 4, 4], objs[1]); rBush.insert([2, 2, 3, 3], objs[2]); rBush.insert([-5, -5, -4, -4], objs[3]); rBush.insert([-4, -4, -1, -1], objs[4]); rBush.insert([-3, -3, -2, -2], objs[5]); + rBush.insert([-3, -3, -2, -2], objs[6]); + rBush.insert([-3, -3, -2, -2], objs[7]); + rBush.insert([-3, -3, -2, -2], objs[8]); + rBush.insert([-3, -3, -2, -2], objs[9]); + rBush.insert([-3, -3, -2, -2], objs[10]); }); describe('#getAllInExtent', function() { From d3cc822f98f7bf8e959f347de92bdb851ddd9e25 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 13 Dec 2013 17:30:28 +0100 Subject: [PATCH 2/5] Do not ascend when node has more siblings --- src/ol/structs/rbush.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ol/structs/rbush.js b/src/ol/structs/rbush.js index e0bdc81819..fe8c8e4153 100644 --- a/src/ol/structs/rbush.js +++ b/src/ol/structs/rbush.js @@ -609,8 +609,9 @@ ol.structs.RBush.prototype.remove_ = function(extent, value) { var path = [node]; /** @type {Array.} */ var indexes = [0]; - var child, children, i, ii; + var childrenDone, child, children, i, ii; while (path.length > 0) { + childrenDone = false; goog.asserts.assert(node.height > 0); if (node.height == 1) { children = node.children; @@ -622,8 +623,7 @@ ol.structs.RBush.prototype.remove_ = function(extent, value) { return; } } - node = path.pop(); - index = indexes.pop(); + childrenDone = true; } else if (index < node.children.length) { child = node.children[index]; if (ol.extent.containsExtent(child.extent, extent)) { @@ -635,8 +635,16 @@ ol.structs.RBush.prototype.remove_ = function(extent, value) { ++index; } } else { - node = path.pop(); - index = indexes.pop(); + childrenDone = true; + } + if (childrenDone === true) { + var lastPathIndex = path.length - 1; + node = path[lastPathIndex]; + index = ++indexes[lastPathIndex]; + if (index > node.children.length) { + path.pop(); + indexes.pop(); + } } } }; From 67d2cddb846ef660a8fef58bfbd3b8526788464b Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 13 Dec 2013 18:27:33 +0100 Subject: [PATCH 3/5] Verify that removing random extent nodes also works --- test/spec/ol/structs/rbush.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/spec/ol/structs/rbush.test.js b/test/spec/ol/structs/rbush.test.js index 757a6b287f..044811e6eb 100644 --- a/test/spec/ol/structs/rbush.test.js +++ b/test/spec/ol/structs/rbush.test.js @@ -299,6 +299,20 @@ describe('ol.structs.RBush', function() { }); + describe('#remove', function() { + + it('can remove all 2000 objects', function() { + var objs = rBush.getAll(); + var i, value; + for (i = objs.length - 1; i >= 0; --i) { + value = objs[i]; + rBush.remove(value); + } + expect(rBush.isEmpty()).to.be(true); + }); + + }); + }); }); From 8bfa0f7ae94f1e4e3ad59cae4682c5e6c4b39bc7 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Mon, 16 Dec 2013 13:53:55 +0100 Subject: [PATCH 4/5] Truthy check is enough --- src/ol/structs/rbush.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ol/structs/rbush.js b/src/ol/structs/rbush.js index fe8c8e4153..2072aaf96b 100644 --- a/src/ol/structs/rbush.js +++ b/src/ol/structs/rbush.js @@ -637,7 +637,7 @@ ol.structs.RBush.prototype.remove_ = function(extent, value) { } else { childrenDone = true; } - if (childrenDone === true) { + if (childrenDone) { var lastPathIndex = path.length - 1; node = path[lastPathIndex]; index = ++indexes[lastPathIndex]; From ec1ee5538a3763e8e2212aecdee14a6fb6840e92 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 16 Dec 2013 14:02:40 +0100 Subject: [PATCH 5/5] Add collinsBart and ordnanceSurvery styles to bing-maps example --- examples/bing-maps.html | 2 ++ examples/bing-maps.js | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/examples/bing-maps.html b/examples/bing-maps.html index c038972c4c..a410469301 100644 --- a/examples/bing-maps.html +++ b/examples/bing-maps.html @@ -30,6 +30,8 @@ + + diff --git a/examples/bing-maps.js b/examples/bing-maps.js index 68a48d9bb5..bef2c7a04c 100644 --- a/examples/bing-maps.js +++ b/examples/bing-maps.js @@ -2,13 +2,19 @@ goog.require('ol.Map'); goog.require('ol.RendererHints'); goog.require('ol.View2D'); goog.require('ol.layer.Tile'); -goog.require('ol.proj'); goog.require('ol.source.BingMaps'); -var styles = ['Road', 'Aerial', 'AerialWithLabels']; +var styles = [ + 'Road', + 'Aerial', + 'AerialWithLabels', + 'collinsBart', + 'ordnanceSurvey' +]; var layers = []; -for (var i = 0; i < styles.length; ++i) { +var i, ii; +for (i = 0, ii = styles.length; i < ii; ++i) { layers.push(new ol.layer.Tile({ visible: false, preload: Infinity, @@ -23,14 +29,15 @@ var map = new ol.Map({ renderers: ol.RendererHints.createFromQueryData(), target: 'map', view: new ol.View2D({ - center: ol.proj.transform([-123.1, 49.25], 'EPSG:4326', 'EPSG:3857'), - zoom: 8 + center: [-6655.5402445057125, 6709968.258934638], + zoom: 13 }) }); $('#layer-select').change(function() { var style = $(this).find(':selected').val(); - for (var i = 0; i < layers.length; ++i) { + var i, ii; + for (i = 0, ii = layers.length; i < ii; ++i) { layers[i].setVisible(styles[i] == style); } });