Skip to content

Instantly share code, notes, and snippets.

@RhinoLance
Created March 12, 2014 00:07
Show Gist options
  • Save RhinoLance/9497816 to your computer and use it in GitHub Desktop.
Save RhinoLance/9497816 to your computer and use it in GitHub Desktop.
Local caching
_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