fix error with auto-refresh
* if layer is toggled with auto-refresh, the layer will be drawn after refresh
This commit is contained in:
parent
8ef1b34c3b
commit
abfc5424a3
@ -23,9 +23,9 @@ export class AutoRefreshComponent implements OnInit, OnDestroy {
|
|||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.interval = setInterval(() => {
|
this.interval = setInterval(() => {
|
||||||
if (this.isFlagActive) {
|
if (this.isFlagActive) {
|
||||||
this.map.autoRefresh();
|
this.map.autoRefresh().catch(error => console.log(error));
|
||||||
}
|
}
|
||||||
}, 30000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
|
@ -7,6 +7,7 @@ import {environment} from '../../environments/environment';
|
|||||||
import {PopUpService} from './pop-up.service';
|
import {PopUpService} from './pop-up.service';
|
||||||
import {IMapBikePoint} from './domain/map-bike-point';
|
import {IMapBikePoint} from './domain/map-bike-point';
|
||||||
import {IDashboardCommonBikePoint} from './domain/dashboard-common-bike-point';
|
import {IDashboardCommonBikePoint} from './domain/dashboard-common-bike-point';
|
||||||
|
import {writeErrorToLogFile} from "@angular/cli/utilities/log-file";
|
||||||
|
|
||||||
|
|
||||||
const createIcon = color => L.icon({
|
const createIcon = color => L.icon({
|
||||||
@ -25,6 +26,7 @@ export class MapService {
|
|||||||
public miniMap;
|
public miniMap;
|
||||||
bikePoints: Array<IMapBikePoint> = [];
|
bikePoints: Array<IMapBikePoint> = [];
|
||||||
mapOverlays: any = {};
|
mapOverlays: any = {};
|
||||||
|
layerToDisplay: any = {};
|
||||||
miniMapMarker: L.layerGroup;
|
miniMapMarker: L.layerGroup;
|
||||||
markerLayer = [];
|
markerLayer = [];
|
||||||
polylineLayer = [];
|
polylineLayer = [];
|
||||||
@ -40,7 +42,15 @@ export class MapService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async autoRefresh(): Promise<any> {
|
public async autoRefresh(): Promise<any> {
|
||||||
|
this.layerToDisplay = {};
|
||||||
for (const name in this.mapOverlays) {
|
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]);
|
this.map.removeLayer(this.mapOverlays[name]);
|
||||||
}
|
}
|
||||||
await this.drawStationMarkers();
|
await this.drawStationMarkers();
|
||||||
@ -102,11 +112,14 @@ export class MapService {
|
|||||||
bikePoint.lon,
|
bikePoint.lon,
|
||||||
bikePoint.status.NbBikes
|
bikePoint.status.NbBikes
|
||||||
]));
|
]));
|
||||||
|
const heatmap = L.heatLayer(heatPoints, {
|
||||||
this.mapOverlays.Heatmap = L.heatLayer(heatPoints, {
|
|
||||||
max: 5,
|
max: 5,
|
||||||
radius: 90
|
radius: 90
|
||||||
});
|
});
|
||||||
|
if (this.layerToDisplay.Heatmap) {
|
||||||
|
this.map.addLayer(heatmap);
|
||||||
|
}
|
||||||
|
this.mapOverlays.Heatmap = heatmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public drawAccidents(): void {
|
public drawAccidents(): void {
|
||||||
@ -124,7 +137,11 @@ export class MapService {
|
|||||||
});
|
});
|
||||||
accidents.push(accidentMarker);
|
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();
|
this.drawMapControl();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user