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

minor fixes: error in parsing, empty pointer

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