Skip to content
Snippets Groups Projects
Commit a7f0291d authored by Oleksandr Husak's avatar Oleksandr Husak
Browse files

remove old points, fix consistency between map and table

parent e7156f9e
Branches
No related tags found
No related merge requests found
......@@ -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)
// }
// });
......
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)
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment