refactored estimateTileSize() into TilesCore

This commit is contained in:
Andy Gup 2014-08-15 14:10:45 -06:00
parent 0f834f9cfd
commit 9628b8ead8
3 changed files with 35 additions and 41 deletions

View File

@ -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);
},
/**

View File

@ -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"

View File

@ -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);
};
/**