[SI-77]: Bugfix; Map
Signed-off-by: Dennis Schmitt <dennis.schmitt@pta.de>
diff --git a/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.spec.ts b/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.spec.ts
index 415d720..250e315 100644
--- a/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.spec.ts
+++ b/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.spec.ts
@@ -13,6 +13,7 @@
import { GridFailureInformationMapComponent } from '@openk-libs/grid-failure-information-map/lib/grid-failure-information-map.component';
import * as L from 'leaflet';
+import { async } from '@angular/core/testing';
describe('GridFailureInformationMapComponent', () => {
let component: GridFailureInformationMapComponent;
@@ -24,7 +25,7 @@
it('should create', () => {
expect(component).toBeTruthy();
});
- it('should call _initMap() and _setMarker after calling ngAfterViewInit', () => {
+ it('should call _initMap() and _setMarker after calling ngAfterViewInit', async(() => {
const latitude: any = 123;
const longitude: any = 456;
component.mapData = [{ latitude: latitude, longitude: longitude }];
@@ -36,5 +37,5 @@
expect(spyMap).toHaveBeenCalled();
expect(spyTileLayer).toHaveBeenCalled();
expect(spyMarker).toHaveBeenCalledWith([latitude, longitude], { icon: (component as any)._icon });
- });
+ }));
});
diff --git a/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.ts b/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.ts
index e1c5d07..a1948e2 100644
--- a/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.ts
+++ b/projects/openk/grid-failure-information-map/src/lib/grid-failure-information-map.component.ts
@@ -20,9 +20,11 @@
styleUrls: ['./grid-failure-information-map.component.scss'],
})
export class GridFailureInformationMapComponent implements AfterViewInit {
+ private _mapData: Array<any>;
@Input()
public set mapData(v: Array<any>) {
- this._setMarker(v);
+ this._mapData = v;
+ this._setMarker();
}
private _map: any;
@@ -36,6 +38,7 @@
ngAfterViewInit(): void {
this._initMap();
+ this._setMarker();
}
private _initMap(): void {
@@ -51,11 +54,13 @@
tiles.addTo(this._map);
}
- private _setMarker(mapData: Array<any>) {
- mapData.forEach(gridFailure => {
- if (gridFailure.latitude && gridFailure.longitude) {
- L.marker([gridFailure.latitude, gridFailure.longitude], { icon: this._icon }).addTo(this._map);
- }
- });
+ private _setMarker() {
+ !!this._map &&
+ !!this._mapData &&
+ this._mapData.forEach(gridFailure => {
+ if (gridFailure.latitude && gridFailure.longitude) {
+ L.marker([gridFailure.latitude, gridFailure.longitude], { icon: this._icon }).addTo(this._map);
+ }
+ });
}
}