Add traffic light visualization

This commit is contained in:
David Eder 2021-06-09 09:58:17 +02:00
parent 597feaead8
commit b9c450cedc
8 changed files with 37 additions and 13 deletions

View File

@ -1,6 +1,8 @@
<button (click)="toggleMarker()">Drive!</button> <button (click)="toggleMarker()">Drive!</button>
<agm-map id="map" #map [zoom]="zoom" [latitude]="center.lat" [longitude]="center.lng" style="height: 900px; width: 1200px"> <agm-map *ngIf="traffic_light_markers.length > 0" id="map" #map [zoom]="zoom" [latitude]="center.lat" [longitude]="center.lng" style="height: 900px; width: 1200px">
<agm-marker *ngFor="let m of markers" [iconUrl]="m.iconUrl" [visible]="m.visible" [latitude]="m.lat" [longitude]="m.lng" > <!--<agm-marker *ngFor="let m of markers" [iconUrl]="m.iconUrl" [visible]="m.visible" [latitude]="m.lat" [longitude]="m.lng" >
</agm-marker>-->
<agm-marker *ngFor="let m of traffic_light_markers" [iconUrl]="m.iconUrl" [latitude]="m.lat" [longitude]="m.lng" >
</agm-marker> </agm-marker>
</agm-map> </agm-map>

View File

@ -1,6 +1,7 @@
import {Component, OnInit, ViewChild} from '@angular/core'; import {Component, OnInit, ViewChild} from '@angular/core';
import {AgmMap, AgmMarker} from '@agm/core'; import {AgmMap, AgmMarker} from '@agm/core';
import {RestService} from "../../services/rest.service"; import {RestService} from '../../services/rest.service';
import {NGXLogger} from 'ngx-logger';
@Component({ @Component({
selector: 'app-landing', selector: 'app-landing',
@ -10,7 +11,8 @@ import {RestService} from "../../services/rest.service";
export class LandingComponent implements OnInit { export class LandingComponent implements OnInit {
constructor( constructor(
private restService: RestService private restService: RestService,
private logger: NGXLogger
) { ) {
} }
@ -40,8 +42,30 @@ export class LandingComponent implements OnInit {
}, },
]; ];
traffic_light_markers = [];
ngOnInit() { ngOnInit() {
let traffic_lights = [];
this.restService.getTrafficLights().subscribe(
(data: any) => {
traffic_lights = data;
console.log(data['cursor']);
for (const traffic_light of data['cursor']) {
traffic_light['iconUrl'] = 'assets/pictures/traffic_light_red.png';
traffic_light['lat'] = traffic_light['location'][1];
traffic_light['lng'] = traffic_light['location'][0];
console.log(traffic_light);
this.traffic_light_markers.push(traffic_light);
} }
},
err => this.logger.error(err),
() => {
this.logger.debug('loaded traffic lights');
}
);
}
getDelta(source, destination, steps) { getDelta(source, destination, steps) {
return { return {

View File

@ -6,7 +6,7 @@ import {Observable} from 'rxjs';
@Injectable() @Injectable()
export class RestService { export class RestService {
private currentLocation = 'http://' + environment.location + ':' + environment.port + '/'; private currentLocation = 'http://' + environment.location + ':' + environment.port + '/api/v1/resources/';
constructor( constructor(
private logger: NGXLogger, private logger: NGXLogger,
@ -14,9 +14,7 @@ export class RestService {
) { ) {
} }
testCall(i: number): Observable<string> { getTrafficLights() {
const url = this.currentLocation + 'api1'; return this.http.get(this.currentLocation + 'traffic_lights');
this.logger.debug('Performing ' + i + '. test rest call on', url);
return this.http.get<string>(url);
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

View File

@ -6,7 +6,7 @@ import {NgxLoggerLevel} from 'ngx-logger';
export const environment = { export const environment = {
production: false, production: false,
location: 'localhost', location: 'xwayserver',
port: 5004, port: 5004,
ws_location: 'ws://127.0.0.1', ws_location: 'ws://127.0.0.1',
ws_port: 8000, ws_port: 8000,

View File

@ -1,21 +1,21 @@
[ [
{ {
"id": "1", "id": "1",
"location": [16.20703, 47.90853], "location": [16.20719, 47.89584],
"range": 2000, "range": 2000,
"switchingTime": 500, "switchingTime": 500,
"initialColor": "RED" "initialColor": "RED"
}, },
{ {
"id": "2", "id": "2",
"location": [16.20703, 47.91572], "location": [16.20814, 47.90937],
"range": 800, "range": 800,
"switchingTime": 240, "switchingTime": 240,
"initialColor": "GREEN" "initialColor": "GREEN"
}, },
{ {
"id": "3", "id": "3",
"location": [16.20703, 47.92471], "location": [16.20917, 47.92703],
"range": 1000, "range": 1000,
"switchingTime": 360, "switchingTime": 360,
"initialColor": "RED" "initialColor": "RED"