mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
Merge pull request #69 from jabadia/jabadia-devel
jabadia - tile size nightmares
This commit is contained in:
commit
1161a603a4
@ -190,12 +190,12 @@ define(["tiles/phoneGapConnector"],function(phonegap)
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a rough, approximate size of database in MBs.
|
||||
* Provides the size of database in bytes
|
||||
* @param callback callback(size, null) or callback(null, error)
|
||||
*/
|
||||
this.size = function(callback){
|
||||
if(this._db != null){
|
||||
var usage = { size: 0, tileCount: 0 };
|
||||
var usage = { sizeBytes: 0, tileCount: 0 };
|
||||
|
||||
var transaction = this._db.transaction(["tilepath"])
|
||||
.objectStore("tilepath")
|
||||
@ -206,12 +206,11 @@ define(["tiles/phoneGapConnector"],function(phonegap)
|
||||
if(cursor){
|
||||
var storedObject = cursor.value;
|
||||
var json = JSON.stringify(storedObject);
|
||||
usage.size += this.stringBytes(json);
|
||||
usage.sizeBytes += this.stringBytes(json);
|
||||
usage.tileCount += 1;
|
||||
cursor.continue();
|
||||
}
|
||||
else{
|
||||
usage.size = Math.round(usage.size/1024/1024); /* JAMI: *2 */
|
||||
else{
|
||||
callback(usage,null);
|
||||
}
|
||||
}.bind(this);
|
||||
@ -224,9 +223,8 @@ define(["tiles/phoneGapConnector"],function(phonegap)
|
||||
}
|
||||
}
|
||||
|
||||
this.stringBytes = function(str) {
|
||||
var m = encodeURIComponent(str).match(/%[89ABab]/g);
|
||||
return str.length + (m ? m.length : 0);
|
||||
this.stringBytes = function(str) {
|
||||
return str.length /**2*/ ;
|
||||
}
|
||||
|
||||
this.init = function(callback)
|
||||
|
||||
@ -29,13 +29,7 @@ define([
|
||||
{
|
||||
console.log("extending layer", layer.url);
|
||||
|
||||
layer._tileUrlArr = [];
|
||||
layer._tileSize = 0;
|
||||
|
||||
//Reset _tileUrlArr when extent is changed
|
||||
layer._map.on("update-start",function(evt){
|
||||
layer._tileUrlArr = [];
|
||||
})
|
||||
layer._lastTileUrl = "";
|
||||
|
||||
/* we add some methods to the layer object */
|
||||
/* we don't want to extend the tiled layer class, as it is a capability that we want to add only to one instance */
|
||||
@ -61,8 +55,7 @@ define([
|
||||
if( this.offline.online )
|
||||
{
|
||||
console.log("fetching url online: ", url);
|
||||
layer._tileUrlArr.push(url);
|
||||
console.log("tile url " + layer._tileUrlArr.length)
|
||||
layer._lastTileUrl = url;
|
||||
return url;
|
||||
}
|
||||
|
||||
@ -295,8 +288,8 @@ define([
|
||||
*/
|
||||
layer.estimateTileSize = function(callback)
|
||||
{
|
||||
if(layer._tileUrlArr.length > 0){
|
||||
var url = this.offline.proxyPath + "?" + layer._tileUrlArr[0];
|
||||
if(layer._lastTileUrl){
|
||||
var url = this.offline.proxyPath + "?" + layer._lastTileUrl;
|
||||
request.get(url,{
|
||||
handleAs: "text/plain; charset=x-user-defined",
|
||||
headers: {
|
||||
@ -309,9 +302,8 @@ define([
|
||||
});
|
||||
}
|
||||
else{
|
||||
return NaN;
|
||||
callback(NaN);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
layer.doNextTile = function(i, cells, reportProgress)
|
||||
|
||||
@ -172,8 +172,8 @@ require(["esri/map",
|
||||
basemapLayer.getOfflineUsage(function(usage)
|
||||
{
|
||||
console.log(usage);
|
||||
console.log("Avg tile size:", Math.round(usage.size * 1024 / usage.tileCount * 100) / 100, "Kb");
|
||||
var usageStr = usage.size + " Mb (" + usage.tileCount + " tiles)";
|
||||
console.log("Avg tile size:", Math.round(usage.sizeBytes / 1024 / usage.tileCount * 100) / 100, "Kb");
|
||||
var usageStr = Math.round(usage.sizeBytes/1024/1024*100)/100 + " Mb (" + usage.tileCount + " tiles)";
|
||||
dojo.byId('offline-usage').innerHTML = usageStr;
|
||||
});
|
||||
}
|
||||
|
||||
@ -115,6 +115,7 @@ describe("offline enabler library", function()
|
||||
{
|
||||
g_basemapLayer.deleteAllTiles(function(success)
|
||||
{
|
||||
expect(success).toEqual(true);
|
||||
var extent = new Extent({"xmin":-822542.2830377579,"ymin":4580841.761960262,"xmax":94702.05638410954,"ymax":5131188.365613382,"spatialReference":{"wkid":102100}});
|
||||
var callCount = 0;
|
||||
var reportProgress = function(progress)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user