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

way points from new topic

parent a7f0291d
No related branches found
No related tags found
No related merge requests found
......@@ -72,7 +72,56 @@ Connection settings
}
```
- More objects can be added to the `"object": []`
- There are special colours for objects with id `"Employee1"` - `"Employee4"`. Config: [MarkerColorMap](src/environments/environment.ts)
- There are special colours for objects. Config: [MarkerColorList](src/environments/environment.ts)
- topic `ipos/client/way`
- new way points
- ```json
[
{
"agentId":"Employee1",
"agentType":"HUMAN",
"publisher":"main",
"position":{
"refSystemId":"ROOT",
"point":{
"x":58,
"y":42,
"z":20
}
},
"time":"2022-04-14T09:41:20+00:00"
},
{
"agentId":"Employee1",
"agentType":"HUMAN",
"publisher":"main",
"position":{
"refSystemId":"ROOT",
"point":{
"x":18,
"y":12,
"z":50
}
},
"time":"2022-04-14T09:41:20+00:00"
},
{
"agentId":"Employee2",
"agentType":"ROBOT",
"publisher":"Employee2",
"position":{
"refSystemId":"ROOT",
"point":{
"x":-18,
"y":-52,
"z":33
}
},
"time":"2022-04-14T10:41:20+00:00"
}
]
```
- topic `ipos/client/root`
- ```json
{
......
......@@ -6,7 +6,16 @@ import 'leaflet-arrowheads';
import { IMqttMessage, MqttService } from 'ngx-mqtt';
import { environment, getMarkerConfig} from 'src/environments/environment';
import {Position, PositionUpdate, RelativePos, WGS84, validateTypePosition, validateTypeAgent} from 'src/app/model/base-model';
import {
Position,
PositionUpdate,
RelativePos,
WGS84,
validateTypePosition,
validateTypeAgent,
WayPoint,
isWayPoint
} from 'src/app/model/base-model';
@Component({
......@@ -18,17 +27,20 @@ export class MapComponent implements OnInit {
private subsPosition: Subscription;
private subsRoot: Subscription;
private subsWayPoint: Subscription;
private map!: L.Map;
private root!: Position;
agentsInfo: { [key: string]: {} } = {};
markOverlays: { [key: string]: L.LayerGroup<any> } = {};
wayPointsOverlays: { [key: string]: L.LayerGroup<any> } = {};
posOverlays: { [key: string]: L.LayerGroup<any> } = {};
constructor(private _mqttService: MqttService) {
this.root = {"refSystemId": "ROOT", "point": {"latitude": 51.02545, "longitude": 13.72295}}
// --- Root
this.subsRoot = this._mqttService.observe('ipos/client/root').subscribe((message: IMqttMessage) => {
try {
let root = <Position>JSON.parse(message.payload.toString())
......@@ -41,6 +53,7 @@ export class MapComponent implements OnInit {
}
});
// --- Agent position
this.subsPosition = this._mqttService.observe('ipos/client/position').subscribe((message: IMqttMessage) => {
try {
let upd: PositionUpdate = <PositionUpdate>JSON.parse(message.payload.toString())
......@@ -53,6 +66,24 @@ export class MapComponent implements OnInit {
console.log(e)
}
});
// --- Agent way points
this.subsWayPoint = this._mqttService.observe('ipos/client/way').subscribe((message: IMqttMessage) => {
try {
let points: WayPoint[] = <WayPoint[]>JSON.parse(message.payload.toString())
console.log(points)
points.forEach(wayPoint => {
if (isWayPoint(wayPoint)) {
this.registerWayPoint(wayPoint)
}
});
} catch(e) {
console.log(e)
}
});
}
ngOnInit(): void { }
......@@ -86,8 +117,6 @@ export class MapComponent implements OnInit {
// }
// });
} else {
this.markOverlays[key] = L.layerGroup().addTo(<L.Map>this.map)
}
......@@ -111,6 +140,50 @@ export class MapComponent implements OnInit {
this.addMarker(key, pos, props, desc.extractedAttributes?.theta)
}
registerWayPoint(wayPoint: WayPoint) {
// empty position
if (wayPoint.position==undefined) {
console.log("Error: empty position.")
return
}
// empty position
if (Object.values(wayPoint.position).every((e)=>{e==undefined})) {
console.log("Error: empty point.")
return;
}
let key = wayPoint.agentId
// --- Marker config
let serialNum = Object.keys(this.markOverlays).indexOf(key)
var markerConf = getMarkerConfig(serialNum)
// --- Layer on the map
if (!(key in this.wayPointsOverlays)) {
this.wayPointsOverlays[key] = L.layerGroup().addTo(<L.Map>this.map)
}
let point = wayPoint.position.point
if ('x' in point) {
var globPos = this.ref2root(point)
} else {
var globPos = L.latLng([point.latitude, point.longitude]);
}
// --- Marker
let markerDesc = `<p> \
<h4>Way point</h4>
<strong>Agent</strong>: ${wayPoint.agentId} <br>\
<strong>Time</strong>: ${wayPoint.time} <br>
</p>`
let marker = L.circleMarker(globPos, {radius: 5, color: markerConf.color}).bindPopup(markerDesc).openPopup();
marker.addTo(this.wayPointsOverlays[key])
}
addMarker(key: string, pos: Position, popup: string, theta: number) {
// empty position
......
......@@ -7,7 +7,7 @@ export interface PositionUpdate {
export interface Agent {
id: string
sensorId: string
type: ObjectType
type: AgentType
sensorType: SensorType
position: Position
orientation?: Quaternion
......@@ -53,7 +53,7 @@ export enum NotificationType {
"Unknown"
}
enum ObjectType {
enum AgentType {
"HUMAN",
"BOX",
"ROBOT"
......@@ -109,3 +109,22 @@ export function isAgent(obj: any): obj is Agent {
&& "position" in obj
&& isPosition(obj.position)
}
// --- Way points
export interface WayPoint {
"agentId": string
"agentType"?: AgentType
"publisher"?: string
"position": Position
"time": string
}
export function isWayPoint(obj: any): obj is WayPoint {
return obj
&& "agentId" in obj
&& "time" in obj
&& isPosition(obj.position)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment