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

Commit 2a3e390

Browse files
committed
fix(SebmGoogleMapMarker): run click event in zone
The markerClick event did not run in the zone. This fixes the behavior and notifies angular to run the change detection.
1 parent 592648c commit 2a3e390

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/services/marker-manager.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Injectable} from 'angular2/core';
1+
import {Injectable, NgZone} from 'angular2/core';
22
import {Observer} from 'rxjs/Observer';
33
import {Observable} from 'rxjs/Observable';
44
import {SebmGoogleMapMarker} from '../directives/google-map-marker';
@@ -10,12 +10,20 @@ export class MarkerManager {
1010
private _markers: Map<SebmGoogleMapMarker, Promise<Marker>> =
1111
new Map<SebmGoogleMapMarker, Promise<Marker>>();
1212

13-
constructor(private _mapsWrapper: GoogleMapsAPIWrapper) {}
13+
constructor(private _mapsWrapper: GoogleMapsAPIWrapper, private _zone: NgZone) {}
1414

1515
deleteMarker(marker: SebmGoogleMapMarker): Promise<void> {
16-
let promise = this._markers.get(marker).then((m: Marker) => m.setMap(null));
17-
this._markers.delete(marker);
18-
return promise;
16+
const m = this._markers.get(marker);
17+
if (m == null) {
18+
// marker already deleted
19+
return Promise.resolve();
20+
}
21+
return m.then((m: Marker) => {
22+
return this._zone.run(() => {
23+
m.setMap(null);
24+
this._markers.delete(marker);
25+
});
26+
});
1927
}
2028

2129
updateMarkerPosition(marker: SebmGoogleMapMarker): Promise<void> {
@@ -43,8 +51,9 @@ export class MarkerManager {
4351

4452
createClickObserable(marker: SebmGoogleMapMarker): Observable<void> {
4553
return Observable.create((observer: Observer<void>) => {
46-
this._markers.get(marker)
47-
.then((m: Marker) => { m.addListener('click', () => { observer.next(null); }); });
54+
this._markers.get(marker).then((m: Marker) => {
55+
m.addListener('click', () => this._zone.run(() => observer.next(null)));
56+
});
4857
});
4958
}
5059
}

0 commit comments

Comments
 (0)