fix error with auto-refresh

* if layer is toggled with auto-refresh, the layer will be drawn after refresh
This commit is contained in:
tim-herbst 2021-01-03 15:16:44 +01:00
parent 8ef1b34c3b
commit abfc5424a3
2 changed files with 22 additions and 5 deletions

View File

@ -23,9 +23,9 @@ export class AutoRefreshComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.interval = setInterval(() => {
if (this.isFlagActive) {
this.map.autoRefresh();
this.map.autoRefresh().catch(error => console.log(error));
}
}, 30000);
}, 10000);
}
ngOnDestroy(): void {

View File

@ -7,6 +7,7 @@ import {environment} from '../../environments/environment';
import {PopUpService} from './pop-up.service';
import {IMapBikePoint} from './domain/map-bike-point';
import {IDashboardCommonBikePoint} from './domain/dashboard-common-bike-point';
import {writeErrorToLogFile} from "@angular/cli/utilities/log-file";
const createIcon = color => L.icon({
@ -25,6 +26,7 @@ export class MapService {
public miniMap;
bikePoints: Array<IMapBikePoint> = [];
mapOverlays: any = {};
layerToDisplay: any = {};
miniMapMarker: L.layerGroup;
markerLayer = [];
polylineLayer = [];
@ -40,7 +42,15 @@ export class MapService {
}
public async autoRefresh(): Promise<any> {
this.layerToDisplay = {};
for (const name in this.mapOverlays) {
if (this.map.hasLayer(this.mapOverlays[name])) {
if (this.mapOverlays.Heatmap === this.mapOverlays[name]) {
this.layerToDisplay.Heatmap = this.mapOverlays[name];
} else if (this.mapOverlays.Accidents === this.mapOverlays[name]) {
this.layerToDisplay.Accidents = this.mapOverlays[name];
}
}
this.map.removeLayer(this.mapOverlays[name]);
}
await this.drawStationMarkers();
@ -102,11 +112,14 @@ export class MapService {
bikePoint.lon,
bikePoint.status.NbBikes
]));
this.mapOverlays.Heatmap = L.heatLayer(heatPoints, {
const heatmap = L.heatLayer(heatPoints, {
max: 5,
radius: 90
});
if (this.layerToDisplay.Heatmap) {
this.map.addLayer(heatmap);
}
this.mapOverlays.Heatmap = heatmap;
}
public drawAccidents(): void {
@ -124,7 +137,11 @@ export class MapService {
});
accidents.push(accidentMarker);
}
this.mapOverlays.Accidents = L.layerGroup(accidents);
const accidentLayer = L.layerGroup(accidents);
if (this.layerToDisplay.Accidents) {
this.map.addLayer(accidentLayer);
}
this.mapOverlays.Accidents = accidentLayer;
this.drawMapControl();
});
}