import L from "leaflet"; import Building from "./Building"; import { Helpers, _, MOBILE, $ } from "./Helpers"; import { Functions } from "./Functions"; import { DEBUG } from "./main"; import angular from "angular"; 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("iframe") as HTMLIFrameElement; popup.src = `./popup.html?mpid=${mp.Id}&wsip=${Functions.WebSocketIp}`; popup.style.width = "100%"; popup.style.height = "100%" popup.style.top = "0"; popup.style.left = "0"; popup.style.border = "none"; mp.bindPopup(popup, {className: "mp-popup"}); if (DEBUG) console.log(`new MountingPoint() with ID = ${mp.Id}`); return resolve(mp); }); } } function _moreInfo(info: string) { let popup = open("", Helpers.GenUuid()) as Window; //
	let display = popup.document.createElement("pre") as HTMLPreElement;
	display.innerHTML = unescape(info);
	display.style.fontSize = "15";

	//