mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 03:42:37 +02:00
chore: remove U.Keys, and refactor global shorcuts
This commit is contained in:
parent
ef94389c03
commit
9d211005b1
3 changed files with 66 additions and 81 deletions
|
@ -20,6 +20,10 @@ export class Panel {
|
||||||
if (!this.mode) this.mode = mode
|
if (!this.mode) this.mode = mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isOpen() {
|
||||||
|
return this.container.classList.contains("on")
|
||||||
|
}
|
||||||
|
|
||||||
open({ content, className, actions = [] } = {}) {
|
open({ content, className, actions = [] } = {}) {
|
||||||
this.container.className = `with-transition panel ${this.classname} ${this.mode || ''}`
|
this.container.className = `with-transition panel ${this.classname} ${this.mode || ''}`
|
||||||
this.container.innerHTML = ''
|
this.container.innerHTML = ''
|
||||||
|
|
|
@ -245,33 +245,6 @@ L.DomEvent.once = (el, types, fn, context) => {
|
||||||
return L.DomEvent.on(el, types, fn, context).on(el, types, handler, context)
|
return L.DomEvent.on(el, types, fn, context).on(el, types, handler, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Global events
|
|
||||||
*/
|
|
||||||
U.Keys = {
|
|
||||||
LEFT: 37,
|
|
||||||
UP: 38,
|
|
||||||
RIGHT: 39,
|
|
||||||
DOWN: 40,
|
|
||||||
TAB: 9,
|
|
||||||
ENTER: 13,
|
|
||||||
ESC: 27,
|
|
||||||
APPLE: 91,
|
|
||||||
SHIFT: 16,
|
|
||||||
ALT: 17,
|
|
||||||
CTRL: 18,
|
|
||||||
E: 69,
|
|
||||||
F: 70,
|
|
||||||
H: 72,
|
|
||||||
I: 73,
|
|
||||||
L: 76,
|
|
||||||
M: 77,
|
|
||||||
O: 79,
|
|
||||||
P: 80,
|
|
||||||
S: 83,
|
|
||||||
Z: 90,
|
|
||||||
}
|
|
||||||
|
|
||||||
L.LatLng.prototype.isValid = function () {
|
L.LatLng.prototype.isValid = function () {
|
||||||
return (
|
return (
|
||||||
isFinite(this.lat) &&
|
isFinite(this.lat) &&
|
||||||
|
|
|
@ -518,73 +518,81 @@ U.Map = L.Map.extend({
|
||||||
|
|
||||||
initShortcuts: function () {
|
initShortcuts: function () {
|
||||||
const globalShortcuts = function (e) {
|
const globalShortcuts = function (e) {
|
||||||
const key = e.keyCode
|
|
||||||
const hasModifier = (e.ctrlKey || e.metaKey) && !e.shiftKey
|
|
||||||
|
|
||||||
/* Generic shortcuts */
|
if (e.key === 'Escape') {
|
||||||
if (key === U.Keys.F && hasModifier) {
|
|
||||||
L.DomEvent.stop(e)
|
|
||||||
this.search()
|
|
||||||
} else if (e.keyCode === U.Keys.ESC) {
|
|
||||||
if (this.dialog.visible) {
|
if (this.dialog.visible) {
|
||||||
this.dialog.close()
|
this.dialog.close()
|
||||||
} else {
|
} else if (this.editEnabled && this.editTools.drawing()) {
|
||||||
this.panel.close()
|
this.editTools.stopDrawing()
|
||||||
|
} else if (this.measureTools.enabled()) {
|
||||||
|
this.measureTools.stopDrawing()
|
||||||
|
} else if (this.editPanel?.isOpen()) {
|
||||||
this.editPanel?.close()
|
this.editPanel?.close()
|
||||||
|
} else if (this.fullPanel?.isOpen()) {
|
||||||
this.fullPanel?.close()
|
this.fullPanel?.close()
|
||||||
|
} else if (this.panel.isOpen()) {
|
||||||
|
this.panel.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.hasEditMode()) return
|
// From now on, only ctrl/meta shortcut
|
||||||
|
if (!(e.ctrlKey || e.metaKey) || e.shiftKey) return
|
||||||
|
|
||||||
|
if (e.key === 'f') {
|
||||||
|
L.DomEvent.stop(e)
|
||||||
|
this.search()
|
||||||
|
}
|
||||||
|
|
||||||
/* Edit mode only shortcuts */
|
/* Edit mode only shortcuts */
|
||||||
if (key === U.Keys.E && hasModifier && !this.editEnabled) {
|
if (!this.hasEditMode()) return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Edit mode Off
|
||||||
|
if (!this.editEnabled) {
|
||||||
|
switch (e.key) {
|
||||||
|
case 'e':
|
||||||
L.DomEvent.stop(e)
|
L.DomEvent.stop(e)
|
||||||
this.enableEdit()
|
this.enableEdit()
|
||||||
} else if (key === U.Keys.E && hasModifier && this.editEnabled && !this.isDirty) {
|
break
|
||||||
L.DomEvent.stop(e)
|
|
||||||
this.disableEdit()
|
|
||||||
}
|
}
|
||||||
if (key === U.Keys.S && hasModifier) {
|
return
|
||||||
L.DomEvent.stop(e)
|
|
||||||
if (this.isDirty) {
|
|
||||||
this.save()
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (key === U.Keys.Z && hasModifier && this.isDirty) {
|
// Edit mode on
|
||||||
L.DomEvent.stop(e)
|
let used = true
|
||||||
this.askForReset()
|
switch (e.key) {
|
||||||
}
|
case 'e':
|
||||||
if (key === U.Keys.M && hasModifier && this.editEnabled) {
|
if (!this.isDirty) this.disableEdit()
|
||||||
L.DomEvent.stop(e)
|
break
|
||||||
|
case 's':
|
||||||
|
if (this.isDirty) this.save()
|
||||||
|
break
|
||||||
|
case 'z':
|
||||||
|
if (this.isDirty) this.askForReset()
|
||||||
|
break
|
||||||
|
case 'm':
|
||||||
this.editTools.startMarker()
|
this.editTools.startMarker()
|
||||||
}
|
break
|
||||||
if (key === U.Keys.P && hasModifier && this.editEnabled) {
|
case 'p':
|
||||||
L.DomEvent.stop(e)
|
|
||||||
this.editTools.startPolygon()
|
this.editTools.startPolygon()
|
||||||
}
|
break
|
||||||
if (key === U.Keys.L && hasModifier && this.editEnabled) {
|
case 'l':
|
||||||
L.DomEvent.stop(e)
|
|
||||||
this.editTools.startPolyline()
|
this.editTools.startPolyline()
|
||||||
}
|
break
|
||||||
if (key === U.Keys.I && hasModifier && this.editEnabled) {
|
case 'i':
|
||||||
L.DomEvent.stop(e)
|
|
||||||
this.importer.open()
|
this.importer.open()
|
||||||
}
|
break
|
||||||
if (key === U.Keys.O && hasModifier && this.editEnabled) {
|
case 'o':
|
||||||
L.DomEvent.stop(e)
|
|
||||||
this.importer.openFiles()
|
this.importer.openFiles()
|
||||||
}
|
break
|
||||||
if (key === U.Keys.H && hasModifier && this.editEnabled) {
|
case 'h':
|
||||||
L.DomEvent.stop(e)
|
|
||||||
this.help.show('edit')
|
this.help.show('edit')
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
used = false
|
||||||
}
|
}
|
||||||
if (e.keyCode === U.Keys.ESC) {
|
if (used) L.DomEvent.stop(e)
|
||||||
if (this.editEnabled && this.editTools.drawing()) {
|
|
||||||
this.editTools.stopDrawing()
|
|
||||||
}
|
|
||||||
if (this.measureTools.enabled()) this.measureTools.stopDrawing()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
L.DomEvent.addListener(document, 'keydown', globalShortcuts, this)
|
L.DomEvent.addListener(document, 'keydown', globalShortcuts, this)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue