Created
March 12, 2014 00:07
-
-
Save RhinoLance/9497816 to your computer and use it in GitHub Desktop.
Local caching
This file contains hidden or 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
_loadTile: function (tile, tilePoint) { | |
//try{ | |
var that = this; | |
tile._layer = this; | |
tile.onload = this._tileOnLoad; | |
tile.onerror = this._tileOnError; | |
tilePoint.z = this._getZoomForUrl(); | |
if (!this.tileStore) { | |
//console.log("Getting from web"); | |
tile.src = this.getTileUrl(tilePoint); | |
return; | |
} | |
var sFileName = this._getFilePath({ x: tilePoint.x, y: tilePoint.y, z: tilePoint.z }); | |
//console.log("fileName " + sFileName); | |
this.tileStore.getFile( | |
sFileName, | |
null, | |
function (oFile) { | |
//console.log("Tile loaded from cache "); | |
tile.src = oFile.toURL(); | |
}, | |
function (oError) { | |
//console.log("Cached tile not found, fetching it ..."); | |
try{ | |
if (!that.canCache(tilePoint)) { | |
//console.log('cancache: No'); | |
tile.src = that.getTileUrl(tilePoint); | |
return; | |
} | |
} catch (ex) { console.error("err qwe : " + ex + " \n" + JSON.stringify(ex)); } | |
//console.log('no local tile'); | |
that._downloadTile( | |
{ x: tilePoint.x, y: tilePoint.y, z: tilePoint.z }, | |
function (oResult) { | |
//console.log('download done.'); | |
if (oResult.status == "success") { | |
tile.src = oResult.data.toURL(); | |
//console.log("loaded from new cache" ); | |
} | |
} | |
); | |
} | |
); | |
//} catch (ex) { console.log("err abc: " + ex + " \n" + JSON.stringify(ex)); } | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment