Skip to content

Commit

Permalink
fix(SebmGoogleMapMarker): run click event in zone
Browse files Browse the repository at this point in the history
The markerClick event did not run in the zone.
This fixes the behavior and notifies angular
to run the change detection.
  • Loading branch information
sebholstein committed Jan 30, 2016
1 parent 592648c commit 2a3e390
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/services/marker-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/core';
import {Injectable, NgZone} from 'angular2/core';
import {Observer} from 'rxjs/Observer';
import {Observable} from 'rxjs/Observable';
import {SebmGoogleMapMarker} from '../directives/google-map-marker';
Expand All @@ -10,12 +10,20 @@ export class MarkerManager {
private _markers: Map<SebmGoogleMapMarker, Promise<Marker>> =
new Map<SebmGoogleMapMarker, Promise<Marker>>();

constructor(private _mapsWrapper: GoogleMapsAPIWrapper) {}
constructor(private _mapsWrapper: GoogleMapsAPIWrapper, private _zone: NgZone) {}

deleteMarker(marker: SebmGoogleMapMarker): Promise<void> {
let promise = this._markers.get(marker).then((m: Marker) => m.setMap(null));
this._markers.delete(marker);
return promise;
const m = this._markers.get(marker);
if (m == null) {
// marker already deleted
return Promise.resolve();
}
return m.then((m: Marker) => {
return this._zone.run(() => {
m.setMap(null);
this._markers.delete(marker);
});
});
}

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

createClickObserable(marker: SebmGoogleMapMarker): Observable<void> {
return Observable.create((observer: Observer<void>) => {
this._markers.get(marker)
.then((m: Marker) => { m.addListener('click', () => { observer.next(null); }); });
this._markers.get(marker).then((m: Marker) => {
m.addListener('click', () => this._zone.run(() => observer.next(null)));
});
});
}
}

1 comment on commit 2a3e390

@hassam7
Copy link

@hassam7 hassam7 commented on 2a3e390 Oct 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SebastianM why should the click event run in zone. I mean the google maps mvcobject architecture already takes care updating marker so why do we need to update angular too?

P.S: I hope this the right place to ask question. If please let me know I will be happy to remove this comment.

Please sign in to comment.