import L from "leaflet"; import Building from "./Building"; import { Helpers, _, MOBILE } from "./Helpers"; import { Functions } from "./Functions"; import { DEBUG } from "./main"; export default class MountingPoint extends L.Marker { public Name: string = ""; public Id: number = -1; public SupportedAssets: number[] = []; public Level: number = -1; public MountedAsset: number = -1; private constructor() { super(new L.LatLng(0, 0)); throw new Error("Use static method MountingPoint.Create() instead."); // Don't use this. // This is just here so you can't use the constructor from // outside the class } /** * MountingPoint factory method */ public static async Create( Raw: { id: number; designation: string; tag: string; objectId: number; levelId: number; roomId: number; assetId: number; position3d: { x: number; y: number; z: number; }; supportedAssetTypeIds: number[]; }, Building: Building ): Promise { return new Promise(async resolve => { // Wrong building? if (Building.Id != Raw.objectId) throw new Error("Wrong building"); let rotatedRelativePosition = Helpers.Calculations.RotatePoint( { x: Raw.position3d.x, y: Raw.position3d.y }, Helpers.Calculations.DegToRad(Building.RotationDegree) ); // Rotate mp position around building rotation degree let temp = Object.create(Building.RefPoint); temp.Easting += rotatedRelativePosition.x; temp.Northing += rotatedRelativePosition.y; let position = temp.ToLatLon(); // Add building ref point to mp relative position let mounted = Raw.assetId != -1; let mp = new L.Marker(new L.LatLng(position.Lat, position.Lon), { icon: new L.Icon({ iconUrl: mounted ? "img/marker_mounted.png" : "img/marker_default.png", iconSize: [30, 30] }) }) as MountingPoint; // Setup Leaflet marker mp.Name = _(Raw.tag) ? Raw.designation : Raw.tag; mp.SupportedAssets = Raw.supportedAssetTypeIds || []; mp.Id = Raw.id; mp.Level = Raw.levelId; mp.MountedAsset = Raw.assetId; let popup = document.createElement("div") as HTMLDivElement; //

let header = document.createElement("h2") as HTMLHeadingElement; header.innerText = mp.Name; // let table = document.createElement("table") as HTMLTableElement; table.insertRow().insertCell().innerText = "ID"; table.rows[0].insertCell().innerText = mp.Id.toString(); table.insertRow().insertCell().innerText = "Object ID"; table.rows[1].insertCell().innerText = Raw.objectId.toString(); table.insertRow().insertCell().innerText = "Supported asset IDs"; table.rows[2].insertCell().innerText = mp.SupportedAssets.toString(); // let asset = document.createElement("tr") as HTMLTableRowElement; try { let link = document.createElement("a") as HTMLAnchorElement; link.innerText = "Mounted asset ID"; link.setAttribute( "href", await Functions.GetMountedAssetIp(mp.MountedAsset) ); link.setAttribute("target", MOBILE ? "_parent" : "_blank"); asset.insertCell().appendChild(link); } catch { asset.insertCell().innerText = "Mounted asset ID"; } asset.insertCell().innerText = mp.MountedAsset.toString(); if (mounted) table.appendChild(asset); //