easy async loading for GridLayer
This commit is contained in:
parent
e8c504b5f9
commit
8f97ca619e
@ -23,10 +23,17 @@
|
|||||||
attribution: 'Grid Layer'
|
attribution: 'Grid Layer'
|
||||||
});
|
});
|
||||||
|
|
||||||
grid.createTile = function (coords) {
|
grid.createTile = function (coords, done) {
|
||||||
var tile = document.createElement('div');
|
var tile = document.createElement('div');
|
||||||
tile.innerHTML = [coords.x, coords.y, coords.z].join(',');
|
tile.innerHTML = [coords.x, coords.y, coords.z].join(',');
|
||||||
tile.style.outline = '1px solid red';
|
tile.style.outline = '1px solid red';
|
||||||
|
tile.style.background = 'white';
|
||||||
|
|
||||||
|
// test async
|
||||||
|
setTimeout(function () {
|
||||||
|
done(tile);
|
||||||
|
}, Math.random() * 500);
|
||||||
|
|
||||||
return tile;
|
return tile;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ L.GridLayer = L.Class.extend({
|
|||||||
// minZoom: <Number>,
|
// minZoom: <Number>,
|
||||||
// maxZoom: <Number>,
|
// maxZoom: <Number>,
|
||||||
|
|
||||||
async: false,
|
|
||||||
unloadInvisibleTiles: L.Browser.mobile,
|
unloadInvisibleTiles: L.Browser.mobile,
|
||||||
updateWhenIdle: L.Browser.mobile,
|
updateWhenIdle: L.Browser.mobile,
|
||||||
updateInterval: 150
|
updateInterval: 150
|
||||||
@ -21,6 +20,9 @@ L.GridLayer = L.Class.extend({
|
|||||||
|
|
||||||
initialize: function (options) {
|
initialize: function (options) {
|
||||||
options = L.setOptions(this, options);
|
options = L.setOptions(this, options);
|
||||||
|
|
||||||
|
// make sure it can be passed safely without losing context
|
||||||
|
this._tileReady = L.bind(this._tileReady, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
onAdd: function (map) {
|
onAdd: function (map) {
|
||||||
@ -384,8 +386,8 @@ L.GridLayer = L.Class.extend({
|
|||||||
this._initTile(tile);
|
this._initTile(tile);
|
||||||
|
|
||||||
if (this.createTile.length < 2) {
|
if (this.createTile.length < 2) {
|
||||||
this._tileReady(tile);
|
// if tiles are sync, delay one frame for opacity anim to happen
|
||||||
// TODO pass tileReady to createTile for async
|
setTimeout(L.bind(this._tileReady, this, tile), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
var tilePos = this._getTilePos(coords);
|
var tilePos = this._getTilePos(coords);
|
||||||
@ -421,11 +423,8 @@ L.GridLayer = L.Class.extend({
|
|||||||
|
|
||||||
if (this._animated) {
|
if (this._animated) {
|
||||||
// clear scaled tiles after all new tiles are loaded (for performance)
|
// clear scaled tiles after all new tiles are loaded (for performance)
|
||||||
this._clearBgBuffer();
|
clearTimeout(this._clearBgBufferTimer);
|
||||||
|
this._clearBgBufferTimer = setTimeout(L.bind(this._clearBgBuffer, this), 300);
|
||||||
// TODO find out why timeout was needed
|
|
||||||
// clearTimeout(this._clearBgBufferTimer);
|
|
||||||
// this._clearBgBufferTimer = setTimeout(L.bind(this._clearBgBuffer, this), 500);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user