Better fix for changing pointer ids on event target change

This commit is contained in:
Andreas Hocevar
2022-06-15 16:29:07 +02:00
parent 307e9892fc
commit f99dc1e9ec
2 changed files with 15 additions and 13 deletions

View File

@@ -73,7 +73,7 @@ class MapBrowserEventHandler extends Target {
this.activePointers_ = 0;
/**
* @type {!Object<number, boolean>}
* @type {!Object<number, Event>}
* @private
*/
this.trackedTouches_ = {};
@@ -169,14 +169,26 @@ class MapBrowserEventHandler extends Target {
*/
updateActivePointers_(pointerEvent) {
const event = pointerEvent;
const id = event.pointerId;
if (
event.type == MapBrowserEventType.POINTERUP ||
event.type == MapBrowserEventType.POINTERCANCEL
) {
delete this.trackedTouches_[event.pointerId];
delete this.trackedTouches_[id];
} else if (event.type == MapBrowserEventType.POINTERDOWN) {
this.trackedTouches_[event.pointerId] = true;
this.trackedTouches_[id] = event;
} else if (event.type == MapBrowserEventType.POINTERMOVE) {
for (const pointerId in this.trackedTouches_) {
if (this.trackedTouches_[pointerId].target !== event.target) {
// Some platforms assign a new pointerId when the target changes.
// If this happens, delete one tracked pointer. If there is more
// than one tracked pointer for the old target, it will be cleared
// by subsequent POINTERUP events from other pointers.
delete this.trackedTouches_[pointerId];
break;
}
}
}
this.activePointers_ = Object.keys(this.trackedTouches_).length;
}

View File

@@ -195,16 +195,6 @@ class PointerInteraction extends Interaction {
const id = event.pointerId.toString();
if (mapBrowserEvent.type == MapBrowserEventType.POINTERUP) {
delete this.trackedPointers_[id];
for (const pointerId in this.trackedPointers_) {
if (this.trackedPointers_[pointerId].target !== event.target) {
// Some platforms assign a new pointerId when the target changes.
// If this happens, delete one tracked pointer. If there is more
// than one tracked pointer for the old target, it will be cleared
// by subsequent POINTERUP events from other pointers.
delete this.trackedPointers_[pointerId];
break;
}
}
} else if (mapBrowserEvent.type == MapBrowserEventType.POINTERDOWN) {
this.trackedPointers_[id] = event;
} else if (id in this.trackedPointers_) {