From 9b3caa8eb945a630dc086e11f03e1c3afbcfbd17 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Mon, 16 Sep 2013 00:01:25 +0100 Subject: [PATCH] add function to start 'idle' mode - for use in the mobile app (rather than it forcing the idle timer) the existing idle resume function can be used on returning to iitc also, fix the long-standing bug on mobile where the map disappears after repeated touch panning/zooming. seems leaflet gets confused about zoom levels and ends up with a non-ingeger. when this is found, force it back to an ingeger zoom level when this happens --- code/boot.js | 19 ++++++++++++++++--- code/idle.js | 11 +++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/code/boot.js b/code/boot.js index 72270340..afc2d2ec 100644 --- a/code/boot.js +++ b/code/boot.js @@ -251,6 +251,22 @@ window.setupMap = function() { map.on('movestart', function() { window.mapRunsUserAction = true; window.requests.abort(); window.startRefreshTimeout(-1); }); map.on('moveend', function() { window.mapRunsUserAction = false; window.startRefreshTimeout(ON_MOVE_REFRESH*1000); }); + // on zoomend, check to see the zoom level is an int, and reset the view if not + // (there's a bug on mobile where zoom levels sometimes end up as fractional levels. this causes the base map to be invisible) + map.on('zoomend', function() { + var z = map.getZoom(); + if (z != parseInt(z)) + { + console.warn('Non-integer zoom level at zoomend: '+z+' - trying to fix...'); + map.setZoom(parseInt(z), {animate:false}); + } + }); + + + // set a 'moveend' handler for the map to clear idle state. e.g. after mobile 'my location' is used. + // possibly some cases when resizing desktop browser too + map.on('moveend', idleReset); + window.addResumeFunction(function() { window.startRefreshTimeout(ON_MOVE_REFRESH*1000); }); // create the map data requester @@ -261,7 +277,6 @@ window.setupMap = function() { // (the code originally called the request function directly, and triggered a normal delay for the nxt refresh. // however, the moveend/zoomend gets triggered on map load, causing a duplicate refresh. this helps prevent that window.startRefreshTimeout(ON_MOVE_REFRESH*1000); - }; //adds a base layer to the map. done separately from the above, so that plugins that add base layers can be the default @@ -556,8 +571,6 @@ function boot() { } -console.log('...?'); - @@INCLUDERAW:external/load.js@@ diff --git a/code/idle.js b/code/idle.js index 41610775..1d6083e9 100644 --- a/code/idle.js +++ b/code/idle.js @@ -10,8 +10,7 @@ var idlePoll = function() { var hidden = (document.hidden || document.webkitHidden || document.mozHidden || document.msHidden || false); if (hidden) { - // window hidden - use the refresh time as the idle limit, rather than the max time - window._idleTimeLimit = window.REFRESH; + window.idleSet(); } } @@ -29,6 +28,14 @@ var idleReset = function () { window._idleTimeLimit = MAX_IDLE_TIME; }; +var idleSet = function() { + // force IITC to idle. used by the mobile app when switching to something else + if (!isIdle()) { + window._idleTImeLimit = 0; + } +} + + // only reset idle on mouse move where the coordinates are actually different. // some browsers send the event when not moving! var _lastMouseX=-1, _lastMouseY=-1;