Revert "Remove listeners when dropping tiles"

This reverts commit fd6aaff2f5.
This commit is contained in:
Éric Lemoine
2013-03-07 10:41:23 +01:00
parent 7f9e327a65
commit 7fabff5ffa
3 changed files with 4 additions and 39 deletions

View File

@@ -30,13 +30,6 @@ ol.Tile = function(tileCoord) {
goog.base(this); goog.base(this);
/**
* A count incremented each time the tile is inQueue in a tile queue,
* and decremented each time the tile is dequeued from a tile queue.
* @type {number}
*/
this.inQueue = 0;
/** /**
* @type {ol.TileCoord} * @type {ol.TileCoord}
*/ */

View File

@@ -89,8 +89,6 @@ ol.TileQueue.prototype.dequeue_ = function() {
} }
var tileKey = tile.getKey(); var tileKey = tile.getKey();
delete this.queuedTileKeys_[tileKey]; delete this.queuedTileKeys_[tileKey];
tile.inQueue--;
goog.asserts.assert(tile.inQueue >= 0);
return tile; return tile;
}; };
@@ -112,8 +110,6 @@ ol.TileQueue.prototype.enqueue = function(tile, tileSourceKey, tileCenter) {
this.heap_.push([priority, tile, tileSourceKey, tileCenter]); this.heap_.push([priority, tile, tileSourceKey, tileCenter]);
this.queuedTileKeys_[tileKey] = true; this.queuedTileKeys_[tileKey] = true;
this.siftDown_(0, this.heap_.length - 1); this.siftDown_(0, this.heap_.length - 1);
tile.inQueue++;
goog.asserts.assert(tile.inQueue > 0);
} }
} }
}; };
@@ -250,11 +246,6 @@ ol.TileQueue.prototype.reprioritize = function() {
if (priority == ol.TileQueue.DROP) { if (priority == ol.TileQueue.DROP) {
tileKey = tile.getKey(); tileKey = tile.getKey();
delete this.queuedTileKeys_[tileKey]; delete this.queuedTileKeys_[tileKey];
tile.inQueue--;
goog.asserts.assert(tile.inQueue >= 0);
if (tile.inQueue === 0) {
goog.events.removeAll(tile);
}
} else { } else {
node[0] = priority; node[0] = priority;
heap[n++] = node; heap[n++] = node;

View File

@@ -21,20 +21,13 @@ describe('ol.TileQueue', function() {
} }
function addRandomPriorityTiles(tq, num) { function addRandomPriorityTiles(tq, num) {
var tiles = [];
var i, tile, priority; var i, tile, priority;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
tile = new ol.Tile(); tile = new ol.Tile();
tile.toDrop = (i % 2 === 0) ? true : false;
goog.events.listen(tile, goog.events.EventType.CHANGE,
goog.nullFunction);
priority = Math.floor(Math.random() * 100); priority = Math.floor(Math.random() * 100);
tq.heap_.push([priority, tile, '', new ol.Coordinate(0, 0)]); tq.heap_.push([priority, tile, '', new ol.Coordinate(0, 0)]);
tq.queuedTileKeys_[tile.getKey()] = true; tq.queuedTileKeys_[tile.getKey()] = true;
tile.inQueue++;
tiles.push(tile);
} }
return tiles;
} }
describe('heapify', function() { describe('heapify', function() {
@@ -52,15 +45,16 @@ describe('ol.TileQueue', function() {
it('does reprioritize the array', function() { it('does reprioritize the array', function() {
var tq = new ol.TileQueue(function() {}); var tq = new ol.TileQueue(function() {});
var tiles = addRandomPriorityTiles(tq, 100); addRandomPriorityTiles(tq, 100);
tq.heapify_(); tq.heapify_();
// now reprioritize, changing the priority of 50 tiles and removing the // now reprioritize, changing the priority of 50 tiles and removing the
// rest // rest
tq.tilePriorityFunction_ = function(tile) { var i = 0;
if (tile.toDrop) { tq.tilePriorityFunction_ = function() {
if ((i++) % 2 === 0) {
return ol.TileQueue.DROP; return ol.TileQueue.DROP;
} }
return Math.floor(Math.random() * 100); return Math.floor(Math.random() * 100);
@@ -70,23 +64,10 @@ describe('ol.TileQueue', function() {
expect(tq.heap_.length).toEqual(50); expect(tq.heap_.length).toEqual(50);
expect(isHeap(tq)).toBeTruthy(); expect(isHeap(tq)).toBeTruthy();
var i, tile;
for (i = 0; i < tiles.length; ++i) {
tile = tiles[i];
var hasListener = goog.events.hasListener(tile);
if (tile.toDrop) {
expect(hasListener).toBeFalsy();
} else {
expect(hasListener).toBeTruthy();
}
}
}); });
}); });
}); });
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('ol.Coordinate'); goog.require('ol.Coordinate');
goog.require('ol.Tile'); goog.require('ol.Tile');
goog.require('ol.TileQueue'); goog.require('ol.TileQueue');