diff --git a/lib/tiles/offlineEnabler.js b/lib/tiles/offlineEnabler.js index 26136bd..afd1aca 100644 --- a/lib/tiles/offlineEnabler.js +++ b/lib/tiles/offlineEnabler.js @@ -287,19 +287,31 @@ define([ /* internal methods */ + /** + * 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 + */ layer.estimateTileSize = function(callback) { - var url = this.offline.proxyPath + "?" + layer._tileUrlArr[0]; - var size = 0; - request.get(url,{ - handleAs: "text/plain; charset=x-user-defined", - headers: { // This is required to stop the - "X-Requested-With": "" // server from rejecting the - } - }).then(function(response){ - var img = Base64Utils.wordToBase64(Base64Utils.stringToWord(response)); - callback(img.length + url.length); - }); + if(layer._tileUrlArr.length > 0){ + var url = this.offline.proxyPath + "?" + layer._tileUrlArr[0]; + request.get(url,{ + handleAs: "text/plain; charset=x-user-defined", + headers: { + "X-Requested-With": "" //bypasses a dojo xhr bug + } + }).then(function(response){ + var img = Base64Utils.wordToBase64(Base64Utils.stringToWord(response)); + callback(img.length + url.length); + }); + } + else{ + return NaN; + } + }; layer.doNextTile = function(i, cells, reportProgress)