diff --git a/lib/tiles/OfflineTilesEnablerLayer.js b/lib/tiles/OfflineTilesEnablerLayer.js index bd5be75..1771c41 100644 --- a/lib/tiles/OfflineTilesEnablerLayer.js +++ b/lib/tiles/OfflineTilesEnablerLayer.js @@ -419,26 +419,7 @@ define([ */ estimateTileSize : function(callback) { - if(this._lastTileUrl) - { - var url = this.offline.proxyPath? this.offline.proxyPath + "?" + this._lastTileUrl : this._lastTileUrl; - request.get(url,{ - handleAs: "text/plain; charset=x-user-defined", - headers: { - "X-Requested-With": "" //bypasses a dojo xhr bug - }, - timeout: 2000 - }).then(function(response){ - var img = Base64Utils.wordToBase64(Base64Utils.stringToWord(response)); - callback(img.length + url.length,null); - }, - function(err){ - callback(null,err); - }); - } - else{ - callback(NaN); - } + this._tilesCore._estimateTileSize(this._lastTileUrl,this.offline.proxyPath,callback); }, /** diff --git a/lib/tiles/TilesCore.js b/lib/tiles/TilesCore.js index 5920728..22f31df 100644 --- a/lib/tiles/TilesCore.js +++ b/lib/tiles/TilesCore.js @@ -4,6 +4,7 @@ */ define([ "dojo/query", + "dojo/request", "esri/geometry/Point", "esri/geometry/Extent", "esri/SpatialReference", @@ -12,7 +13,7 @@ define([ "tiles/base64utils", "tiles/tilingScheme" ], - function(query,Point,Extent,SpatialReference,TileInfo,LOD,Base64Utils,TilingScheme){ + function(query,request,Point,Extent,SpatialReference,TileInfo,LOD,Base64Utils,TilingScheme){ "use strict"; var TilesCore = function(){ @@ -49,6 +50,37 @@ define([ req.send(null); }; + /** + * Makes a request to a tile url and uses that as a basis for the + * the average tile size. + * Future Iterations could call multiple tiles and do an actual average. + * @param callback + * @returns {Number} Returns NaN if there was a problem retrieving the tile + */ + this._estimateTileSize = function(lastTileUrl,proxyPath,callback) + { + if(lastTileUrl) + { + var url = proxyPath? proxyPath + "?" + lastTileUrl : lastTileUrl; + request.get(url,{ + handleAs: "text/plain; charset=x-user-defined", + headers: { + "X-Requested-With": "" //bypasses a dojo xhr bug + }, + timeout: 2000 + }).then(function(response){ + var img = Base64Utils.wordToBase64(Base64Utils.stringToWord(response)); + callback(img.length + url.length,null); + }, + function(err){ + callback(null,err); + }); + } + else{ + callback(NaN); + } + }; + /** * Loads a csv file into storage. * Format is "url,img\r\n somebase64image,http://esri.com" diff --git a/lib/tiles/offlineTilesEnabler.js b/lib/tiles/offlineTilesEnabler.js index 5389766..ceb9761 100644 --- a/lib/tiles/offlineTilesEnabler.js +++ b/lib/tiles/offlineTilesEnabler.js @@ -323,26 +323,7 @@ define([ */ layer.estimateTileSize = function(callback) { - if(layer._lastTileUrl) - { - var url = this.offline.proxyPath? this.offline.proxyPath + "?" + layer._lastTileUrl : layer._lastTileUrl; - request.get(url,{ - handleAs: "text/plain; charset=x-user-defined", - headers: { - "X-Requested-With": "" //bypasses a dojo xhr bug - }, - timeout: 2000 - }).then(function(response){ - var img = Base64Utils.wordToBase64(Base64Utils.stringToWord(response)); - callback(img.length + url.length,null); - }, - function(err){ - callback(null,err); - }); - } - else{ - callback(NaN); - } + layer._tilesCore._estimateTileSize(this._lastTileUrl,this.offline.proxyPath,callback); }; /**