"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // #region Initialization console.log("\nBegin initialization ##################################################"); var angular_1 = __importDefault(require("angular")); angular_1.default != undefined ? console.log("\tLoaded AngularJs.") : console.error("\tFailed to load AngularJs."); var leaflet_1 = __importDefault(require("leaflet")); leaflet_1.default != undefined ? console.log("\tLoaded Leaflet.") : console.error("\tFailed to load Leaflet."); var utm_latlng_1 = __importDefault(require("utm-latlng")); utm_latlng_1.default != undefined ? console.log("\tLoaded utm-latlng.") : console.error("\tFailed to load utm-latlng."); var isMobile = /Android/i.test(navigator.userAgent); // Check for mobile browser console.log("\tDetected " + (isMobile ? "mobile browser." : "desktop browser, disabling AR features.")); // AngularJS var ngApp = angular_1.default.module("main", []); console.log("\tInitialized AngularJs."); console.log("Initialization finished ###############################################"); // #endregion // #region Helpers var Calc; (function (Calc) { // Converts radians to degrees function RadToDeg(rad) { return rad * (180 / Math.PI); } Calc.RadToDeg = RadToDeg; // Converts degrees to radians function DegToRad(deg) { return (deg * Math.PI) / 180; } Calc.DegToRad = DegToRad; // Rotates a point around 0,0 by an angle in radians function RotatePoint(point, angle) { return { x: point.x * Math.cos(angle) - point.y * Math.sin(angle), y: point.x * Math.sin(angle) + point.y * Math.cos(angle) }; } Calc.RotatePoint = RotatePoint; // UTM Coordinates var UTM = /** @class */ (function () { function UTM(e, n, zn, zl) { this.Easting = e; this.Northing = n; this.ZoneNumber = zn; this.ZoneLetter = zl; } return UTM; }()); var _precision = 7; // Precision for LatLon to UTM conversion var _utm = new utm_latlng_1.default("WGS 84"); // Create UTM/LatLng converter for WGS84 projection // Wrapper for LatLon to UTM conversion function LatLonToUtm(lat, lon) { return _utm.convertLatLngToUtm(lat, lon, _precision); } Calc.LatLonToUtm = LatLonToUtm; // Wrapper for UTM to LatLon conversion function UtmToLatLon(utm) { var temp = _utm.convertUtmToLatLng(utm.Easting, utm.Northing, utm.ZoneNumber, utm.ZoneLetter); return { lat: temp.lat, lon: temp.lng }; } Calc.UtmToLatLon = UtmToLatLon; })(Calc || (Calc = {})); // Leaflet marker with additional info to represent a mounting point var MountingPoint = /** @class */ (function (_super) { __extends(MountingPoint, _super); function MountingPoint() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.SupportedAssets = []; _this.ID = -1; return _this; } return MountingPoint; }(leaflet_1.default.Marker)); // Represents all levels with the same designation, // Stores the mounting points of those levels var Layer = /** @class */ (function () { function Layer(name) { this.Name = name; this.Ids = []; this.Selected = true; this.LLayer = leaflet_1.default.layerGroup(undefined); } return Layer; }()); // Returns true if str is undefined, empty or null function IsStringEmpty(str) { return str == undefined || str == "" || str == null; } // jQuery like shortcut to get html elements function $(query) { return document.querySelector(query); } // Retrieves the angular $scope from outside a controller function GetScope() { return angular_1.default.element($("body")).scope(); } function Status(str) { GetScope().status = str; console.log(str); $("#progressBar").value++; } // #endregion // Main AngularJs controller ngApp.controller("ctrl", function ($scope) { var data = {}; // Will hold the websocket response var t0 = null; // Measures the time it takes to load and parse $scope.disableInput = false; // True when loadData kicks in, disables the inputs $scope.connected = false; // True when websocket response was received $scope.status = undefined; // String that will be shown while connecting // Writes the websocket response to data when the load button is clicked /** @function */ $scope.loadDataFromWS = function (ip) { $scope.disableInput = true; console.log("Begin loading data ####################################################"); t0 = performance.now(); // Get start time // Default value for ip if nothing was entered ip = IsStringEmpty(ip) ? "ws://192.168.133.140:2080" : ip; // Catch invalid ips try { var ws = new WebSocket(ip); // Connect to the websocket } catch (e) { alert("Invalid IP"); return; } Status("\tConnecting to " + ip + "..."); // Connect to the web socket ws.onopen = function () { console.log("\tConnected."); ws.send(JSON.stringify({ type: "getEssentials", uuid: "UUID" })); }; // Handles the response of the websocket ws.onmessage = function (response) { console.log("\tFetched " + Math.round(new TextEncoder().encode(response.data).length / 1000) + "kb."); data = JSON.parse(response.data).data; // Parse websocket response to data window.localStorage.setItem("data", escape(response.data)); $scope.$broadcast("dataLoaded"); // Call response event to kick in the map and selection GUI }; // Handle bad websocket responses ws.onclose = function (event) { if (event.code > 1000) { t0 = null; $scope.status = ""; alert("Error when getting websocket response.\n" + event.code); $scope.disableInput = false; } }; }; /** @function */ $scope.loadDataFromCache = function () { $scope.disableInput = true; console.log("Begin loading data ####################################################"); t0 = performance.now(); Status("Loading data from cache..."); try { if (window.localStorage.getItem("data") == null) throw new Error(); var _data = unescape(window.localStorage.getItem("data")); data = JSON.parse(_data).data; console.log("\tLoaded " + Math.round(new TextEncoder().encode(_data).length / 1000) + "kb from cache."); $scope.$broadcast("dataLoaded"); } catch (_a) { $scope.status = ""; $scope.disableInput = false; t0 = null; console.log("\tCould not load data from cache."); alert("No data cached."); } }; // Handles websocket response event $scope.$on("dataLoaded", function () { var _data = data; $scope.connected = true; // Switches the connection menu for the mounting point selection $scope.loading = true; // Disables the GUI while doing stuff // #region MAP console.log("\tCreating map."); // Create the map, set view and image var map = new leaflet_1.default.Map("map").setView(new leaflet_1.default.LatLng(53.0528064472226, 8.89412999153137), 8); var imageBounds = new leaflet_1.default.LatLngBounds([ [53.0528064472226, 8.89412999153137], [53.056520842139, 8.90030980110168] ]); var mapImage = leaflet_1.default.imageOverlay("img/RDE2.jpg", imageBounds); map.addLayer(mapImage); map.fitBounds(imageBounds); // #endregion // #region BUILDINGS // Get buildings var buildings = _data.objects; Status("\tParsing " + buildings.length + " buildings..."); // Create GeoJson from buidling footprints var footprintPolygons = { type: "FeatureCollection", features: [] }; for (var _i = 0, buildings_1 = buildings; _i < buildings_1.length; _i++) { var currentBuilding = buildings_1[_i]; // Check if current builing has footprint data, if not: skip if (!(currentBuilding.path[0] == undefined)) { // Holds footprint coordinates of the current building var footprintCoords = [[]]; // Parse footprint coordinates from current building for (var _a = 0, _b = currentBuilding.path; _a < _b.length; _a++) { var pos = _b[_a]; footprintCoords[0].push([ // Convert from radians to degrees and add to the array Calc.RadToDeg(pos.lon), Calc.RadToDeg(pos.lat) ]); } // Last point has to be the same as the first point so we add it again footprintCoords[0].push([ Calc.RadToDeg(currentBuilding.path[0].lon), Calc.RadToDeg(currentBuilding.path[0].lat) ]); // Create new GeoJson Feature with building footprint var currentFootprint = { type: "Feature", properties: { name: currentBuilding.designation }, geometry: { type: "Polygon", coordinates: footprintCoords } }; // Add GeoJson feature to feature collection footprintPolygons.features.push(currentFootprint); } } // Draw building footprints to map, add name popups var footprintGeoJson = leaflet_1.default.geoJSON(footprintPolygons, { onEachFeature: function (feature, layer) { layer.bindPopup("
| ID | \n\t\t\t\t\t\t\t\t\t\t\t\t" + m.id + " | \n\t\t\t\t\t\t\t\t\t\t\t
| Object ID | \n\t\t\t\t\t\t\t\t\t\t\t\t" + m.objectId + " | \n\t\t\t\t\t\t\t\t\t\t\t
| Supported Asset Type IDs | \n\t\t\t\t\t\t\t\t\t\t\t\t" + m.supportedAssetTypeIds + " | \n\t\t\t\t\t\t\t\t\t\t\t