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
This commit is contained in:
		
							
								
								
									
										19
									
								
								code/boot.js
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								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('movestart', function() { window.mapRunsUserAction = true; window.requests.abort(); window.startRefreshTimeout(-1); }); | ||||||
|   map.on('moveend', function() { window.mapRunsUserAction = false; window.startRefreshTimeout(ON_MOVE_REFRESH*1000); }); |   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); }); |   window.addResumeFunction(function() { window.startRefreshTimeout(ON_MOVE_REFRESH*1000); }); | ||||||
|  |  | ||||||
|   // create the map data requester |   // 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. |   // (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 |   //  however, the moveend/zoomend gets triggered on map load, causing a duplicate refresh. this helps prevent that | ||||||
|   window.startRefreshTimeout(ON_MOVE_REFRESH*1000); |   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 | //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@@ | @@INCLUDERAW:external/load.js@@ | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								code/idle.js
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								code/idle.js
									
									
									
									
									
								
							| @@ -10,8 +10,7 @@ var idlePoll = function() { | |||||||
|  |  | ||||||
|   var hidden = (document.hidden || document.webkitHidden || document.mozHidden || document.msHidden || false); |   var hidden = (document.hidden || document.webkitHidden || document.mozHidden || document.msHidden || false); | ||||||
|   if (hidden) { |   if (hidden) { | ||||||
|     // window hidden - use the refresh time as the idle limit, rather than the max time |     window.idleSet(); | ||||||
|     window._idleTimeLimit = window.REFRESH; |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -29,6 +28,14 @@ var idleReset = function () { | |||||||
|   window._idleTimeLimit = MAX_IDLE_TIME; |   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. | // only reset idle on mouse move where the coordinates are actually different. | ||||||
| // some browsers send the event when not moving! | // some browsers send the event when not moving! | ||||||
| var _lastMouseX=-1, _lastMouseY=-1; | var _lastMouseX=-1, _lastMouseY=-1; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user