Completed airbase element (first panel, spawn panel still to add)

This commit is contained in:
dpassoni
2023-03-14 17:04:02 +01:00
parent 96a4070b39
commit 2a60edcaec
6 changed files with 77 additions and 24 deletions

View File

@@ -3,6 +3,8 @@ import { LatLng } from "leaflet";
export class ContextMenu {
#container: HTMLElement | null;
#latlng: LatLng = new LatLng(0, 0);
#x: number = 0;
#y: number = 0;
constructor(id: string) {
this.#container = document.getElementById(id);
@@ -12,17 +14,9 @@ export class ContextMenu {
show(x: number, y: number, latlng: LatLng) {
this.#latlng = latlng;
this.#container?.classList.toggle("hide", false);
if (this.#container != null) {
if (x + this.#container.offsetWidth < window.innerWidth)
this.#container.style.left = x + "px";
else
this.#container.style.left = window.innerWidth - this.#container.offsetWidth + "px";
if (y + this.#container.offsetHeight < window.innerHeight)
this.#container.style.top = y + "px";
else
this.#container.style.top = window.innerHeight - this.#container.offsetHeight + "px";
}
this.#x = x;
this.#y = y;
this.clip();
}
hide() {
@@ -38,4 +32,19 @@ export class ContextMenu {
{
return this.#latlng;
}
clip()
{
if (this.#container != null) {
if (this.#x + this.#container.offsetWidth < window.innerWidth)
this.#container.style.left = this.#x + "px";
else
this.#container.style.left = window.innerWidth - this.#container.offsetWidth + "px";
if (this.#y + this.#container.offsetHeight < window.innerHeight)
this.#container.style.top = this.#y + "px";
else
this.#container.style.top = window.innerHeight - this.#container.offsetHeight + "px";
}
}
}