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
No related branches found
No related tags found
No related merge requests found
...@@ -73,19 +73,18 @@ export class MapComponent implements OnInit { ...@@ -73,19 +73,18 @@ export class MapComponent implements OnInit {
registerPoint(key: string, desc: { [key: string]: any }) { registerPoint(key: string, desc: { [key: string]: any }) {
// --- Leyers for markers // --- Leyers for markers
if (key in this.markOverlays) { if (key in this.markOverlays) {
console.log(this.markOverlays) this.markOverlays[key].clearLayers();
// this.markOverlays[key].clearLayers();
var myIconReplc = L.Icon.extend({ // var myIconReplc = L.Icon.extend({
options: {} // options: {}
}); // });
this.markOverlays[key].eachLayer(layer => { // this.markOverlays[key].eachLayer(layer => {
if (!(layer instanceof L.Circle)) { // if (!(layer instanceof L.Circle)) {
this.map.removeLayer(layer) // this.map.removeLayer(layer)
} // }
}); // });
......
import { Component, OnInit, ViewChild } from '@angular/core'; 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 { IMqttMessage, MqttService } from 'ngx-mqtt';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
...@@ -38,15 +38,22 @@ export class TableComponent implements OnInit { ...@@ -38,15 +38,22 @@ export class TableComponent implements OnInit {
this.subsPosition = this._mqttService.observe('ipos/client/position').subscribe((message: IMqttMessage) => { this.subsPosition = this._mqttService.observe('ipos/client/position').subscribe((message: IMqttMessage) => {
try { try {
let upd: PositionUpdate = JSON.parse(message.payload.toString()) 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))] let agentNames = [...new Set(this.dataSource.map((agent: any) => agent.id))]
this.dataSource.forEach((agent: any)=> { this.dataSource.forEach((agent: any)=> {
let idx = agentNames.indexOf(agent.id) + 1 let idx = agentNames.indexOf(agent.id) + 1
agent.color = getMarkerConfig(idx).color agent.color = getMarkerConfig(idx).color
}) })
// 3. Update table
this.table?.renderRows(); this.table?.renderRows();
} catch(e) { } catch(e) {
console.log(e) console.log(e)
......
...@@ -14,6 +14,7 @@ export interface Agent { ...@@ -14,6 +14,7 @@ export interface Agent {
lastPosUpdate: string lastPosUpdate: string
zoneDescriptors: ZoneDesc[] zoneDescriptors: ZoneDesc[]
extractedAttributes?: ExtAttribute extractedAttributes?: ExtAttribute
[x: string]: any
} }
export interface Position { export interface Position {
...@@ -87,27 +88,24 @@ export function validateTypeAgent(obj: any) { ...@@ -87,27 +88,24 @@ export function validateTypeAgent(obj: any) {
// --- Type Guards // --- Type Guards
function isWGS84(obj: any): obj is WGS84 { function isWGS84(obj: any): obj is WGS84 {
return Object.prototype.hasOwnProperty.call(obj, "latitude") return obj
&& Object.prototype.hasOwnProperty.call(obj, "longitude") && "latitude" in obj
&& "longitude" in obj
} }
function isRelativePos(obj: any): obj is RelativePos { function isRelativePos(obj: any): obj is RelativePos {
return Object.prototype.hasOwnProperty.call(obj, "x") return obj
&& Object.prototype.hasOwnProperty.call(obj, "y") && "x" in obj
&& "y" in obj
} }
export function isPosition(obj: any): obj is Position { export function isPosition(obj: any): obj is Position {
return isWGS84(obj.point) || isRelativePos(obj.point) return isWGS84(obj.point) || isRelativePos(obj.point)
&& Object.prototype.hasOwnProperty.call(obj, "refSystemId")
} }
export function isAgent(obj: any): obj is Agent { export function isAgent(obj: any): obj is Agent {
return "id" in obj return obj
&& "type" in obj && "id" in obj
&& "sensorId" in obj
&& "sensorType" in obj
&& "position" in obj && "position" in obj
&& isPosition(obj.position) && 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