Skip to content
Open
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
8 changes: 8 additions & 0 deletions web/src/distancemeasure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class DistanceMeasure implements maplibregl.IControl {
document.addEventListener('keyup', (e) => {
if (e.key === 'Escape' && this._measuring) {
this._removeMeasuring()
} else if (e.key === 'm' && !this._isTypingTarget(e.target)) {
this._onClickDistanceMeasure()
}
})

Expand All @@ -59,6 +61,12 @@ class DistanceMeasure implements maplibregl.IControl {
this._map = undefined
}

_isTypingTarget(target: EventTarget | null): boolean {
if (!(target instanceof HTMLElement)) return false
const tag = target.tagName
return tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT' || target.isContentEditable
}

_onClickDistanceMeasure() {
if (this._measuring) {
this._removeMeasuring()
Expand Down