UNPKG

5.14 kBJavaScriptView Raw
1"use strict";
2var core_1 = require('@angular/core');
3var info_window_manager_1 = require('../services/managers/info-window-manager');
4var infoWindowId = 0;
5/**
6 * SebmGoogleMapInfoWindow renders a info window inside a {@link SebmGoogleMapMarker} or standalone.
7 *
8 * ### Example
9 * ```typescript
10 * import { Component } from 'angular2/core';
11 * import { SebmGoogleMap, SebmGoogleMapMarker, SebmGoogleMapInfoWindow } from
12 * 'angular2-google-maps/core';
13 *
14 * @Component({
15 * selector: 'my-map-cmp',
16 * directives: [SebmGoogleMap, SebmGoogleMapMarker, SebmGoogleMapInfoWindow],
17 * styles: [`
18 * .sebm-google-map-container {
19 * height: 300px;
20 * }
21 * `],
22 * template: `
23 * <sebm-google-map [latitude]="lat" [longitude]="lng" [zoom]="zoom">
24 * <sebm-google-map-marker [latitude]="lat" [longitude]="lng" [label]="'M'">
25 * <sebm-google-map-info-window [disableAutoPan]="true">
26 * Hi, this is the content of the <strong>info window</strong>
27 * </sebm-google-map-info-window>
28 * </sebm-google-map-marker>
29 * </sebm-google-map>
30 * `
31 * })
32 * ```
33 */
34var SebmGoogleMapInfoWindow = (function () {
35 function SebmGoogleMapInfoWindow(_infoWindowManager, _el) {
36 this._infoWindowManager = _infoWindowManager;
37 this._el = _el;
38 /**
39 * Sets the open state for the InfoWindow. You can also call the open() and close() methods.
40 */
41 this.isOpen = false;
42 /**
43 * Emits an event when the info window is closed.
44 */
45 this.infoWindowClose = new core_1.EventEmitter();
46 this._infoWindowAddedToManager = false;
47 this._id = (infoWindowId++).toString();
48 }
49 SebmGoogleMapInfoWindow.prototype.ngOnInit = function () {
50 this.content = this._el.nativeElement.querySelector('.sebm-google-map-info-window-content');
51 this._infoWindowManager.addInfoWindow(this);
52 this._infoWindowAddedToManager = true;
53 this._updateOpenState();
54 this._registerEventListeners();
55 };
56 /** @internal */
57 SebmGoogleMapInfoWindow.prototype.ngOnChanges = function (changes) {
58 if (!this._infoWindowAddedToManager) {
59 return;
60 }
61 if ((changes['latitude'] || changes['longitude']) && typeof this.latitude === 'number' &&
62 typeof this.longitude === 'number') {
63 this._infoWindowManager.setPosition(this);
64 }
65 if (changes['zIndex']) {
66 this._infoWindowManager.setZIndex(this);
67 }
68 if (changes['isOpen']) {
69 this._updateOpenState();
70 }
71 this._setInfoWindowOptions(changes);
72 };
73 SebmGoogleMapInfoWindow.prototype._registerEventListeners = function () {
74 var _this = this;
75 this._infoWindowManager.createEventObservable('closeclick', this).subscribe(function () {
76 _this.isOpen = false;
77 _this.infoWindowClose.emit();
78 });
79 };
80 SebmGoogleMapInfoWindow.prototype._updateOpenState = function () {
81 this.isOpen ? this.open() : this.close();
82 };
83 SebmGoogleMapInfoWindow.prototype._setInfoWindowOptions = function (changes) {
84 var options = {};
85 var optionKeys = Object.keys(changes).filter(function (k) { return SebmGoogleMapInfoWindow._infoWindowOptionsInputs.indexOf(k) !== -1; });
86 optionKeys.forEach(function (k) { options[k] = changes[k].currentValue; });
87 this._infoWindowManager.setOptions(this, options);
88 };
89 /**
90 * Opens the info window.
91 */
92 SebmGoogleMapInfoWindow.prototype.open = function () { return this._infoWindowManager.open(this); };
93 /**
94 * Closes the info window.
95 */
96 SebmGoogleMapInfoWindow.prototype.close = function () {
97 var _this = this;
98 return this._infoWindowManager.close(this).then(function () { _this.infoWindowClose.emit(); });
99 };
100 /** @internal */
101 SebmGoogleMapInfoWindow.prototype.id = function () { return this._id; };
102 /** @internal */
103 SebmGoogleMapInfoWindow.prototype.toString = function () { return 'SebmGoogleMapInfoWindow-' + this._id.toString(); };
104 /** @internal */
105 SebmGoogleMapInfoWindow.prototype.ngOnDestroy = function () { this._infoWindowManager.deleteInfoWindow(this); };
106 SebmGoogleMapInfoWindow._infoWindowOptionsInputs = ['disableAutoPan', 'maxWidth'];
107 SebmGoogleMapInfoWindow.decorators = [
108 { type: core_1.Component, args: [{
109 selector: 'sebm-google-map-info-window',
110 inputs: ['latitude', 'longitude', 'disableAutoPan', 'isOpen', 'zIndex', 'maxWidth'],
111 outputs: ['infoWindowClose'],
112 template: "<div class='sebm-google-map-info-window-content'>\n <ng-content></ng-content>\n </div>\n "
113 },] },
114 ];
115 /** @nocollapse */
116 SebmGoogleMapInfoWindow.ctorParameters = function () { return [
117 { type: info_window_manager_1.InfoWindowManager, },
118 { type: core_1.ElementRef, },
119 ]; };
120 return SebmGoogleMapInfoWindow;
121}());
122exports.SebmGoogleMapInfoWindow = SebmGoogleMapInfoWindow;
123//# sourceMappingURL=google-map-info-window.js.map
\No newline at end of file