From ee575dae35e46c0c6b5b8093d5311552c1041eb1 Mon Sep 17 00:00:00 2001 From: Oleksandr Husak <oleksandr.husak@mailbox.tu-dresden.de> Date: Wed, 6 Apr 2022 14:27:59 +0200 Subject: [PATCH] minor fixes: error in parsing, empty pointer --- src/app/components/map/map.component.ts | 35 ++++++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/app/components/map/map.component.ts b/src/app/components/map/map.component.ts index e4068ce..185aea6 100644 --- a/src/app/components/map/map.component.ts +++ b/src/app/components/map/map.component.ts @@ -30,14 +30,22 @@ export class MapComponent implements OnInit { this.root = {"refSystemId": "ROOT", "point": {"latitude": 51.02545, "longitude": 13.72295}} this.subsRoot = this._mqttService.observe('ipos/client/root').subscribe((message: IMqttMessage) => { - this.root = JSON.parse(message.payload.toString()) - console.log("New root: ", this.root) - this.registerPoint("ROOT", {"position": this.root}) + try { + this.root = JSON.parse(message.payload.toString()) + console.log("New root: ", this.root) + this.registerPoint("ROOT", {"position": this.root}) + } catch(e) { + console.log(e) + } }); this.subsPosition = this._mqttService.observe('ipos/client/position').subscribe((message: IMqttMessage) => { - let upd: PositionUpdate = JSON.parse(message.payload.toString()) - upd.objects.forEach(obj => this.registerPoint(obj.id, obj)); + try { + let upd: PositionUpdate = JSON.parse(message.payload.toString()) + upd.objects.forEach(obj => this.registerPoint(obj.id, obj)); + } catch(e) { + console.log(e) + } }); } @@ -88,8 +96,21 @@ export class MapComponent implements OnInit { } addMarker(key: string, pos: Position, popup: string, theta: number) { + + // empty position + if (pos==undefined) { + console.log("Eroro: empty position.") + return + } + let point = pos.point + // empty point + if (Object.values(point).every((e)=>{e==undefined})) { + console.log("Eroro: empty point.") + return; + } + if ('x' in point) { var globPos = this.ref2root(point) } else { @@ -124,8 +145,8 @@ export class MapComponent implements OnInit { // --- Orientation if (theta && 'x' in point) { let orient: RelativePos = { - "x": point.x + Math.sin(theta) * 3, - "y": point.y + Math.cos(theta) * 3, + "x": point.x + Math.sin(theta) * 3 ?? 3, + "y": point.y + Math.cos(theta) * 3 ?? 3, "z": point.z } let globPointOrient = this.ref2root(orient) -- GitLab