Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TILES-4675 fix touch events #23

Merged
merged 3 commits into from
Nov 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class Joint extends Evented<EventTable> {

this.updateLabel();

document.addEventListener('touchmove', this.onMouseMove);
document.addEventListener('mousemove', this.onMouseMove);
}

Expand Down Expand Up @@ -153,15 +154,11 @@ export class Joint extends Evented<EventTable> {
}

const el = this.marker.getContent();
el.addEventListener('mousedown', () => {
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);
el.addEventListener('mouseover', this.onMouseOver);
el.addEventListener('mouseout', this.onMouseOut);
}
Expand Down Expand Up @@ -213,7 +210,18 @@ export class Joint extends Evented<EventTable> {

const container = this.map.getContainer();

this.coordinates = this.map.unproject(getMousePosition(container, ev.clientX, ev.clientY));
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') {
this.coordinates = this.map.unproject(
getMousePosition(container, ev.clientX, ev.clientY),
);
}

this.marker?.setCoordinates(this.coordinates);
};

Expand All @@ -224,6 +232,14 @@ export class Joint extends Evented<EventTable> {
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) {
Expand Down