two simple changes (although diff seems more complex)

- layer.resampling = false
- temp url is now void:/level/row/col, as tiledlayer code seems to split the returned url by '/' to get level row and col values
This commit is contained in:
Javier Abadia 2014-02-24 00:16:20 +01:00
parent ddec0a3890
commit f44da88cab

View File

@ -51,6 +51,8 @@ define([
else
return callback(false, "indexedDB not supported");
layer.resampling = false;
/**
* Internal method that overrides the getTileUrl() method.
* If application is offline then tiles are written to local storage.
@ -64,55 +66,53 @@ define([
*/
layer.getTileUrl = function(level,row,col)
{
if(isNaN(level) == false && isNaN(row) == false && isNaN(col) == false){
console.log("looking for tile",level,row,col);
var url = this._getTileUrl(level,row,col);
if( this.offline.online )
{
console.log("fetching url online: ", url);
layer._lastTileUrl = url;
return url;
}
url = url.split('?')[0];
/* temporary URL returned immediately, as we haven't retrieved the image from the indexeddb yet */
var tileid = "void:"+level+"-"+row+"-"+col;
this.offline.store.get(url, function(success, offlineTile)
{
/* when the .get() callback is called we replace the temporary URL originally returned by the data:image url */
var img = query("img[src="+tileid+"]")[0];
if( success )
{
console.log("found tile offline", url);
var imgURL = "data:image;base64," + offlineTile.img;
// search for the img with src="void:"+level+"-"+row+"-"+col and replace with actual url
img.style.borderColor = "blue";
// when we return a nonexistent url to the image, the TiledMapServiceLayer::_tileErrorHandler() method
// sets img visibility to 'hidden', so we need to show the image back once we have put the data:image
img.style.visibility = "visible";
img.src = imgURL;
return ""; /* this result goes nowhere, seriously */
}
else
{
img.style.borderColor = "green";
console.log("tile is not in the offline store", url);
return ""; /* this result goes nowhere, seriously */
}
});
return tileid;
}
else{
if(isNaN(level) || isNaN(row) || isNaN(col) )
{
console.log("level,row,col:",level,row,col);
return null;
}
console.log("looking for tile",level,row,col);
var url = this._getTileUrl(level,row,col);
if( this.offline.online )
{
console.log("fetching url online: ", url);
layer._lastTileUrl = url;
return url;
}
url = url.split('?')[0];
/* temporary URL returned immediately, as we haven't retrieved the image from the indexeddb yet */
var tileid = "void:/"+level+"/"+row+"/"+col;
this.offline.store.get(url, function(success, offlineTile)
{
/* when the .get() callback is called we replace the temporary URL originally returned by the data:image url */
var img = query("img[src="+tileid+"]")[0];
if( success )
{
console.log("found tile offline", url);
var imgURL = "data:image;base64," + offlineTile.img;
// search for the img with src="void:"+level+"-"+row+"-"+col and replace with actual url
img.style.borderColor = "blue";
// when we return a nonexistent url to the image, the TiledMapServiceLayer::_tileErrorHandler() method
// sets img visibility to 'hidden', so we need to show the image back once we have put the data:image
img.style.visibility = "visible";
img.src = imgURL;
}
else
{
img.style.borderColor = "green";
console.log("tile is not in the offline store", url);
}
return ""; /* this result goes nowhere, seriously */
});
return tileid;
};
/**