Skip to content

Commit b669aea

Browse files
committed
fix(InfoWindow): fire infoWindowClose Event
Closes #728 Closes #811
1 parent 0789a17 commit b669aea

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/core/directives/google-map-info-window.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export class SebmGoogleMapInfoWindow implements OnDestroy, OnChanges, OnInit {
109109
this._infoWindowManager.addInfoWindow(this);
110110
this._infoWindowAddedToManager = true;
111111
this._updateOpenState();
112+
this._registerEventListeners();
112113
}
113114

114115
/** @internal */
@@ -129,8 +130,15 @@ export class SebmGoogleMapInfoWindow implements OnDestroy, OnChanges, OnInit {
129130
this._setInfoWindowOptions(changes);
130131
}
131132

133+
private _registerEventListeners() {
134+
this._infoWindowManager.createEventObservable('closeclick', this).subscribe(() => {
135+
this.isOpen = false;
136+
this.infoWindowClose.emit();
137+
});
138+
}
139+
132140
private _updateOpenState() {
133-
this.isOpen ? this._infoWindowManager.open(this) : this._infoWindowManager.close(this);
141+
this.isOpen ? this.open() : this.close();
134142
}
135143

136144
private _setInfoWindowOptions(changes: {[key: string]: SimpleChange}) {
@@ -150,7 +158,7 @@ export class SebmGoogleMapInfoWindow implements OnDestroy, OnChanges, OnInit {
150158
* Closes the info window.
151159
*/
152160
close(): Promise<void> {
153-
return this._infoWindowManager.close(this).then(() => { this.infoWindowClose.emit(void 0); });
161+
return this._infoWindowManager.close(this).then(() => { this.infoWindowClose.emit(); });
154162
}
155163

156164
/** @internal */

src/core/services/google-maps-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export interface MapTypeStyler {
164164
weight?: number;
165165
}
166166

167-
export interface InfoWindow {
167+
export interface InfoWindow extends MVCObject {
168168
constructor(opts?: InfoWindowOptions): void;
169169
close(): void;
170170
getContent(): string|Node;

src/core/services/managers/info-window-manager.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Observable } from 'rxjs/Observable';
2+
import { Observer } from 'rxjs/Observer';
13
import {Injectable, NgZone} from '@angular/core';
24

35
import {SebmGoogleMapInfoWindow} from '../../directives/google-map-info-window';
@@ -72,4 +74,15 @@ export class InfoWindowManager {
7274
const infoWindowPromise = this._mapsWrapper.createInfoWindow(options);
7375
this._infoWindows.set(infoWindow, infoWindowPromise);
7476
}
77+
78+
/**
79+
* Creates a Google Maps event listener for the given InfoWindow as an Observable
80+
*/
81+
createEventObservable<T>(eventName: string, infoWindow: SebmGoogleMapInfoWindow): Observable<T> {
82+
return Observable.create((observer: Observer<T>) => {
83+
this._infoWindows.get(infoWindow).then((i: InfoWindow) => {
84+
i.addListener(eventName, (e: T) => this._zone.run(() => observer.next(e)));
85+
});
86+
});
87+
}
7588
}

0 commit comments

Comments
 (0)