UNPKG

6.71 kBJavaScriptView Raw
1"use strict";
2var core_1 = require('@angular/core');
3var marker_manager_1 = require('../services/managers/marker-manager');
4var google_map_info_window_1 = require('./google-map-info-window');
5var markerId = 0;
6/**
7 * SebmGoogleMapMarker renders a map marker inside a {@link SebmGoogleMap}.
8 *
9 * ### Example
10 * ```typescript
11 * import { Component } from 'angular2/core';
12 * import { SebmGoogleMap, SebmGoogleMapMarker } from 'angular2-google-maps/core';
13 *
14 * @Component({
15 * selector: 'my-map-cmp',
16 * directives: [SebmGoogleMap, SebmGoogleMapMarker],
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-marker>
26 * </sebm-google-map>
27 * `
28 * })
29 * ```
30 */
31var SebmGoogleMapMarker = (function () {
32 function SebmGoogleMapMarker(_markerManager) {
33 this._markerManager = _markerManager;
34 /**
35 * If true, the marker can be dragged. Default value is false.
36 */
37 this.draggable = false;
38 /**
39 * If true, the marker is visible
40 */
41 this.visible = true;
42 /**
43 * Whether to automatically open the child info window when the marker is clicked.
44 */
45 this.openInfoWindow = true;
46 /**
47 * The marker's opacity between 0.0 and 1.0.
48 */
49 this.opacity = 1;
50 /**
51 * All markers are displayed on the map in order of their zIndex, with higher values displaying in
52 * front of markers with lower values. By default, markers are displayed according to their
53 * vertical position on screen, with lower markers appearing in front of markers further up the
54 * screen.
55 */
56 this.zIndex = 1;
57 /**
58 * This event emitter gets emitted when the user clicks on the marker.
59 */
60 this.markerClick = new core_1.EventEmitter();
61 /**
62 * This event is fired when the user stops dragging the marker.
63 */
64 this.dragEnd = new core_1.EventEmitter();
65 /**
66 * This event is fired when the user mouses over the marker.
67 */
68 this.mouseOver = new core_1.EventEmitter();
69 /**
70 * This event is fired when the user mouses outside the marker.
71 */
72 this.mouseOut = new core_1.EventEmitter();
73 this._markerAddedToManger = false;
74 this._observableSubscriptions = [];
75 this._id = (markerId++).toString();
76 }
77 /* @internal */
78 SebmGoogleMapMarker.prototype.ngAfterContentInit = function () {
79 if (this.infoWindow != null) {
80 this.infoWindow.hostMarker = this;
81 }
82 };
83 /** @internal */
84 SebmGoogleMapMarker.prototype.ngOnChanges = function (changes) {
85 if (typeof this.latitude !== 'number' || typeof this.longitude !== 'number') {
86 return;
87 }
88 if (!this._markerAddedToManger) {
89 this._markerManager.addMarker(this);
90 this._markerAddedToManger = true;
91 this._addEventListeners();
92 return;
93 }
94 if (changes['latitude'] || changes['longitude']) {
95 this._markerManager.updateMarkerPosition(this);
96 }
97 if (changes['title']) {
98 this._markerManager.updateTitle(this);
99 }
100 if (changes['label']) {
101 this._markerManager.updateLabel(this);
102 }
103 if (changes['draggable']) {
104 this._markerManager.updateDraggable(this);
105 }
106 if (changes['iconUrl']) {
107 this._markerManager.updateIcon(this);
108 }
109 if (changes['opacity']) {
110 this._markerManager.updateOpacity(this);
111 }
112 if (changes['visible']) {
113 this._markerManager.updateVisible(this);
114 }
115 if (changes['zIndex']) {
116 this._markerManager.updateZIndex(this);
117 }
118 };
119 SebmGoogleMapMarker.prototype._addEventListeners = function () {
120 var _this = this;
121 var cs = this._markerManager.createEventObservable('click', this).subscribe(function () {
122 if (_this.openInfoWindow && _this.infoWindow != null) {
123 _this.infoWindow.open();
124 }
125 _this.markerClick.emit(null);
126 });
127 this._observableSubscriptions.push(cs);
128 var ds = this._markerManager.createEventObservable('dragend', this)
129 .subscribe(function (e) {
130 _this.dragEnd.emit({ coords: { lat: e.latLng.lat(), lng: e.latLng.lng() } });
131 });
132 this._observableSubscriptions.push(ds);
133 var mover = this._markerManager.createEventObservable('mouseover', this)
134 .subscribe(function (e) {
135 _this.mouseOver.emit({ coords: { lat: e.latLng.lat(), lng: e.latLng.lng() } });
136 });
137 this._observableSubscriptions.push(mover);
138 var mout = this._markerManager.createEventObservable('mouseout', this)
139 .subscribe(function (e) {
140 _this.mouseOut.emit({ coords: { lat: e.latLng.lat(), lng: e.latLng.lng() } });
141 });
142 this._observableSubscriptions.push(mout);
143 };
144 /** @internal */
145 SebmGoogleMapMarker.prototype.id = function () { return this._id; };
146 /** @internal */
147 SebmGoogleMapMarker.prototype.toString = function () { return 'SebmGoogleMapMarker-' + this._id.toString(); };
148 /** @internal */
149 SebmGoogleMapMarker.prototype.ngOnDestroy = function () {
150 this._markerManager.deleteMarker(this);
151 // unsubscribe all registered observable subscriptions
152 this._observableSubscriptions.forEach(function (s) { return s.unsubscribe(); });
153 };
154 SebmGoogleMapMarker.decorators = [
155 { type: core_1.Directive, args: [{
156 selector: 'sebm-google-map-marker',
157 inputs: [
158 'latitude', 'longitude', 'title', 'label', 'draggable: markerDraggable', 'iconUrl',
159 'openInfoWindow', 'opacity', 'visible', 'zIndex'
160 ],
161 outputs: ['markerClick', 'dragEnd', 'mouseOver', 'mouseOut']
162 },] },
163 ];
164 /** @nocollapse */
165 SebmGoogleMapMarker.ctorParameters = function () { return [
166 { type: marker_manager_1.MarkerManager, },
167 ]; };
168 SebmGoogleMapMarker.propDecorators = {
169 'infoWindow': [{ type: core_1.ContentChild, args: [google_map_info_window_1.SebmGoogleMapInfoWindow,] },],
170 };
171 return SebmGoogleMapMarker;
172}());
173exports.SebmGoogleMapMarker = SebmGoogleMapMarker;
174//# sourceMappingURL=google-map-marker.js.map
\No newline at end of file