minor tile code cleanup

This commit is contained in:
Vladimir Agafonkin 2014-03-20 17:19:19 -07:00
parent 9b752757ef
commit b0ce42f270

View File

@ -287,9 +287,8 @@ L.GridLayer = L.Layer.extend({
_addTiles: function (tileRange) { _addTiles: function (tileRange) {
var queue = [], var queue = [],
center = tileRange.getCenter(); center = tileRange.getCenter(),
j, i, coords;
var j, i, coords;
// create a queue of coordinates to load tiles from // create a queue of coordinates to load tiles from
for (j = tileRange.min.y; j <= tileRange.max.y; j++) { for (j = tileRange.min.y; j <= tileRange.max.y; j++) {
@ -305,6 +304,11 @@ L.GridLayer = L.Layer.extend({
} }
} }
// sort tile queue to load tiles in order of their distance to center
queue.sort(function (a, b) {
return a.distanceTo(center) - b.distanceTo(center);
});
var tilesToLoad = queue.length; var tilesToLoad = queue.length;
if (tilesToLoad === 0) { return; } if (tilesToLoad === 0) { return; }
@ -316,11 +320,6 @@ L.GridLayer = L.Layer.extend({
this._tilesToLoad += tilesToLoad; this._tilesToLoad += tilesToLoad;
// sort tile queue to load tiles in order of their distance to center
queue.sort(function (a, b) {
return a.distanceTo(center) - b.distanceTo(center);
});
// create DOM fragment to append tiles in one batch // create DOM fragment to append tiles in one batch
var fragment = document.createDocumentFragment(); var fragment = document.createDocumentFragment();
@ -385,7 +384,7 @@ L.GridLayer = L.Layer.extend({
for (var key in this._level.tiles) { for (var key in this._level.tiles) {
var coords = this._keyToTileCoords(key); var coords = this._keyToTileCoords(key);
if (!tileRange.contains(coords)) { if (!tileRange.contains(coords)) {
this._removeTile(key, coords.z); this._removeTile(key);
} }
} }
}, },