forked from openstreetmap/iD
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace inconsistently-supported dblclick events with custom handler …
…on platforms supporting pointer events Fix issue where double-tap-to-zoom would not be properly disabled when drawing on touch devices (close openstreetmap#2128) Support adding nodes to ways with double-tap with on touch devices (close openstreetmap#2677) Support double-tap-to-zoom with styluses on touch devices Don't accept double click/tap events if the taps are far apart Don't re-enter modeSelect when clicking the selected feature again
- Loading branch information
1 parent
a1edf3a
commit 11dcf16
Showing
9 changed files
with
141 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { dispatch as d3_dispatch } from 'd3-dispatch'; | ||
import { mouse as d3_mouse } from 'd3-selection'; | ||
|
||
import { utilRebind } from './rebind'; | ||
import { geoVecLength } from '../geo/vector'; | ||
|
||
// a double-click / double-tap event detector with wider | ||
export function utilDoubleUp() { | ||
|
||
var dispatch = d3_dispatch('doubleUp'); | ||
|
||
var _maxTimespan = 500; // milliseconds | ||
var _maxDistance = 20; // web pixels; be somewhat generous to account for touch devices | ||
var _pointer; // object representing the pointer that could trigger double up | ||
|
||
function pointerIsValidFor(loc) { | ||
// second pointerup must occur within a small timeframe after the first pointerdown | ||
return new Date().getTime() - _pointer.startTime <= _maxTimespan && | ||
// all pointer events must occur within a small distance of the first pointerdown | ||
geoVecLength(_pointer.startLoc, loc) <= _maxDistance; | ||
} | ||
|
||
function pointerdown() { | ||
// d3_mouse works since pointer events inherit from mouse events | ||
var loc = d3_mouse(this); | ||
|
||
if (_pointer && !pointerIsValidFor(loc)) { | ||
// if this pointer is no longer valid, clear it so another can be started | ||
_pointer = undefined; | ||
} | ||
if (!_pointer) { | ||
// don't rely on the pointerId since it can change between down events on touch devices | ||
_pointer = { | ||
startLoc: loc, | ||
startTime: new Date().getTime(), | ||
upCount: 0 | ||
}; | ||
} | ||
} | ||
|
||
function pointerup() { | ||
if (!_pointer) return; | ||
|
||
_pointer.upCount += 1; | ||
|
||
if (_pointer.upCount === 2) { // double up! | ||
var loc = d3_mouse(this); | ||
if (pointerIsValidFor(loc)) { | ||
dispatch.call('doubleUp', this, loc); | ||
} | ||
// clear the pointer info in any case | ||
_pointer = undefined; | ||
} | ||
} | ||
|
||
function doubleUp(selection) { | ||
if ('PointerEvent' in window) { | ||
// dblclick isn't well supported on touch devices so manually use | ||
// pointer events if they're available | ||
selection | ||
.on('pointerdown.doubleUp', pointerdown) | ||
.on('pointerup.doubleUp', pointerup); | ||
} else { | ||
// fallback to dblclick | ||
selection | ||
.on('dblclick.doubleUp', function() { | ||
dispatch.call('doubleUp', this, d3_mouse(this)); | ||
}); | ||
} | ||
} | ||
|
||
doubleUp.off = function(selection) { | ||
selection | ||
.on('pointerdown.doubleUp', null) | ||
.on('pointerup.doubleUp', null) | ||
.on('dblclick.doubleUp', null); | ||
}; | ||
|
||
return utilRebind(doubleUp, dispatch, 'on'); | ||
} |
Oops, something went wrong.