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

Commit c5a2414

Browse files
svarzeesebholstein
authored andcommitted
fix(marker): fix mislocated info window
Fixes the problem with mislocated info window after being removed and recreated with *ngIf Fixes #752 Closes #754
1 parent fc6864a commit c5a2414

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/core/directives/google-map-marker.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {AfterContentInit, ContentChild, Directive, EventEmitter, OnChanges, OnDestroy, SimpleChange} from '@angular/core';
1+
import {Directive, EventEmitter, OnChanges, OnDestroy, SimpleChange,
2+
AfterContentInit, ContentChildren, QueryList} from '@angular/core';
23
import {Subscription} from 'rxjs/Subscription';
34

45
import {MouseEvent} from '../map-types';
@@ -119,7 +120,7 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn
119120
/**
120121
* @internal
121122
*/
122-
@ContentChild(SebmGoogleMapInfoWindow) infoWindow: SebmGoogleMapInfoWindow;
123+
@ContentChildren(SebmGoogleMapInfoWindow) infoWindow: QueryList<SebmGoogleMapInfoWindow> = new QueryList<SebmGoogleMapInfoWindow>();
123124

124125
private _markerAddedToManger: boolean = false;
125126
private _id: string;
@@ -129,9 +130,17 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn
129130

130131
/* @internal */
131132
ngAfterContentInit() {
132-
if (this.infoWindow != null) {
133-
this.infoWindow.hostMarker = this;
133+
this.handleInfoWindowUpdate();
134+
this.infoWindow.changes.subscribe(() => this.handleInfoWindowUpdate());
135+
}
136+
137+
private handleInfoWindowUpdate() {
138+
if (this.infoWindow.length > 1) {
139+
throw new Error('Expected no more than one info window.');
134140
}
141+
this.infoWindow.forEach(marker => {
142+
marker.hostMarker = this;
143+
});
135144
}
136145

137146
/** @internal */
@@ -173,8 +182,8 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn
173182

174183
private _addEventListeners() {
175184
const cs = this._markerManager.createEventObservable('click', this).subscribe(() => {
176-
if (this.openInfoWindow && this.infoWindow != null) {
177-
this.infoWindow.open();
185+
if (this.openInfoWindow) {
186+
this.infoWindow.forEach(infoWindow => infoWindow.open());
178187
}
179188
this.markerClick.emit(null);
180189
});

0 commit comments

Comments
 (0)