mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
added /utils subdir. Added debouncer util lib
This commit is contained in:
parent
03ff996ccb
commit
151ea12612
@ -302,7 +302,8 @@ define([
|
||||
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);
|
||||
|
||||
@ -151,7 +151,8 @@
|
||||
var dojoConfig = {
|
||||
paths: {
|
||||
tiles: locationPath + "/../../lib/tiles",
|
||||
vendor: locationPath + "/../../vendor"
|
||||
vendor: locationPath + "/../../vendor",
|
||||
utils: locationPath + "/../../utils"
|
||||
}
|
||||
}
|
||||
window.proxyPath = "../../lib/proxy.php";
|
||||
|
||||
@ -12,7 +12,7 @@ require(["esri/map",
|
||||
"dojo/dom", "dojo/on", "dojo/query",
|
||||
"vendor/bootstrap-map-js/src/js/bootstrapmap",
|
||||
"esri/urlUtils", "esri/geometry/webMercatorUtils",
|
||||
"tiles/offlineEnabler",
|
||||
"tiles/offlineEnabler","utils/debouncer",
|
||||
"dojo/dom-construct", "dojo/domReady!"],
|
||||
function(Map,
|
||||
GraphicsLayer, Graphic, SimpleFillSymbol,
|
||||
@ -20,7 +20,7 @@ require(["esri/map",
|
||||
dom, on, query,
|
||||
BootstrapMap,
|
||||
urlUtils, webMercatorUtils,
|
||||
offlineEnabler,
|
||||
offlineEnabler,debouncer,
|
||||
domConstruct)
|
||||
{
|
||||
var scalebar;
|
||||
@ -106,7 +106,9 @@ require(["esri/map",
|
||||
|
||||
function initEvents()
|
||||
{
|
||||
map.on('extent-change', updateTileCountEstimation );
|
||||
map.on('extent-change',debouncer.debounceMap(function(){
|
||||
updateTileCountEstimation();
|
||||
}) );
|
||||
on(dojo.byId('minLevel'),'change', updateTileCountEstimation);
|
||||
on(dojo.byId('maxLevel'),'change', updateTileCountEstimation);
|
||||
|
||||
@ -117,6 +119,7 @@ require(["esri/map",
|
||||
function initOffline()
|
||||
{
|
||||
console.log("extending");
|
||||
|
||||
offlineEnabler.extend(basemapLayer,function(success)
|
||||
{
|
||||
if(success)
|
||||
@ -189,7 +192,8 @@ require(["esri/map",
|
||||
|
||||
//NOTE: Number of tiles per zoom level will not change unless the map div changes size
|
||||
var levelEstimation;
|
||||
try{basemapLayer.getLevelEstimation(map.extent,minLevel,function(result){
|
||||
|
||||
basemapLayer.getLevelEstimation(map.extent,minLevel,function(result){
|
||||
levelEstimation = result;
|
||||
|
||||
for(var level=minLevel; level<=maxLevel; level++)
|
||||
@ -217,7 +221,7 @@ require(["esri/map",
|
||||
rowContent = "<td><b>" + rowContent.join("</b></td><td><b>") + "</b></td>";
|
||||
tr = domConstruct.place("<tr>", dojo.byId('tile-count-table-body'),'last')
|
||||
domConstruct.place(rowContent, tr,'last');
|
||||
}).bind(this);}catch(err){console.log("ERROR " + err.toString)}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
39
utils/debouncer.js
Normal file
39
utils/debouncer.js
Normal file
@ -0,0 +1,39 @@
|
||||
define([],function(){
|
||||
return {
|
||||
|
||||
/**
|
||||
* Activates the orientation listener and listens for native events.
|
||||
* Handle orientation events to allow for resizing the map and working around
|
||||
* jQuery mobile bugs related to how and when the view settles after such an event
|
||||
*/
|
||||
setOrientationListener: function(callback){
|
||||
var supportsOrientationChange = "onorientationchange" in window,
|
||||
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
|
||||
|
||||
window.addEventListener(orientationEvent, this.debounceMap(function(){
|
||||
callback();
|
||||
},this.DEBOUNCE_DELAY).bind(this), false);
|
||||
},
|
||||
|
||||
/**
|
||||
* Minimize the number of times window readjustment fires a function
|
||||
* http://davidwalsh.name/javascript-debounce-function
|
||||
* @param func
|
||||
* @param wait
|
||||
* @param immediate
|
||||
* @returns {Function}
|
||||
*/
|
||||
debounceMap: function (func, wait, immediate) {
|
||||
var timeout;
|
||||
return function() {
|
||||
var context = this, args = arguments;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(function() {
|
||||
timeout = null;
|
||||
if (!immediate) func.apply(context, args);
|
||||
}, wait);
|
||||
if (immediate && !timeout) func.apply(context, args);
|
||||
};
|
||||
}
|
||||
}
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user