Skip to content

Commit

Permalink
fix(marker): fix mislocated info window
Browse files Browse the repository at this point in the history
Fixes the problem with mislocated info window after being removed and recreated with *ngIf

Fixes #752
Closes #754
  • Loading branch information
svarzee authored and sebholstein committed Jan 2, 2017
1 parent fc6864a commit c5a2414
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/core/directives/google-map-marker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {AfterContentInit, ContentChild, Directive, EventEmitter, OnChanges, OnDestroy, SimpleChange} from '@angular/core';
import {Directive, EventEmitter, OnChanges, OnDestroy, SimpleChange,
AfterContentInit, ContentChildren, QueryList} from '@angular/core';
import {Subscription} from 'rxjs/Subscription';

import {MouseEvent} from '../map-types';
Expand Down Expand Up @@ -119,7 +120,7 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn
/**
* @internal
*/
@ContentChild(SebmGoogleMapInfoWindow) infoWindow: SebmGoogleMapInfoWindow;
@ContentChildren(SebmGoogleMapInfoWindow) infoWindow: QueryList<SebmGoogleMapInfoWindow> = new QueryList<SebmGoogleMapInfoWindow>();

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

/* @internal */
ngAfterContentInit() {
if (this.infoWindow != null) {
this.infoWindow.hostMarker = this;
this.handleInfoWindowUpdate();
this.infoWindow.changes.subscribe(() => this.handleInfoWindowUpdate());
}

private handleInfoWindowUpdate() {
if (this.infoWindow.length > 1) {
throw new Error('Expected no more than one info window.');
}
this.infoWindow.forEach(marker => {
marker.hostMarker = this;
});
}

/** @internal */
Expand Down Expand Up @@ -173,8 +182,8 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn

private _addEventListeners() {
const cs = this._markerManager.createEventObservable('click', this).subscribe(() => {
if (this.openInfoWindow && this.infoWindow != null) {
this.infoWindow.open();
if (this.openInfoWindow) {
this.infoWindow.forEach(infoWindow => infoWindow.open());
}
this.markerClick.emit(null);
});
Expand Down

0 comments on commit c5a2414

Please sign in to comment.