From 312143bd0487d2f4cfb17494a95dff7a1cc16bd4 Mon Sep 17 00:00:00 2001 From: Andrey Kuznecov Date: Thu, 27 Oct 2022 21:49:52 +0700 Subject: [PATCH 1/3] fix touch events --- src/joint.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/joint.ts b/src/joint.ts index 7e47933..490591f 100644 --- a/src/joint.ts +++ b/src/joint.ts @@ -83,6 +83,7 @@ export class Joint extends Evented { this.updateLabel(); + document.addEventListener('touchmove', this.onMouseMove); document.addEventListener('mousemove', this.onMouseMove); } @@ -160,8 +161,16 @@ export class Joint extends Evented { targetData: this, }); }); + el.addEventListener('touchstart', () => { + this.disablePopup(); + this.dragging = true; + this.emit('dragstart', { + targetData: this, + }); + }); document.addEventListener('mouseup', this.onMouseUp); + document.addEventListener('touchend', this.onMouseUp); el.addEventListener('mouseover', this.onMouseOver); el.addEventListener('mouseout', this.onMouseOut); } @@ -213,7 +222,18 @@ export class Joint extends Evented { const container = this.map.getContainer(); - this.coordinates = this.map.unproject(getMousePosition(container, ev.clientX, ev.clientY)); + if (ev.type == 'touchmove') { + var evt = typeof ev.originalEvent === 'undefined' ? ev : ev.originalEvent; + var touch = evt.touches[0] || evt.changedTouches[0]; + this.coordinates = this.map.unproject( + getMousePosition(container, touch.pageX, touch.pageY), + ); + } else if (ev.type == 'mousemove') { + this.coordinates = this.map.unproject( + getMousePosition(container, ev.clientX, ev.clientY), + ); + } + this.marker?.setCoordinates(this.coordinates); }; From 62688a9a9dfb4833b233e78fe36d6bb28ea325fb Mon Sep 17 00:00:00 2001 From: Andrey Kuznecov Date: Thu, 27 Oct 2022 22:27:40 +0700 Subject: [PATCH 2/3] fix linter --- src/joint.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/joint.ts b/src/joint.ts index 490591f..b83e1cb 100644 --- a/src/joint.ts +++ b/src/joint.ts @@ -222,13 +222,13 @@ export class Joint extends Evented { const container = this.map.getContainer(); - if (ev.type == 'touchmove') { - var evt = typeof ev.originalEvent === 'undefined' ? ev : ev.originalEvent; - var touch = evt.touches[0] || evt.changedTouches[0]; + if (ev.type === 'touchmove') { + const evt = typeof ev.originalEvent === 'undefined' ? ev : ev.originalEvent; + const touch = evt.touches[0] || evt.changedTouches[0]; this.coordinates = this.map.unproject( getMousePosition(container, touch.pageX, touch.pageY), ); - } else if (ev.type == 'mousemove') { + } else if (ev.type === 'mousemove') { this.coordinates = this.map.unproject( getMousePosition(container, ev.clientX, ev.clientY), ); From 847515dd0ea49f87a3067f7235e26e4f3847a6ea Mon Sep 17 00:00:00 2001 From: Andrey Kuznecov Date: Wed, 2 Nov 2022 21:55:42 +0700 Subject: [PATCH 3/3] fix revew --- src/joint.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/joint.ts b/src/joint.ts index b83e1cb..b04b6ce 100644 --- a/src/joint.ts +++ b/src/joint.ts @@ -154,20 +154,8 @@ export class Joint extends Evented { } const el = this.marker.getContent(); - el.addEventListener('mousedown', () => { - this.disablePopup(); - this.dragging = true; - this.emit('dragstart', { - targetData: this, - }); - }); - el.addEventListener('touchstart', () => { - this.disablePopup(); - this.dragging = true; - this.emit('dragstart', { - targetData: this, - }); - }); + el.addEventListener('mousedown', this.omMouseDown); + el.addEventListener('touchstart', this.omMouseDown); document.addEventListener('mouseup', this.onMouseUp); document.addEventListener('touchend', this.onMouseUp); @@ -244,6 +232,14 @@ export class Joint extends Evented { this.dragging = false; this.emit('dragend'); }; + + private omMouseDown = () => { + this.disablePopup(); + this.dragging = true; + this.emit('dragstart', { + targetData: this, + }); + }; } function createLabel(map: mapgl.Map, coordinates: GeoPoint, distance: number, isFirst: boolean) {