mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 03:42:37 +02:00
fix: fix contextmenu positionning when map is not full screen
This commit is contained in:
parent
c90618a248
commit
cba0af96f6
2 changed files with 9 additions and 6 deletions
|
@ -63,16 +63,18 @@ export class Positioned {
|
||||||
else this.container.style.bottom = 'initial'
|
else this.container.style.bottom = 'initial'
|
||||||
}
|
}
|
||||||
|
|
||||||
computePosition([x, y]) {
|
computePosition([x, y], parent) {
|
||||||
let left
|
let left
|
||||||
let top
|
let top
|
||||||
if (x < window.innerWidth / 2) {
|
x = x - parent.getBoundingClientRect().left
|
||||||
|
y = y - parent.getBoundingClientRect().top
|
||||||
|
if (x < parent.offsetWidth / 2) {
|
||||||
left = x
|
left = x
|
||||||
} else {
|
} else {
|
||||||
left = x - this.container.offsetWidth
|
left = x - this.container.offsetWidth
|
||||||
}
|
}
|
||||||
if (y < window.innerHeight / 2) {
|
if (y < parent.offsetHeight / 2) {
|
||||||
top = Math.min(y, window.innerHeight - this.container.offsetHeight)
|
top = Math.min(y, parent.offsetHeight - this.container.offsetHeight)
|
||||||
} else {
|
} else {
|
||||||
top = Math.max(0, y - this.container.offsetHeight)
|
top = Math.max(0, y - this.container.offsetHeight)
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,12 @@ export default class ContextMenu extends Positioned {
|
||||||
this.container.appendChild(li)
|
this.container.appendChild(li)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.body.appendChild(this.container)
|
const parent = document.elementFromPoint(left, top).closest('.leaflet-container')
|
||||||
|
parent.appendChild(this.container)
|
||||||
if (this.options.fixed) {
|
if (this.options.fixed) {
|
||||||
this.setPosition({ left, top })
|
this.setPosition({ left, top })
|
||||||
} else {
|
} else {
|
||||||
this.computePosition([left, top])
|
this.computePosition([left, top], parent)
|
||||||
}
|
}
|
||||||
this.container.querySelector('li > *').focus()
|
this.container.querySelector('li > *').focus()
|
||||||
this.container.addEventListener(
|
this.container.addEventListener(
|
||||||
|
|
Loading…
Reference in a new issue