diff --git a/lib/tiles/dbStore.js b/lib/tiles/dbStore.js index 71ccd74..2b95549 100644 --- a/lib/tiles/dbStore.js +++ b/lib/tiles/dbStore.js @@ -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) diff --git a/lib/tiles/offlineEnabler.js b/lib/tiles/offlineEnabler.js index af00238..02263ca 100644 --- a/lib/tiles/offlineEnabler.js +++ b/lib/tiles/offlineEnabler.js @@ -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) diff --git a/samples/tiles/tiles-indexed-db.js b/samples/tiles/tiles-indexed-db.js index 7fdaa87..60b4e76 100644 --- a/samples/tiles/tiles-indexed-db.js +++ b/samples/tiles/tiles-indexed-db.js @@ -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; }); } diff --git a/test/spec/offlineEnablerSpec.js b/test/spec/offlineEnablerSpec.js index 622d385..a61b53c 100644 --- a/test/spec/offlineEnablerSpec.js +++ b/test/spec/offlineEnablerSpec.js @@ -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)