@@ -398,6 +398,94 @@ const TrafficLight = {
398
398
}
399
399
}
400
400
401
+ /**
402
+ * Represents a charging station.
403
+ */
404
+ const ChargingStation = {
405
+ name : 'unnamed_charging_station' ,
406
+ latitude : 0 ,
407
+ longitude : 0 ,
408
+ marker : null ,
409
+ timeStateChange : 0 ,
410
+ state : { } ,
411
+
412
+ init ( name , latitude , longitude ) {
413
+ this . name = name
414
+ this . latitude = latitude
415
+ this . longitude = longitude
416
+ this . marker = new Feature ( {
417
+ type : 'charging-station' ,
418
+ geometry : new Point ( fromLonLat ( [ longitude , latitude ] ) )
419
+ } )
420
+ this . marker . setProperties ( [ 'name' ] )
421
+ this . marker . set ( 'name' , name )
422
+ this . state = {
423
+ sending : false ,
424
+ receiving : false ,
425
+ } ;
426
+ } ,
427
+
428
+ getMarker ( ) {
429
+ return this . marker
430
+ } ,
431
+
432
+ setIsEquipped ( isEquipped ) {
433
+ this . state . equipped = isEquipped
434
+ } ,
435
+
436
+ setLocation ( latitude , longitude ) {
437
+ this . latitude = latitude
438
+ this . longitude = longitude
439
+ } ,
440
+
441
+ setState ( stateName ) {
442
+ if ( this . state [ stateName ] !== undefined ) {
443
+ this . state [ stateName ] = true
444
+ this . timeStateChange = Date . now ( ) ;
445
+ }
446
+ } ,
447
+
448
+ /**
449
+ * Updates the marker of the Charging Station.
450
+ */
451
+ updateView ( ) {
452
+ // Location
453
+ this . marker . setGeometry ( new Point ( fromLonLat ( [ this . longitude , this . latitude ] ) ) )
454
+
455
+ // Update style
456
+ const style = this . createStyle ( )
457
+ this . marker . setStyle ( style )
458
+
459
+ if ( ( Date . now ( ) - this . timeStateChange ) > 500 ) {
460
+ // Clear sending/receiving states
461
+ this . state . sending = false
462
+ this . state . receiving = false
463
+ }
464
+ } ,
465
+
466
+ /**
467
+ * Creates the style of the RSU marker based on the Charging Station's state.
468
+ */
469
+ createStyle ( ) {
470
+ let style = 'charging-station'
471
+ if ( this . state . equipped ) {
472
+ style = 'charging-station-equipped'
473
+ }
474
+ if ( this . state . sending ) {
475
+ style = 'charging-station-sending'
476
+ }
477
+ if ( this . state . receiving ) {
478
+ style = 'charging-station-receiving'
479
+ }
480
+ return new Style ( {
481
+ image : new Icon ( {
482
+ anchor : [ 0.5 , 1 ] ,
483
+ src : `markers/${ style } .png`
484
+ } )
485
+ } )
486
+ }
487
+ }
488
+
401
489
402
490
/**
403
491
* Controls the map and its unit markers.
@@ -425,10 +513,16 @@ const map = (function() {
425
513
426
514
/**
427
515
* Stores all traffic lights (equipped)
428
- * Map<name: string, traffic
516
+ * Map<name: string, traffic-light: TrafficLight>
429
517
*/
430
518
let trafficLights = { }
431
519
520
+ /**
521
+ * Stores all charging stations (equipped)
522
+ * Map<name: string, charging-station: ChargingStation>
523
+ */
524
+ let chargingStations = { }
525
+
432
526
/**
433
527
* An additional layer beside the map itself.
434
528
* This layer contains all unit markers.
@@ -534,6 +628,22 @@ const map = (function() {
534
628
}
535
629
}
536
630
631
+ /**
632
+ * Creates a charging station and adds it to the map.
633
+ * @param {string } name Name of the charging station
634
+ * @param {number } latitude Latitude value of the geo position
635
+ * @param {number } longitude Longitude value of the geo position
636
+ * @param {boolean } equipped true if charging station is equipped with an application
637
+ */
638
+ function addChargingStation ( name , latitude , longitude , equipped ) {
639
+ if ( ! chargingStations [ name ] ) {
640
+ chargingStations [ name ] = Object . assign ( { } , ChargingStation )
641
+ chargingStations [ name ] . init ( name , latitude , longitude )
642
+ chargingStations [ name ] . setIsEquipped ( equipped )
643
+ addMarker ( chargingStations [ name ] . getMarker ( ) )
644
+ }
645
+ }
646
+
537
647
/**
538
648
* Updates the state of a unit.
539
649
* @param {string } unitName Name of the unit to update
@@ -546,6 +656,8 @@ const map = (function() {
546
656
rsus [ unitName ] . setState ( state )
547
657
} else if ( trafficLights [ unitName ] ) {
548
658
trafficLights [ unitName ] . setState ( state ) ;
659
+ } else if ( chargingStations [ unitName ] ) {
660
+ chargingStations [ unitName ] . setState ( state ) ;
549
661
}
550
662
}
551
663
@@ -605,6 +717,8 @@ const map = (function() {
605
717
rsus [ unitName ] . updateView ( )
606
718
} else if ( trafficLights [ unitName ] ) {
607
719
trafficLights [ unitName ] . updateView ( )
720
+ } else if ( chargingStations [ unitName ] ) {
721
+ chargingStations [ unitName ] . updateView ( )
608
722
}
609
723
}
610
724
}
@@ -631,6 +745,10 @@ const map = (function() {
631
745
marker = trafficLights [ unitName ] . getMarker ( )
632
746
vectorLayer . getSource ( ) . removeFeature ( marker )
633
747
delete trafficLights [ unitName ]
748
+ } else if ( chargingStations [ unitName ] ) {
749
+ marker = chargingStations [ unitName ] . getMarker ( )
750
+ vectorLayer . getSource ( ) . removeFeature ( marker )
751
+ delete chargingStations [ unitName ]
634
752
}
635
753
}
636
754
@@ -642,6 +760,7 @@ const map = (function() {
642
760
agents = { }
643
761
rsus = { }
644
762
trafficLights = { }
763
+ chargingStations = { }
645
764
vectorLayer . getSource ( ) . clear ( )
646
765
}
647
766
@@ -654,6 +773,7 @@ const map = (function() {
654
773
addAgent,
655
774
addRsu,
656
775
addTrafficLight,
776
+ addChargingStation,
657
777
updateViews,
658
778
removeUnit,
659
779
removeAllUnits,
@@ -809,6 +929,13 @@ const WebSocketClient = (function() {
809
929
map . addTrafficLight ( unitName , position . latitude , position . longitude , equipped )
810
930
updatedUnits . push ( unitName )
811
931
}
932
+ } else if ( data . ChargingStationRegistration ) {
933
+ // Add traffic light to map
934
+ unitName = data . ChargingStationRegistration . chargingStationMapping . name
935
+ let position = data . ChargingStationRegistration . chargingStationMapping . position
936
+ let equipped = data . ChargingStationRegistration . chargingStationMapping . applications . length > 0 ;
937
+ map . addChargingStation ( unitName , position . latitude , position . longitude , equipped )
938
+ updatedUnits . push ( unitName )
812
939
}
813
940
814
941
// Update markers of updated units
0 commit comments