@@ -133,6 +133,14 @@ define([
133
133
return ( getTimestamp ( ) - screenSpaceEventHandler . _lastSeenTouchEvent ) > ScreenSpaceEventHandler . mouseEmulationIgnoreMilliseconds ;
134
134
}
135
135
136
+ function checkPixelTolerance ( startPosition , endPosition , pixelTolerance ) {
137
+ var xDiff = startPosition . x - endPosition . x ;
138
+ var yDiff = startPosition . y - endPosition . y ;
139
+ var totalPixels = Math . sqrt ( xDiff * xDiff + yDiff * yDiff ) ;
140
+
141
+ return totalPixels < pixelTolerance ;
142
+ }
143
+
136
144
function handleMouseDown ( screenSpaceEventHandler , event ) {
137
145
if ( ! canProcessMouseEvent ( screenSpaceEventHandler ) ) {
138
146
return ;
@@ -193,11 +201,7 @@ define([
193
201
194
202
if ( defined ( clickAction ) ) {
195
203
var startPosition = screenSpaceEventHandler . _primaryStartPosition ;
196
- var xDiff = startPosition . x - position . x ;
197
- var yDiff = startPosition . y - position . y ;
198
- var totalPixels = Math . sqrt ( xDiff * xDiff + yDiff * yDiff ) ;
199
-
200
- if ( totalPixels < screenSpaceEventHandler . _clickPixelTolerance ) {
204
+ if ( checkPixelTolerance ( startPosition , position , screenSpaceEventHandler . _clickPixelTolerance ) ) {
201
205
Cartesian2 . clone ( position , mouseClickEvent . position ) ;
202
206
203
207
clickAction ( mouseClickEvent ) ;
@@ -398,11 +402,13 @@ define([
398
402
var touchClickEvent = {
399
403
position : new Cartesian2 ( )
400
404
} ;
405
+ var touchHoldEvent = {
406
+ position : new Cartesian2 ( )
407
+ } ;
401
408
402
409
function fireTouchEvents ( screenSpaceEventHandler , event ) {
403
410
var modifier = getModifier ( event ) ;
404
411
var positions = screenSpaceEventHandler . _positions ;
405
- var previousPositions = screenSpaceEventHandler . _previousPositions ;
406
412
var numberOfTouches = positions . length ;
407
413
var action ;
408
414
var clickAction ;
@@ -411,6 +417,12 @@ define([
411
417
if ( numberOfTouches !== 1 && screenSpaceEventHandler . _buttonDown [ MouseButton . LEFT ] ) {
412
418
// transitioning from single touch, trigger UP and might trigger CLICK
413
419
screenSpaceEventHandler . _buttonDown [ MouseButton . LEFT ] = false ;
420
+
421
+ if ( defined ( screenSpaceEventHandler . _touchHoldTimer ) ) {
422
+ clearTimeout ( screenSpaceEventHandler . _touchHoldTimer ) ;
423
+ screenSpaceEventHandler . _touchHoldTimer = undefined ;
424
+ }
425
+
414
426
action = screenSpaceEventHandler . getInputAction ( ScreenSpaceEventType . LEFT_UP , modifier ) ;
415
427
416
428
if ( defined ( action ) ) {
@@ -419,25 +431,23 @@ define([
419
431
action ( touchEndEvent ) ;
420
432
}
421
433
422
- if ( numberOfTouches === 0 ) {
434
+ if ( numberOfTouches === 0 && ! screenSpaceEventHandler . _isTouchHolding ) {
423
435
// releasing single touch, check for CLICK
424
436
clickAction = screenSpaceEventHandler . getInputAction ( ScreenSpaceEventType . LEFT_CLICK , modifier ) ;
425
437
426
438
if ( defined ( clickAction ) ) {
427
439
var startPosition = screenSpaceEventHandler . _primaryStartPosition ;
428
- var endPosition = previousPositions . values [ 0 ] ;
429
- var xDiff = startPosition . x - endPosition . x ;
430
- var yDiff = startPosition . y - endPosition . y ;
431
- var totalPixels = Math . sqrt ( xDiff * xDiff + yDiff * yDiff ) ;
432
-
433
- if ( totalPixels < screenSpaceEventHandler . _clickPixelTolerance ) {
440
+ var endPosition = screenSpaceEventHandler . _previousPositions . values [ 0 ] ;
441
+ if ( checkPixelTolerance ( startPosition , endPosition , screenSpaceEventHandler . _clickPixelTolerance ) ) {
434
442
Cartesian2 . clone ( screenSpaceEventHandler . _primaryPosition , touchClickEvent . position ) ;
435
443
436
444
clickAction ( touchClickEvent ) ;
437
445
}
438
446
}
439
447
}
440
448
449
+ screenSpaceEventHandler . _isTouchHolding = false ;
450
+
441
451
// Otherwise don't trigger CLICK, because we are adding more touches.
442
452
}
443
453
@@ -469,6 +479,25 @@ define([
469
479
action ( touchStartEvent ) ;
470
480
}
471
481
482
+ screenSpaceEventHandler . _touchHoldTimer = setTimeout ( function ( ) {
483
+ if ( ! screenSpaceEventHandler . isDestroyed ( ) ) {
484
+ screenSpaceEventHandler . _touchHoldTimer = undefined ;
485
+ screenSpaceEventHandler . _isTouchHolding = true ;
486
+
487
+ clickAction = screenSpaceEventHandler . getInputAction ( ScreenSpaceEventType . RIGHT_CLICK , modifier ) ;
488
+
489
+ if ( defined ( clickAction ) ) {
490
+ var startPosition = screenSpaceEventHandler . _primaryStartPosition ;
491
+ var endPosition = screenSpaceEventHandler . _previousPositions . values [ 0 ] ;
492
+ if ( checkPixelTolerance ( startPosition , endPosition , screenSpaceEventHandler . _holdPixelTolerance ) ) {
493
+ Cartesian2 . clone ( screenSpaceEventHandler . _primaryPosition , touchHoldEvent . position ) ;
494
+
495
+ clickAction ( touchHoldEvent ) ;
496
+ }
497
+ }
498
+ }
499
+ } , ScreenSpaceEventHandler . touchHoldDelayMilliseconds ) ;
500
+
472
501
event . preventDefault ( ) ;
473
502
}
474
503
@@ -669,6 +698,7 @@ define([
669
698
RIGHT : false
670
699
} ;
671
700
this . _isPinching = false ;
701
+ this . _isTouchHolding = false ;
672
702
this . _lastSeenTouchEvent = - ScreenSpaceEventHandler . mouseEmulationIgnoreMilliseconds ;
673
703
674
704
this . _primaryStartPosition = new Cartesian2 ( ) ;
@@ -680,9 +710,12 @@ define([
680
710
681
711
this . _removalFunctions = [ ] ;
682
712
713
+ this . _touchHoldTimer = undefined ;
714
+
683
715
// TODO: Revisit when doing mobile development. May need to be configurable
684
716
// or determined based on the platform?
685
717
this . _clickPixelTolerance = 5 ;
718
+ this . _holdPixelTolerance = 25 ;
686
719
687
720
this . _element = defaultValue ( element , document ) ;
688
721
@@ -799,5 +832,13 @@ define([
799
832
*/
800
833
ScreenSpaceEventHandler . mouseEmulationIgnoreMilliseconds = 800 ;
801
834
835
+ /**
836
+ * The amount of time, in milliseconds, before a touch on the screen becomes a
837
+ * touch and hold.
838
+ * @type {Number }
839
+ * @default 1500
840
+ */
841
+ ScreenSpaceEventHandler . touchHoldDelayMilliseconds = 1500 ;
842
+
802
843
return ScreenSpaceEventHandler ;
803
844
} ) ;
0 commit comments