public
Created

modestmaps.js diff

  • Download Gist
modestmaps.js.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
diff --git a/modestmaps.js b/modestmaps.js
index 869c650..dd50831 100644
--- a/modestmaps.js
+++ b/modestmaps.js
@@ -134,7 +134,7 @@ if (!com) {
toKey: function() {
/* there used to be a clever hash function here but there were collisions.
TODO: optimize, but test for collisions properly :) */
- return [ Math.floor(this.zoom), Math.floor(this.column), Math.floor(this.row) ].join(',');
+ return [ 'c', Math.floor(this.zoom), Math.floor(this.column), Math.floor(this.row) ].join('_');
},
// Clone this object.
copy: function() {
@@ -1092,10 +1094,17 @@ if (!com) {
this.map.parent.appendChild(this.parent);
}
this.setProvider(provider);
+
+ this.keyPrefix = "layer_" + (new Date()).getTime();
+ if (!this.parent.id) {
+ this.parent.id = this.keyPrefix;
+ }
}
MM.Layer.prototype = {
+ keyPrefix: null,
+
map: null,
parent: null,
tiles: null,
@@ -1218,7 +1227,7 @@ if (!com) {
while(visibleTiles.length)
{
this.provider.releaseTile(visibleTiles[0].coord);
- this.requestManager.clearRequest(visibleTiles[0].coord.toKey());
+ this.requestManager.clearRequest(this.keyPrefix + visibleTiles[0].coord.toKey());
level.removeChild(visibleTiles[0]);
visibleTiles.shift();
}
@@ -1253,7 +1262,7 @@ if (!com) {
*/
inventoryVisibleTile: function(layer_element, tile_coord)
{
- var tile_key = tile_coord.toKey(),
+ var tile_key = this.keyPrefix + tile_coord.toKey(),
valid_tile_keys = [tile_key];
/*
@@ -1294,7 +1303,7 @@ if (!com) {
for(var pz = 1; pz <= maxStepsOut; pz++)
{
var parent_coord = tile_coord.zoomBy(-pz).container();
- var parent_key = parent_coord.toKey();
+ var parent_key = this.keyPrefix + parent_coord.toKey();
if (this.enablePyramidLoading) {
// mark all parent tiles valid
@@ -1336,13 +1345,13 @@ if (!com) {
var child_coord = tile_coord.zoomBy(1);
// mark everything valid whether or not we have it:
- valid_tile_keys.push(child_coord.toKey());
+ valid_tile_keys.push(this.keyPrefix + child_coord.toKey());
child_coord.column += 1;
- valid_tile_keys.push(child_coord.toKey());
+ valid_tile_keys.push(this.keyPrefix + child_coord.toKey());
child_coord.row += 1;
- valid_tile_keys.push(child_coord.toKey());
+ valid_tile_keys.push(this.keyPrefix + child_coord.toKey());
child_coord.column -= 1;
- valid_tile_keys.push(child_coord.toKey());
+ valid_tile_keys.push(this.keyPrefix + child_coord.toKey());
}
return valid_tile_keys;
@@ -1400,7 +1409,7 @@ if (!com) {
if(!valid_tile_keys[tile.id]) {
this.provider.releaseTile(tile.coord);
- this.requestManager.clearRequest(tile.coord.toKey());
+ this.requestManager.clearRequest(this.keyPrefix + tile.coord.toKey());
level.removeChild(tile);
} else {
@@ -1416,7 +1425,9 @@ if (!com) {
tile.style.height = Math.ceil(tileHeight) + 'px';
// log last-touched-time of currently cached tiles
- this.recentTilesById[tile.id].lastTouchedTime = now;
+ if (tile.id in this.recentTilesById) {
+ this.recentTilesById[tile.id].lastTouchedTime = now;
+ }
}
}
},
@@ -1544,6 +1555,10 @@ if (!com) {
while(this.tileCacheSize > maxTiles)
{
+ if (this.recentTiles.length == 0) {
+ console.warn("0 recent tiles; unable to trim the cache any more");
+ break;
+ }
// delete the oldest record
var tileRecord = this.recentTiles.pop();
var now = new Date().getTime();
@@ -1554,7 +1569,7 @@ if (!com) {
var tile = this.tiles[tileRecord.id];
if (tile.parentNode) {
// I'm leaving this uncommented for now but you should never see it:
- alert("Gah: trying to removing cached tile even though it's still in the DOM");
+ // throw "Gah: trying to removing cached tile even though it's still in the DOM";
}
else {
delete this.tiles[tileRecord.id];

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.