@@ -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 . cameraFromLookAt ( lookAt ) ;
256- this . wwd . redraw ( ) ;
256+ this . applyChanges ( ) ;
257+ } else if ( state === WorldWind . ENDED || state === WorldWind . CANCELLED ) {
258+ gestureDidEnd ( ) ;
257259 }
258260 } ;
259261
@@ -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 . cameraFromLookAt ( lookAt ) ;
318- this . wwd . redraw ( ) ;
318+ this . applyChanges ( ) ;
319+ } else if ( state === WorldWind . ENDED || state === WorldWind . CANCELLED ) {
320+ 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 . cameraFromLookAt ( lookAt ) ;
342- this . wwd . redraw ( ) ;
342+ this . applyChanges ( ) ;
343+ } else if ( state === WorldWind . ENDED || state === WorldWind . CANCELLED ) {
344+ 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 . cameraFromLookAt ( lookAt ) ;
361- this . wwd . redraw ( ) ;
361+ this . applyChanges ( ) ;
362362 }
363+ } else if ( state === WorldWind . ENDED || state === WorldWind . CANCELLED ) {
364+ 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 . cameraFromLookAt ( lookAt ) ;
383- this . wwd . redraw ( ) ;
383+ this . applyChanges ( ) ;
384+ } else if ( state === WorldWind . ENDED || state === WorldWind . CANCELLED ) {
385+ 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 . cameraFromLookAt ( 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+ gestureDidEnd ( ) ;
404406 }
405407 } ;
406408
407409 // Intentionally not documented.
408410 BasicWorldWindowController . prototype . handleWheelEvent = function ( event ) {
409- var lookAt = this . wwd . cameraAsLookAt ( 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,15 @@ define([
425432
426433 // Apply the scale to this view's properties.
427434 lookAt . range *= scale ;
428- this . applyLookAtLimits ( lookAt ) ;
429- this . wwd . cameraFromLookAt ( 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 ( ) {
439444 // Clamp latitude to between -90 and +90, and normalize longitude to between -180 and +180.
440445 lookAt . position . latitude = WWMath . clamp ( lookAt . position . latitude , - 90 , 90 ) ;
441446 lookAt . position . longitude = Angle . normalizedDegreesLongitude ( lookAt . position . longitude ) ;
@@ -463,16 +468,10 @@ define([
463468 // Force tilt to 0 when in 2D mode to keep the viewer looking straight down.
464469 lookAt . tilt = 0 ;
465470 }
466- } ;
467471
468- /**
469- * Documented in super-class.
470- * @ignore
471- */
472- BasicWorldWindowController . prototype . applyLimits = function ( ) {
473- var lookAt = this . wwd . cameraAsLookAt ( this . lookAt ) ;
474- this . applyLookAtLimits ( lookAt ) ;
472+ // Update camera view.
475473 this . wwd . cameraFromLookAt ( lookAt ) ;
474+ this . wwd . redraw ( ) ;
476475 } ;
477476
478477 /**
@@ -481,8 +480,17 @@ define([
481480 * @ignore
482481 */
483482 BasicWorldWindowController . prototype . gestureDidBegin = function ( ) {
484- this . wwd . cameraAsLookAt ( this . beginLookAt ) ;
485- this . lookAt . copy ( this . beginLookAt ) ;
483+ if ( activeGestures ++ === 0 ) {
484+ this . wwd . cameraAsLookAt ( this . beginLookAt ) ;
485+ this . lookAt . copy ( this . beginLookAt ) ;
486+ }
487+ } ;
488+
489+ BasicWorldWindowController . prototype . gestureDidEnd = function ( ) {
490+ // this should always be the case, but we check anyway
491+ if ( activeGestures > 0 ) {
492+ activeGestures -- ;
493+ }
486494 } ;
487495
488496 return BasicWorldWindowController ;
0 commit comments