Jelajahi Sumber

feat: configure unit popup

fzadrazil 4 tahun lalu
induk
melakukan
670662bdf5

+ 8 - 2
angular.json

@@ -28,13 +28,19 @@
             "aot": true,
             "assets": [
               "src/favicon.ico",
-              "src/assets"
+              "src/assets",
+              {
+                "glob": "**/*",
+                "input": "./node_modules/hslayers-ng/src/assets",
+                "output": "./hslayers-ng/assets"
+              }
             ],
             "styles": [
               "node_modules/primeng/resources/themes/bootstrap4-dark-blue/theme.css",
               "node_modules/primeng/resources/primeng.min.css",
               "node_modules/primeicons/primeicons.css",
-              "src/assets/scss/styles.scss"
+              "src/assets/scss/styles.scss",
+              "node_modules/hslayers-ng/css/hslayers-ng.css"
             ],
             "scripts": [
               "node_modules/jquery/dist/jquery.js",

File diff ditekan karena terlalu besar
+ 3702 - 6822
package-lock.json


+ 12 - 10
package.json

@@ -12,25 +12,17 @@
   },
   "private": true,
   "dependencies": {
-    "@angular/animations": "~12.2.9",
-    "@angular/common": "~12.2.9",
-    "@angular/compiler": "~12.2.9",
-    "@angular/core": "~12.2.9",
-    "@angular/forms": "~12.2.9",
-    "@angular/platform-browser": "~12.2.9",
-    "@angular/platform-browser-dynamic": "~12.2.9",
-    "@angular/router": "~12.2.9",
     "@fortawesome/angular-fontawesome": "^0.9.0",
     "@fortawesome/fontawesome-svg-core": "^1.2.36",
     "@fortawesome/free-solid-svg-icons": "^5.15.4",
     "bootstrap": "^4.6.0",
-    "hslayers-ng": "^6.1.0",
+    "hslayers-ng": "c:/Projects/hslayers-ng/dist/hslayers/",
     "jquery": "^3.6.0",
     "lodash": "^4.17.21",
     "moment": "^2.29.1",
     "moment-timezone": "^0.5.33",
     "ngx-cookie-service": "^12.0.3",
-    "ol": "^6.8.1",
+    "ol": "^6.9.0",
     "primeicons": "^4.1.0",
     "primeng": "^12.2.0",
     "rxjs": "~6.6.0",
@@ -39,6 +31,16 @@
     "vega-tooltip": "^0.25.1",
     "zone.js": "~0.11.3"
   },
+  "peerDependencies": {
+    "@angular/animations": "~12.2.9",
+    "@angular/common": "~12.2.9",
+    "@angular/compiler": "~12.2.9",
+    "@angular/core": "~12.2.9",
+    "@angular/forms": "~12.2.9",
+    "@angular/platform-browser": "~12.2.9",
+    "@angular/platform-browser-dynamic": "~12.2.9",
+    "@angular/router": "~12.2.9"
+  },
   "devDependencies": {
     "@angular-devkit/build-angular": "~12.2.9",
     "@angular/cli": "~12.2.9",

+ 44 - 25
src/app/dashboard/components/map/map.component.ts

@@ -1,4 +1,4 @@
-import { Component, Input, OnChanges, OnDestroy, OnInit, AfterViewInit, SimpleChanges } from '@angular/core';
+import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core';
 import { ConfirmationService, MenuItem, MessageService } from 'primeng/api';
 import { Extent } from 'ol/extent';
 import { Group, Tile, Vector as VectorLayer } from 'ol/layer';
@@ -19,13 +19,14 @@ import {
   HsLayerEditorService,
   HsEventBusService
 } from 'hslayers-ng';
+import { environment } from '../../../../environments/environment';
 
 @Component({
   selector: 'app-map',
   templateUrl: './map.component.html',
   styleUrls: ['./map.component.scss']
 })
-export class MapComponent implements OnInit, OnDestroy, OnChanges, AfterViewInit {
+export class MapComponent implements OnInit, OnDestroy, OnChanges {
 
   @Input('units') units: Array<{ drivers?: Drivers; generalInfo?: GeneralInfo; holder?: any; lastpos?: Lastpos; sensors?: Array<Sensor>; unit?: Unit }>;
   mapReady: boolean = false;
@@ -41,18 +42,9 @@ export class MapComponent implements OnInit, OnDestroy, OnChanges, AfterViewInit
     public HsLayerEditorService: HsLayerEditorService,
     public HsEventBusService: HsEventBusService
   ) {
-  }
-
-  ngAfterViewInit(): void {
-  //  this.mapReady = true;
-
-  //  if (this.dataReady)
-  //    this.initMap()
-  }
-
-  ngOnInit(): void {
     this.HsConfig.update({
-      assetsPath: 'https://unpkg.com/hslayers-ng-app@3.1.0/assets/',
+      assetsPath: environment.hslayersAssetsPath,
+      popUpDisplay: 'click',
       proxyPrefix: window.location.hostname.includes('localhost')
         ? `${window.location.protocol}//${window.location.hostname}:8085/`
         : '/proxy/',
@@ -89,17 +81,24 @@ export class MapComponent implements OnInit, OnDestroy, OnChanges, AfterViewInit
         mapControls: true,
         basemapGallery: true
       },
+      panelsEnabled: {
+        info: false, //(true by default),
+        layermanager: false
+      },
       sidebarPosition: 'invisible',
       queryPoint: 'hidden',
-    //  default_view: new View({
-    //    center: [1873444.3416929364, 6286508.646897761], // Latitude longitude    to Spherical Mercator
-    //    extent: [1871197.0792499082, 6282949.4051418, 1873509.6915773677, 6287134.61866585],
-    //    multiWorld: false,
-    //    zoom: 6
-    //  })
+      //  default_view: new View({
+      //    center: [1873444.3416929364, 6286508.646897761], // Latitude longitude    to Spherical Mercator
+      //    extent: [1871197.0792499082, 6282949.4051418, 1873509.6915773677, 6287134.61866585],
+      //    multiWorld: false,
+      //    zoom: 6
+      //  })
     });
   }
 
+  ngOnInit(): void {
+  }
+
   ngOnChanges(changes: SimpleChanges): void {
     if (changes['units']) {
       //this.dataReady = true;
@@ -149,7 +148,7 @@ export class MapComponent implements OnInit, OnDestroy, OnChanges, AfterViewInit
         }
       }
     };
-    geoJsonUnits['features'] = this.units ? this.units.filter(u => (u.lastpos.position.x > 0)).map(u => this.getUnitPos(u.lastpos)) : [];
+    geoJsonUnits['features'] = this.units ? this.units.filter(u => (u.lastpos.position.x > 0)).map(u => this.getUnitPos(u.lastpos, u.unit)) : [];
 
     const vectorSource = new VectorSource({
       features: new GeoJSON().readFeatures(geoJsonUnits),
@@ -161,6 +160,20 @@ export class MapComponent implements OnInit, OnDestroy, OnChanges, AfterViewInit
     const vectorLayer = new VectorLayer({
       source: vectorSource,
       style: this.styleFunction,
+      properties: {
+        popUp: {
+          attributes: [
+            {
+              attribute: 'id',
+              label: 'Unit ID'
+            },
+            {
+              attribute: 'desc',
+              label: 'Description'
+            }
+          ]
+        }
+      }
     });
 
     return vectorLayer;
@@ -181,12 +194,18 @@ export class MapComponent implements OnInit, OnDestroy, OnChanges, AfterViewInit
     })
   }
 
-  getUnitPos(pos: Lastpos): any {
+  getUnitPos(pos: Lastpos, unit: Unit): any {
     return {
-      'type': 'Feature',
-      'geometry': {
-        'type': 'Point',
-        'coordinates': [pos.position.x, pos.position.y]
+      "type": "Feature",
+      "geometry": {
+        "type": "Point",
+        "coordinates": [pos.position.x, pos.position.y]
+      },
+      "properties": {
+        "id": unit.unitId,
+        "desc": unit.description,
+        "online": pos.attributes.is_online,
+        "moving": pos.attributes.is_moving
       }
     }
   }

+ 2 - 1
src/environments/environment.prod.ts

@@ -2,5 +2,6 @@ export const environment = {
   production: true,
   baseHref: '/',
   useMock: false,
-  sensLogBaseUrl: 'https://sensor.lesprojekt.cz'
+  sensLogBaseUrl: 'https://sensor.lesprojekt.cz',
+  hslayersAssetsPath: 'https://unpkg.com/hslayers-ng-app@6.1.0/assets/'
 };

+ 2 - 1
src/environments/environment.ts

@@ -1,4 +1,5 @@
 export const environment = {
   production: false,
-  sensLogBaseUrl: ''
+  sensLogBaseUrl: '',
+  hslayersAssetsPath: './hslayers-ng/assets'
 };

+ 5 - 0
tsconfig.json

@@ -13,6 +13,11 @@
     "skipLibCheck": true,
     "target": "es2015",
     "module": "es2020",
+    "paths": {
+      "@angular/*": [
+        "./node_modules/@angular/*"
+      ]
+    },
     "lib": [
       "es2018",
       "dom"

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini