Skip to content

Commit

Permalink
improve redraw behaviour in getTileComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomEtc committed Apr 12, 2011
1 parent c202b0a commit 4e7c6b6
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Expand Up @@ -8,6 +8,10 @@ Following the semantic versioning recommendation best we can:
minor version, and backwards incompatible API changes increment minor version, and backwards incompatible API changes increment
the major version." -- http://semver.org/ the major version." -- http://semver.org/


v0.14.3
- improve redraw behavior by ensuring layer is visible in getTileComplete
- use a closure in v0.14.2's setTimeout to ensure proper 'this'

v0.14.2 v0.14.2
- add setTimeout to processQueue to avoid stack overflow/recursion - add setTimeout to processQueue to avoid stack overflow/recursion
bug in IE 7/8 (https://github.com/stamen/modestmaps-js/issues/12) bug in IE 7/8 (https://github.com/stamen/modestmaps-js/issues/12)
Expand Down
35 changes: 22 additions & 13 deletions modestmaps.js
@@ -1,5 +1,5 @@
/*! /*!
* Modest Maps JS v0.14.2 * Modest Maps JS v0.14.3
* http://modestmaps.com/ * http://modestmaps.com/
* *
* Copyright (c) 2010 Stamen Design, All Rights Reserved. * Copyright (c) 2010 Stamen Design, All Rights Reserved.
Expand Down Expand Up @@ -816,6 +816,17 @@ if (!com) {
} }
} }
}, },

getProcessQueue: function() {
// let's only create this closure once...
if (!this._processQueue) {
var theManager = this;
this._processQueue = function() {
theManager.processQueue();
}
}
return this._processQueue;
},


processQueue: function(sortFunc) { processQueue: function(sortFunc) {
if (sortFunc && this.requestQueue.length > 8) { if (sortFunc && this.requestQueue.length > 8) {
Expand Down Expand Up @@ -897,7 +908,7 @@ if (!com) {
// use setTimeout() to avoid the IE recursion limit, see // use setTimeout() to avoid the IE recursion limit, see
// http://cappuccino.org/discuss/2010/03/01/internet-explorer-global-variables-and-stack-overflows/ // http://cappuccino.org/discuss/2010/03/01/internet-explorer-global-variables-and-stack-overflows/
// and https://github.com/stamen/modestmaps-js/issues/12 // and https://github.com/stamen/modestmaps-js/issues/12
setTimeout(theManager.processQueue, 0); setTimeout(theManager.getProcessQueue(), 0);


}; };
} }
Expand Down Expand Up @@ -1559,17 +1570,6 @@ if (!com) {
theMap.recentTilesById[tile.id] = record; theMap.recentTilesById[tile.id] = record;
theMap.recentTiles.push(record); theMap.recentTiles.push(record);


// add tile to its layer:
var theLayer = theMap.layers[tile.coord.zoom];
theLayer.appendChild(tile);

//if (!theMap.lastTileReceived) {
// theMap.lastTileReceived = new Date().getTime();
//}
//var t = new Date().getTime();
//console.log(tile.coord.toString() + ' ' + (t-theMap.lastTileReceived));
//theMap.lastTileReceived = t;

// position this tile (avoids a full draw() call): // position this tile (avoids a full draw() call):
var theCoord = theMap.coordinate.zoomTo(tile.coord.zoom); var theCoord = theMap.coordinate.zoomTo(tile.coord.zoom);
var scale = Math.pow(2, theMap.coordinate.zoom - tile.coord.zoom); var scale = Math.pow(2, theMap.coordinate.zoom - tile.coord.zoom);
Expand All @@ -1582,6 +1582,15 @@ if (!com) {
tile.style.width = Math.ceil(theMap.provider.tileWidth * scale) + 'px'; tile.style.width = Math.ceil(theMap.provider.tileWidth * scale) + 'px';
tile.style.height = Math.ceil(theMap.provider.tileHeight * scale) + 'px'; tile.style.height = Math.ceil(theMap.provider.tileHeight * scale) + 'px';


// add tile to its layer
var theLayer = theMap.layers[tile.coord.zoom];
theLayer.appendChild(tile);

// ensure the layer is visible if it's still the current layer
if (Math.round(theMap.coordinate.zoom) == tile.coord.zoom) {
theLayer.style.display = 'block';
}

// request a lazy redraw of all layers // request a lazy redraw of all layers
// this will remove tiles that were only visible // this will remove tiles that were only visible
// to cover this tile while it loaded: // to cover this tile while it loaded:
Expand Down
4 changes: 2 additions & 2 deletions modestmaps.min.js

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions src/map.js
Expand Up @@ -652,17 +652,6 @@
theMap.recentTilesById[tile.id] = record; theMap.recentTilesById[tile.id] = record;
theMap.recentTiles.push(record); theMap.recentTiles.push(record);


// add tile to its layer:
var theLayer = theMap.layers[tile.coord.zoom];
theLayer.appendChild(tile);

//if (!theMap.lastTileReceived) {
// theMap.lastTileReceived = new Date().getTime();
//}
//var t = new Date().getTime();
//console.log(tile.coord.toString() + ' ' + (t-theMap.lastTileReceived));
//theMap.lastTileReceived = t;

// position this tile (avoids a full draw() call): // position this tile (avoids a full draw() call):
var theCoord = theMap.coordinate.zoomTo(tile.coord.zoom); var theCoord = theMap.coordinate.zoomTo(tile.coord.zoom);
var scale = Math.pow(2, theMap.coordinate.zoom - tile.coord.zoom); var scale = Math.pow(2, theMap.coordinate.zoom - tile.coord.zoom);
Expand All @@ -675,6 +664,15 @@
tile.style.width = Math.ceil(theMap.provider.tileWidth * scale) + 'px'; tile.style.width = Math.ceil(theMap.provider.tileWidth * scale) + 'px';
tile.style.height = Math.ceil(theMap.provider.tileHeight * scale) + 'px'; tile.style.height = Math.ceil(theMap.provider.tileHeight * scale) + 'px';


// add tile to its layer
var theLayer = theMap.layers[tile.coord.zoom];
theLayer.appendChild(tile);

// ensure the layer is visible if it's still the current layer
if (Math.round(theMap.coordinate.zoom) == tile.coord.zoom) {
theLayer.style.display = 'block';
}

// request a lazy redraw of all layers // request a lazy redraw of all layers
// this will remove tiles that were only visible // this will remove tiles that were only visible
// to cover this tile while it loaded: // to cover this tile while it loaded:
Expand Down
13 changes: 12 additions & 1 deletion src/requests.js
Expand Up @@ -112,6 +112,17 @@
} }
} }
}, },

getProcessQueue: function() {
// let's only create this closure once...
if (!this._processQueue) {
var theManager = this;
this._processQueue = function() {
theManager.processQueue();
}
}
return this._processQueue;
},


processQueue: function(sortFunc) { processQueue: function(sortFunc) {
if (sortFunc && this.requestQueue.length > 8) { if (sortFunc && this.requestQueue.length > 8) {
Expand Down Expand Up @@ -193,7 +204,7 @@
// use setTimeout() to avoid the IE recursion limit, see // use setTimeout() to avoid the IE recursion limit, see
// http://cappuccino.org/discuss/2010/03/01/internet-explorer-global-variables-and-stack-overflows/ // http://cappuccino.org/discuss/2010/03/01/internet-explorer-global-variables-and-stack-overflows/
// and https://github.com/stamen/modestmaps-js/issues/12 // and https://github.com/stamen/modestmaps-js/issues/12
setTimeout(theManager.processQueue, 0); setTimeout(theManager.getProcessQueue(), 0);


}; };
} }
Expand Down
2 changes: 1 addition & 1 deletion src/start.js
@@ -1,5 +1,5 @@
/*! /*!
* Modest Maps JS v0.14.2 * Modest Maps JS v0.14.3
* http://modestmaps.com/ * http://modestmaps.com/
* *
* Copyright (c) 2010 Stamen Design, All Rights Reserved. * Copyright (c) 2010 Stamen Design, All Rights Reserved.
Expand Down

0 comments on commit 4e7c6b6

Please sign in to comment.