Created
November 11, 2011 03:45
-
-
Save shawnbot/1357132 to your computer and use it in GitHub Desktop.
modestmaps.js diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment