diff --git a/src/app/components/map/map.component.ts b/src/app/components/map/map.component.ts index 396395d7e1a8dc260b5cee2ab81840cd20e05b48..ff0f43a04e38e00bf9dd13e525ea63ddd61f58cb 100644 --- a/src/app/components/map/map.component.ts +++ b/src/app/components/map/map.component.ts @@ -73,19 +73,18 @@ export class MapComponent implements OnInit { registerPoint(key: string, desc: { [key: string]: any }) { // --- Leyers for markers if (key in this.markOverlays) { - console.log(this.markOverlays) - // this.markOverlays[key].clearLayers(); + this.markOverlays[key].clearLayers(); - var myIconReplc = L.Icon.extend({ - options: {} - }); + // var myIconReplc = L.Icon.extend({ + // options: {} + // }); - this.markOverlays[key].eachLayer(layer => { - if (!(layer instanceof L.Circle)) { - this.map.removeLayer(layer) - } - }); + // this.markOverlays[key].eachLayer(layer => { + // if (!(layer instanceof L.Circle)) { + // this.map.removeLayer(layer) + // } + // }); diff --git a/src/app/components/table/table.component.ts b/src/app/components/table/table.component.ts index 0fa9088e0ac352f281532fb2d5540a8855b359e4..72a9dad4803ef66977b82e906b2802d41e55bdf9 100644 --- a/src/app/components/table/table.component.ts +++ b/src/app/components/table/table.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit, ViewChild } from '@angular/core'; -import {Agent, PositionUpdate} from 'src/app/model/base-model'; +import { isAgent, PositionUpdate } from 'src/app/model/base-model'; import { IMqttMessage, MqttService } from 'ngx-mqtt'; import { Subscription } from 'rxjs'; @@ -38,15 +38,22 @@ export class TableComponent implements OnInit { this.subsPosition = this._mqttService.observe('ipos/client/position').subscribe((message: IMqttMessage) => { try { let upd: PositionUpdate = JSON.parse(message.payload.toString()) - // upd.objects.forEach(obj => validateTypeObject(obj)); - this.dataSource.push(...upd.objects); + // 1. Validate + let oldAgentNames = [...new Set(this.dataSource.map((agent: any) => agent.id))] + let validAgents = upd.objects.filter((agent: any) => { + return isAgent(agent) || oldAgentNames.includes(agent.id) + }); + + // 2. Extract + this.dataSource.push(...validAgents); let agentNames = [...new Set(this.dataSource.map((agent: any) => agent.id))] this.dataSource.forEach((agent: any)=> { let idx = agentNames.indexOf(agent.id) + 1 agent.color = getMarkerConfig(idx).color }) + // 3. Update table this.table?.renderRows(); } catch(e) { console.log(e) diff --git a/src/app/model/base-model.ts b/src/app/model/base-model.ts index 32c8dc7502bd510a3719554ae9f8c9a1e184b369..30864c0e5f01ce5d1834888d7509badafe9ca1dd 100644 --- a/src/app/model/base-model.ts +++ b/src/app/model/base-model.ts @@ -14,6 +14,7 @@ export interface Agent { lastPosUpdate: string zoneDescriptors: ZoneDesc[] extractedAttributes?: ExtAttribute + [x: string]: any } export interface Position { @@ -87,27 +88,24 @@ export function validateTypeAgent(obj: any) { // --- Type Guards function isWGS84(obj: any): obj is WGS84 { - return Object.prototype.hasOwnProperty.call(obj, "latitude") - && Object.prototype.hasOwnProperty.call(obj, "longitude") + return obj + && "latitude" in obj + && "longitude" in obj } function isRelativePos(obj: any): obj is RelativePos { - return Object.prototype.hasOwnProperty.call(obj, "x") - && Object.prototype.hasOwnProperty.call(obj, "y") + return obj + && "x" in obj + && "y" in obj } export function isPosition(obj: any): obj is Position { return isWGS84(obj.point) || isRelativePos(obj.point) - && Object.prototype.hasOwnProperty.call(obj, "refSystemId") } export function isAgent(obj: any): obj is Agent { - return "id" in obj - && "type" in obj - && "sensorId" in obj - && "sensorType" in obj + return obj + && "id" in obj && "position" in obj && isPosition(obj.position) - && "lastPosUpdate" in obj - && "zoneDescriptors" in obj } \ No newline at end of file