1
- import { Injectable } from 'angular2/core' ;
1
+ import { Injectable , NgZone } from 'angular2/core' ;
2
2
import { Observer } from 'rxjs/Observer' ;
3
3
import { Observable } from 'rxjs/Observable' ;
4
4
import { SebmGoogleMapMarker } from '../directives/google-map-marker' ;
@@ -10,12 +10,20 @@ export class MarkerManager {
10
10
private _markers : Map < SebmGoogleMapMarker , Promise < Marker > > =
11
11
new Map < SebmGoogleMapMarker , Promise < Marker > > ( ) ;
12
12
13
- constructor ( private _mapsWrapper : GoogleMapsAPIWrapper ) { }
13
+ constructor ( private _mapsWrapper : GoogleMapsAPIWrapper , private _zone : NgZone ) { }
14
14
15
15
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
+ } ) ;
19
27
}
20
28
21
29
updateMarkerPosition ( marker : SebmGoogleMapMarker ) : Promise < void > {
@@ -43,8 +51,9 @@ export class MarkerManager {
43
51
44
52
createClickObserable ( marker : SebmGoogleMapMarker ) : Observable < void > {
45
53
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
+ } ) ;
48
57
} ) ;
49
58
}
50
59
}
0 commit comments