/**
* ng2-gm - Angular 2 components for Google Maps
* @version v0.0.2
* @link https://github.com/williampaulo/angular2-google-maps#readme
* @license MIT
*/
import {Component, SimpleChange, OnDestroy, OnChanges, ElementRef, EventEmitter} from '@angular/core';
import {InfoWindowManager} from '../services/info-window-manager';
import {SebmGoogleMapMarker} from './google-map-marker';
let infoWindowId = 0;
/**
* SebmGoogleMapInfoWindow renders a info window inside a {@link SebmGoogleMapMarker} or standalone.
*
* ### Example
* ```typescript
* import {Component} from 'angular2/core';
* import {SebmGoogleMap, SebmGoogleMapMarker, SebmGoogleMapInfoWindow} from
* 'angular2-google-maps/core';
*
* @Component({
* selector: 'my-map-cmp',
* directives: [SebmGoogleMap, SebmGoogleMapMarker, SebmGoogleMapInfoWindow],
* styles: [`
* .sebm-google-map-container {
* height: 300px;
* }
* `],
* template: `
*
*
*
* Hi, this is the content of the info window
*
*
*
* `
* })
* ```
*/
@Component({
selector: 'sebm-google-map-info-window',
inputs: ['latitude', 'longitude', 'disableAutoPan'],
outputs: ['infoWindowClose'],
template: `
`
})
export class SebmGoogleMapInfoWindow implements OnDestroy,
OnChanges {
/**
* The latitude position of the info window (only usefull if you use it ouside of a {@link
* SebmGoogleMapMarker}).
*/
latitude: number;
/**
* The longitude position of the info window (only usefull if you use it ouside of a {@link
* SebmGoogleMapMarker}).
*/
longitude: number;
/**
* Disable auto-pan on open. By default, the info window will pan the map so that it is fully
* visible when it opens.
*/
disableAutoPan: boolean;
/**
* All InfoWindows are displayed on the map in order of their zIndex, with higher values
* displaying in front of InfoWindows with lower values. By default, InfoWindows are displayed
* according to their latitude, with InfoWindows of lower latitudes appearing in front of
* InfoWindows at higher latitudes. InfoWindows are always displayed in front of markers.
*/
zIndex: number;
/**
* Maximum width of the infowindow, regardless of content's width. This value is only considered
* if it is set before a call to open. To change the maximum width when changing content, call
* close, update maxWidth, and then open.
*/
maxWidth: number;
/**
* Holds the marker that is the host of the info window (if available)
*/
hostMarker: SebmGoogleMapMarker;
/**
* Holds the native element that is used for the info window content.
*/
content: Node;
/**
* Emits an event when the info window is closed.
*/
infoWindowClose: EventEmitter = new EventEmitter();
private static _infoWindowOptionsInputs: string[] = ['disableAutoPan', 'maxWidth'];
private _infoWindowAddedToManager: boolean = false;
private _id: string = (infoWindowId++).toString();
constructor(private _infoWindowManager: InfoWindowManager, private _el: ElementRef) {}
ngOnInit() {
this.content = this._el.nativeElement.querySelector('.sebm-google-map-info-window-content');
this._infoWindowManager.addInfoWindow(this);
this._infoWindowAddedToManager = true;
}
/** @internal */
ngOnChanges(changes: {[key: string]: SimpleChange}) {
if (!this._infoWindowAddedToManager) {
return;
}
if ((changes['latitude'] || changes['longitude']) && typeof this.latitude === 'number' &&
typeof this.longitude === 'number') {
this._infoWindowManager.setPosition(this);
}
if (changes['zIndex']) {
this._infoWindowManager.setZIndex(this);
}
this._setInfoWindowOptions(changes);
}
private _setInfoWindowOptions(changes: {[key: string]: SimpleChange}) {
let options: {[propName: string]: any} = {};
let optionKeys = Object.keys(changes).filter(
k => SebmGoogleMapInfoWindow._infoWindowOptionsInputs.indexOf(k) !== -1);
optionKeys.forEach((k) => { options[k] = changes[k].currentValue; });
this._infoWindowManager.setOptions(this, options);
}
/**
* Opens the info window.
*/
open(): Promise { return this._infoWindowManager.open(this); }
/**
* Closes the info window.
*/
close(): Promise {
return this._infoWindowManager.close(this).then(() => { this.infoWindowClose.emit(void 0); });
}
/** @internal */
id(): string { return this._id; }
/** @internal */
toString(): string { return 'SebmGoogleMapInfoWindow-' + this._id.toString(); }
/** @internal */
ngOnDestroy() { this._infoWindowManager.deleteInfoWindow(this); }
}