mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Completed airbase element (first panel, spawn panel still to add)
This commit is contained in:
@@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user