Browse Source

feat: Add Markers in real time

master
Konstantinos Kamaropoulos 5 years ago
parent
commit
a937885269
  1. 44
      src/app/about/about.component.ts

44
src/app/about/about.component.ts

@ -22,6 +22,8 @@ export class AboutComponent implements OnInit {
lat = 37.9838; lat = 37.9838;
lng = 23.7275; lng = 23.7275;
sub: any;
constructor(private logsService: LogsService) {} constructor(private logsService: LogsService) {}
async ngOnInit() { async ngOnInit() {
@ -36,28 +38,30 @@ export class AboutComponent implements OnInit {
// Add map controls // Add map controls
// this.map.addControl(new mapboxgl.NavigationControl()); // this.map.addControl(new mapboxgl.NavigationControl());
let data = await this.logsService.getUpdates(); this.sub = interval(1000).subscribe(async val => {
for (let log of data) { let data = await this.logsService.getUpdates();
if (log['gps_data']['status'] == 'A') { for (let log of data) {
let html = if (log['gps_data']['status'] == 'A') {
log['gps_data']['datestamp'] + let html =
' ' + log['gps_data']['datestamp'] +
log['gps_data']['timestamp'] + ' ' +
'<br><table><tr><th>Sensor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>Reading</th></tr>'; log['gps_data']['timestamp'] +
for (let record in log['sensorReadings']) { '<br><table><tr><th>Sensor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>Reading</th></tr>';
if (Object.prototype.hasOwnProperty.call(log['sensorReadings'], record)) { for (let record in log['sensorReadings']) {
html += '<tr><td>' + record + '</td>' + '<td>' + log['sensorReadings'][record] + '</td></tr>'; if (Object.prototype.hasOwnProperty.call(log['sensorReadings'], record)) {
html += '<tr><td>' + record + '</td>' + '<td>' + log['sensorReadings'][record] + '</td></tr>';
}
} }
html += '</table>';
var popup = new mapboxgl.Popup({ offset: 25 }).setHTML(html);
var marker = new mapboxgl.Marker({
draggable: false
})
.setLngLat([log['gps_data']['longitude'], log['gps_data']['latitude']])
.setPopup(popup)
.addTo(this.map);
} }
html += '</table>';
var popup = new mapboxgl.Popup({ offset: 25 }).setHTML(html);
var marker = new mapboxgl.Marker({
draggable: false
})
.setLngLat([log['gps_data']['longitude'], log['gps_data']['latitude']])
.setPopup(popup)
.addTo(this.map);
} }
} });
} }
} }

Loading…
Cancel
Save