diff --git a/lib/tiles/offlineEnabler.js b/lib/tiles/offlineEnabler.js index 7fd66d7..af00238 100644 --- a/lib/tiles/offlineEnabler.js +++ b/lib/tiles/offlineEnabler.js @@ -30,6 +30,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){ @@ -100,21 +101,19 @@ define([ return tileid; }; - layer.getLevelEstimation = function(extent, level,callback) - { - //var tilingScheme = new TilingScheme(this,geometry); - //var cellIds = tilingScheme.getAllCellIdsInExtent(extent,level); - var cellIdLength = this._tileUrlArr.length; - this.estimateTileSize(function(tileSize){ - var levelEstimation = { - level: level, - tileCount: cellIdLength, - sizeBytes: cellIdLength * tileSize - } + layer.getLevelEstimation = function(extent, level, tileSize) + { + var tilingScheme = new TilingScheme(this,geometry); + var cellIds = tilingScheme.getAllCellIdsInExtent(extent,level); - callback(levelEstimation); - }); - }; + var levelEstimation = { + level: level, + tileCount: cellIds.length, + sizeBytes: cellIds.length * tileSize + } + + return levelEstimation; + }; layer.prepareForOffline = function(minLevel, maxLevel, extent, reportProgress) { diff --git a/samples/tiles/tiles-indexed-db.js b/samples/tiles/tiles-indexed-db.js index 1e52a73..523c483 100644 --- a/samples/tiles/tiles-indexed-db.js +++ b/samples/tiles/tiles-indexed-db.js @@ -182,30 +182,32 @@ require(["esri/map", { console.log('updating'); var zoomLevel = map.getLevel(); - dojo.byId('currentLevel').value = zoomLevel; - dojo.byId('maxLevel').value = zoomLevel; + dojo.byId('currentLevel').value = zoomLevel; - var minLevel = parseInt(dojo.byId('minLevel').value); - var maxLevel = zoomLevel; + var minLevel = parseInt(dojo.byId('minLevel').value); + var maxLevel = parseInt(dojo.byId('maxLevel').value); + + if( maxLevel > zoomLevel + 3 || maxLevel > basemapLayer.maxLevel) + { + maxLevel = Math.min(basemapLayer.maxLevel, zoomLevel + 3); + dojo.byId('maxLevel').value = maxLevel; + } var totalEstimation = { tileCount:0, sizeBytes:0 } domConstruct.empty('tile-count-table-body'); - //NOTE: Number of tiles per zoom level will not change unless the map div changes size - var levelEstimation; - - basemapLayer.getLevelEstimation(map.extent,minLevel,function(result){ - levelEstimation = result; - + basemapLayer.estimateTileSize(function(tileSize){ for(var level=minLevel; level<=maxLevel; level++) { + var levelEstimation = basemapLayer.getLevelEstimation(map.extent,level,tileSize); + totalEstimation.tileCount += levelEstimation.tileCount; totalEstimation.sizeBytes += levelEstimation.sizeBytes; - if( levelEstimation.tileCount > 1 && levelEstimation.tileCount < 5000) + if( levelEstimation.tileCount > 1) { - var rowContent = [level, levelEstimation.tileCount, Math.round(levelEstimation.sizeBytes / 1024 / 1024 * 100) / 100 + " Mb"] + var rowContent = [levelEstimation.level, levelEstimation.tileCount, Math.round(levelEstimation.sizeBytes / 1024 / 1024 * 100) / 100 + " Mb"] rowContent = "" + rowContent.join("") + ""; var tr = domConstruct.place("", dojo.byId('tile-count-table-body'),'last') domConstruct.place(rowContent, tr,'last'); @@ -223,8 +225,35 @@ require(["esri/map", rowContent = "" + rowContent.join("") + ""; tr = domConstruct.place("", dojo.byId('tile-count-table-body'),'last') domConstruct.place(rowContent, tr,'last'); - }); + }) +// for(var level=minLevel; level<=maxLevel; level++) +// { +// totalEstimation.tileCount += levelEstimation.tileCount; +// totalEstimation.sizeBytes += levelEstimation.sizeBytes; +// +// if( levelEstimation.tileCount > 1 && levelEstimation.tileCount < 5000) +// { +// var rowContent = [level, levelEstimation.tileCount, Math.round(levelEstimation.sizeBytes / 1024 / 1024 * 100) / 100 + " Mb"] +// rowContent = "" + rowContent.join("") + ""; +// var tr = domConstruct.place("", dojo.byId('tile-count-table-body'),'last') +// domConstruct.place(rowContent, tr,'last'); +// } +// +// if( totalEstimation.tileCount > 5000 ) +// { +// var tr = domConstruct.place("", dojo.byId('tile-count-table-body'),'last') +// domConstruct.place("...", tr,'last'); +// break; +// } +// } +// +// rowContent = ["Total", totalEstimation.tileCount, Math.floor(totalEstimation.sizeBytes / 1024 / 1024 * 100)/100 + " Mb"]; +// rowContent = "" + rowContent.join("") + ""; +// tr = domConstruct.place("", dojo.byId('tile-count-table-body'),'last') +// domConstruct.place(rowContent, tr,'last'); +// }); +// }) } function goOffline() @@ -282,7 +311,7 @@ require(["esri/map", /* launch offline preparation process */ var minLevel = parseInt(dojo.byId('minLevel').value); - var maxLevel = map.getLevel(); + var maxLevel = map.getLevel(); //current zoom level sets max extent basemapLayer.prepareForOffline(minLevel, maxLevel, map.extent, reportProgress); }