Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 21efc4f

Browse files
Mathieu St-Louisdoom777
authored andcommitted
fix(PolylinePoint): prevent accessing undefined variable on change
make every update to polyline point update lat & lng even when only one of them changed fix #1597
1 parent 7922546 commit 21efc4f

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {SimpleChange, SimpleChanges} from '@angular/core';
2+
import {AgmPolylinePoint} from './polyline-point';
3+
4+
describe('AgmPolylinePoint', () => {
5+
describe('ngOnChanges', () => {
6+
it('should emit positionChanged on latitude change', () => {
7+
const polylinePoint = new AgmPolylinePoint();
8+
polylinePoint.latitude = 50;
9+
polylinePoint.longitude = -50;
10+
polylinePoint.positionChanged.emit = jest.fn();
11+
12+
const positionChanges:
13+
SimpleChanges = {'latitude': new SimpleChange('previousLat', 'newLat', false)};
14+
15+
polylinePoint.ngOnChanges(positionChanges);
16+
17+
expect(polylinePoint.positionChanged.emit).toHaveBeenCalledWith({lat: 'newLat', lng: -50});
18+
});
19+
it('should emit positionChanged on longitude change', () => {
20+
const polylinePoint = new AgmPolylinePoint();
21+
polylinePoint.latitude = 50;
22+
polylinePoint.longitude = -50;
23+
polylinePoint.positionChanged.emit = jest.fn();
24+
25+
const positionChanges:
26+
SimpleChanges = {'longitude': new SimpleChange('previousLng', 'newLng', false)};
27+
28+
polylinePoint.ngOnChanges(positionChanges);
29+
30+
expect(polylinePoint.positionChanged.emit).toHaveBeenCalledWith({lat: 50, lng: 'newLng'});
31+
});
32+
it('should emit positionChanged on latitude and longitude change', () => {
33+
const polylinePoint = new AgmPolylinePoint();
34+
polylinePoint.latitude = 50;
35+
polylinePoint.longitude = -50;
36+
polylinePoint.positionChanged.emit = jest.fn();
37+
38+
const positionChanges: SimpleChanges = {
39+
'latitude': new SimpleChange('previousLat', 'newLat', false),
40+
'longitude': new SimpleChange('previousLng', 'newLng', false)
41+
};
42+
43+
polylinePoint.ngOnChanges(positionChanges);
44+
45+
expect(polylinePoint.positionChanged.emit)
46+
.toHaveBeenCalledWith({lat: 'newLat', lng: 'newLng'});
47+
});
48+
});
49+
});

packages/core/directives/polyline-point.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export class AgmPolylinePoint implements OnChanges {
2727
ngOnChanges(changes: SimpleChanges): any {
2828
if (changes['latitude'] || changes['longitude']) {
2929
const position: LatLngLiteral = <LatLngLiteral>{
30-
lat: changes['latitude'].currentValue,
31-
lng: changes['longitude'].currentValue
30+
lat: changes['latitude'] ? changes['latitude'].currentValue : this.latitude,
31+
lng: changes['longitude'] ? changes['longitude'].currentValue : this.longitude
3232
};
3333
this.positionChanged.emit(position);
3434
}

0 commit comments

Comments
 (0)