@@ -131,6 +131,8 @@ define([
131131            this . beginPoint  =  new  Vec2 ( 0 ,  0 ) ; 
132132            this . lastPoint  =  new  Vec2 ( 0 ,  0 ) ; 
133133            this . lastRotation  =  0 ; 
134+             this . lastWheelEvent  =  0 ; 
135+             this . activeGestures  =  0 ; 
134136
135137            /** 
136138             * Internal use only. 
@@ -251,9 +253,9 @@ define([
251253                lookAt . position . latitude  +=  forwardDegrees  *  cosHeading  -  sideDegrees  *  sinHeading ; 
252254                lookAt . position . longitude  +=  forwardDegrees  *  sinHeading  +  sideDegrees  *  cosHeading ; 
253255                this . lastPoint . set ( tx ,  ty ) ; 
254-                 this . applyLookAtLimits ( lookAt ) ; 
255-                  this . wwd . camera . setFromLookAt ( lookAt ) ; 
256-                 this . wwd . redraw ( ) ; 
256+                 this . applyChanges ( ) ; 
257+             }   else   if   ( state   ===   WorldWind . ENDED   ||   state   ===   WorldWind . CANCELLED )   { 
258+                 this . gestureDidEnd ( ) ; 
257259            } 
258260        } ; 
259261
@@ -295,7 +297,7 @@ define([
295297
296298                // Transform the original view's modelview matrix to account for the gesture's change. 
297299                var  modelview  =  Matrix . fromIdentity ( ) ; 
298-                 lookAt . computeViewingTransform ( globe ,  modelview ) ; 
300+                 this . wwd . lookAtToViewingTransform ( lookAt ,  modelview ) ; 
299301                modelview . multiplyByTranslation ( point2 [ 0 ]  -  point1 [ 0 ] ,  point2 [ 1 ]  -  point1 [ 1 ] ,  point2 [ 2 ]  -  point1 [ 2 ] ) ; 
300302
301303                // Compute the globe point at the screen center from the perspective of the transformed view. 
@@ -313,9 +315,9 @@ define([
313315                lookAt . heading  =  params . heading ; 
314316                lookAt . tilt  =  params . tilt ; 
315317                lookAt . roll  =  params . roll ; 
316-                 this . applyLookAtLimits ( lookAt ) ; 
317-                  this . wwd . camera . setFromLookAt ( lookAt ) ; 
318-                 this . wwd . redraw ( ) ; 
318+                 this . applyChanges ( ) ; 
319+             }   else   if   ( state   ===   WorldWind . ENDED   ||   state   ===   WorldWind . CANCELLED )   { 
320+                 this . gestureDidEnd ( ) ; 
319321            } 
320322        } ; 
321323
@@ -337,9 +339,9 @@ define([
337339                // Apply the change in heading and tilt to this view's corresponding properties. 
338340                lookAt . heading  =  this . beginLookAt . heading  +  headingDegrees ; 
339341                lookAt . tilt  =  this . beginLookAt . tilt  +  tiltDegrees ; 
340-                 this . applyLookAtLimits ( lookAt ) ; 
341-                  this . wwd . camera . setFromLookAt ( lookAt ) ; 
342-                 this . wwd . redraw ( ) ; 
342+                 this . applyChanges ( ) ; 
343+             }   else   if   ( state   ===   WorldWind . ENDED   ||   state   ===   WorldWind . CANCELLED )   { 
344+                 this . gestureDidEnd ( ) ; 
343345            } 
344346        } ; 
345347
@@ -356,10 +358,10 @@ define([
356358                    // began. 
357359                    var  lookAt  =  this . lookAt ; 
358360                    lookAt . range  =  this . beginLookAt . range  /  scale ; 
359-                     this . applyLookAtLimits ( lookAt ) ; 
360-                     this . wwd . camera . setFromLookAt ( lookAt ) ; 
361-                     this . wwd . redraw ( ) ; 
361+                     this . applyChanges ( ) ; 
362362                } 
363+             }  else  if  ( state  ===  WorldWind . ENDED  ||  state  ===  WorldWind . CANCELLED )  { 
364+                 this . gestureDidEnd ( ) ; 
363365            } 
364366        } ; 
365367
@@ -378,9 +380,9 @@ define([
378380                var  lookAt  =  this . lookAt ; 
379381                lookAt . heading  -=  rotation  -  this . lastRotation ; 
380382                this . lastRotation  =  rotation ; 
381-                 this . applyLookAtLimits ( lookAt ) ; 
382-                  this . wwd . camera . setFromLookAt ( lookAt ) ; 
383-                 this . wwd . redraw ( ) ; 
383+                 this . applyChanges ( ) ; 
384+             }   else   if   ( state   ===   WorldWind . ENDED   ||   state   ===   WorldWind . CANCELLED )   { 
385+                 this . gestureDidEnd ( ) ; 
384386            } 
385387        } ; 
386388
@@ -397,16 +399,21 @@ define([
397399                var  tiltDegrees  =  - 90  *  ty  /  this . wwd . canvas . clientHeight ; 
398400                // Apply the change in heading and tilt to this view's corresponding properties. 
399401                var  lookAt  =  this . lookAt ; 
400-                 lookAt . tilt  =  this . beginTilt  +  tiltDegrees ; 
401-                 this . applyLookAtLimits ( lookAt ) ; 
402-                  this . wwd . camera . setFromLookAt ( lookAt ) ; 
403-                 this . wwd . redraw ( ) ; 
402+                 lookAt . tilt  =  this . beginLookAt . tilt  +  tiltDegrees ; 
403+                 this . applyChanges ( ) ; 
404+             }   else   if   ( state   ===   WorldWind . ENDED   ||   state   ===   WorldWind . CANCELLED )   { 
405+                 this . gestureDidEnd ( ) ; 
404406            } 
405407        } ; 
406408
407409        // Intentionally not documented. 
408410        BasicWorldWindowController . prototype . handleWheelEvent  =  function  ( event )  { 
409-             var  lookAt  =  this . wwd . camera . getAsLookAt ( this . lookAt ) ; 
411+             var  lookAt  =  this . lookAt ; 
412+             var  timeStamp  =  event . timeStamp ; 
413+             if  ( timeStamp  -  this . lastWheelEvent  >  500 )  { 
414+                 this . wwd . cameraAsLookAt ( lookAt ) ; 
415+                 this . lastWheelEvent  =  timeStamp ; 
416+             } 
410417            // Normalize the wheel delta based on the wheel delta mode. This produces a roughly consistent delta across 
411418            // browsers and input devices. 
412419            var  normalizedDelta ; 
@@ -425,17 +432,17 @@ define([
425432
426433            // Apply the scale to this view's properties. 
427434            lookAt . range  *=  scale ; 
428-             this . applyLookAtLimits ( lookAt ) ; 
429-             this . wwd . camera . setFromLookAt ( lookAt ) ; 
430-             this . wwd . redraw ( ) ; 
435+             this . applyChanges ( ) ; 
431436        } ; 
432437
433438        /** 
434439         * Internal use only. 
435-          * Limits the properties of a look at view to prevent unwanted navigation behaviour. 
440+          * Limits the properties of a look at view to prevent unwanted navigation behaviour and update camera view . 
436441         * @ignore  
437442         */ 
438-         BasicWorldWindowController . prototype . applyLookAtLimits  =  function  ( lookAt )  { 
443+         BasicWorldWindowController . prototype . applyChanges  =  function  ( )  { 
444+             var  lookAt  =  this . lookAt ; 
445+ 
439446            // Clamp latitude to between -90 and +90, and normalize longitude to between -180 and +180. 
440447            lookAt . position . latitude  =  WWMath . clamp ( lookAt . position . latitude ,  - 90 ,  90 ) ; 
441448            lookAt . position . longitude  =  Angle . normalizedDegreesLongitude ( lookAt . position . longitude ) ; 
@@ -463,16 +470,10 @@ define([
463470                // Force tilt to 0 when in 2D mode to keep the viewer looking straight down. 
464471                lookAt . tilt  =  0 ; 
465472            } 
466-         } ; 
467473
468-         /** 
469-          * Documented in super-class. 
470-          * @ignore  
471-          */ 
472-         BasicWorldWindowController . prototype . applyLimits  =  function  ( )  { 
473-             var  lookAt  =  this . wwd . camera . getAsLookAt ( this . lookAt ) ; 
474-             this . applyLookAtLimits ( lookAt ) ; 
475-             this . wwd . camera . setFromLookAt ( lookAt ) ; 
474+             // Update camera view. 
475+             this . wwd . cameraFromLookAt ( lookAt ) ; 
476+             this . wwd . redraw ( ) ; 
476477        } ; 
477478
478479        /** 
@@ -481,8 +482,17 @@ define([
481482         * @ignore  
482483         */ 
483484        BasicWorldWindowController . prototype . gestureDidBegin  =  function  ( )  { 
484-             this . wwd . camera . getAsLookAt ( this . beginLookAt ) ; 
485-             this . lookAt . copy ( this . beginLookAt ) ; 
485+             if  ( this . activeGestures ++  ===  0 )  { 
486+                 this . wwd . cameraAsLookAt ( this . beginLookAt ) ; 
487+                 this . lookAt . copy ( this . beginLookAt ) ; 
488+             } 
489+         } ; 
490+ 
491+         BasicWorldWindowController . prototype . gestureDidEnd  =  function  ( )  { 
492+             // this should always be the case, but we check anyway 
493+             if  ( this . activeGestures  >  0 )  { 
494+                 this . activeGestures -- ; 
495+             } 
486496        } ; 
487497
488498        return  BasicWorldWindowController ; 
0 commit comments