UNPKG

8.99 kBJavaScriptView Raw
1"use strict";
2var core_1 = require('@angular/core');
3var polyline_manager_1 = require('../services/managers/polyline-manager');
4var google_map_polyline_point_1 = require('./google-map-polyline-point');
5var polylineId = 0;
6/**
7 * SebmGoogleMapPolyline renders a polyline on a {@link SebmGoogleMap}
8 *
9 * ### Example
10 * ```typescript
11 * import { Component } from 'angular2/core';
12 * import { SebmGoogleMap, SebmGooglePolyline, SebmGooglePolylinePoint } from
13 * 'angular2-google-maps/core';
14 *
15 * @Component({
16 * selector: 'my-map-cmp',
17 * directives: [SebmGoogleMap, SebmGooglePolyline, SebmGooglePolylinePoint],
18 * styles: [`
19 * .sebm-google-map-container {
20 * height: 300px;
21 * }
22 * `],
23 * template: `
24 * <sebm-google-map [latitude]="lat" [longitude]="lng" [zoom]="zoom">
25 * <sebm-google-map-polyline>
26 * <sebm-google-map-polyline-point [latitude]="latA" [longitude]="lngA">
27 * </sebm-google-map-polyline-point>
28 * <sebm-google-map-polyline-point [latitude]="latB" [longitude]="lngB">
29 * </sebm-google-map-polyline-point>
30 * </sebm-google-map-polyline>
31 * </sebm-google-map>
32 * `
33 * })
34 * ```
35 */
36var SebmGoogleMapPolyline = (function () {
37 function SebmGoogleMapPolyline(_polylineManager) {
38 this._polylineManager = _polylineManager;
39 /**
40 * Indicates whether this Polyline handles mouse events. Defaults to true.
41 */
42 this.clickable = true;
43 /**
44 * If set to true, the user can drag this shape over the map. The geodesic property defines the
45 * mode of dragging. Defaults to false.
46 */
47 this.draggable = false;
48 /**
49 * If set to true, the user can edit this shape by dragging the control points shown at the
50 * vertices and on each segment. Defaults to false.
51 */
52 this.editable = false;
53 /**
54 * When true, edges of the polygon are interpreted as geodesic and will follow the curvature of
55 * the Earth. When false, edges of the polygon are rendered as straight lines in screen space.
56 * Note that the shape of a geodesic polygon may appear to change when dragged, as the dimensions
57 * are maintained relative to the surface of the earth. Defaults to false.
58 */
59 this.geodesic = false;
60 /**
61 * Whether this polyline is visible on the map. Defaults to true.
62 */
63 this.visible = true;
64 /**
65 * This event is fired when the DOM click event is fired on the Polyline.
66 */
67 this.lineClick = new core_1.EventEmitter();
68 /**
69 * This event is fired when the DOM dblclick event is fired on the Polyline.
70 */
71 this.lineDblClick = new core_1.EventEmitter();
72 /**
73 * This event is repeatedly fired while the user drags the polyline.
74 */
75 this.lineDrag = new core_1.EventEmitter();
76 /**
77 * This event is fired when the user stops dragging the polyline.
78 */
79 this.lineDragEnd = new core_1.EventEmitter();
80 /**
81 * This event is fired when the user starts dragging the polyline.
82 */
83 this.lineDragStart = new core_1.EventEmitter();
84 /**
85 * This event is fired when the DOM mousedown event is fired on the Polyline.
86 */
87 this.lineMouseDown = new core_1.EventEmitter();
88 /**
89 * This event is fired when the DOM mousemove event is fired on the Polyline.
90 */
91 this.lineMouseMove = new core_1.EventEmitter();
92 /**
93 * This event is fired on Polyline mouseout.
94 */
95 this.lineMouseOut = new core_1.EventEmitter();
96 /**
97 * This event is fired on Polyline mouseover.
98 */
99 this.lineMouseOver = new core_1.EventEmitter();
100 /**
101 * This event is fired whe the DOM mouseup event is fired on the Polyline
102 */
103 this.lineMouseUp = new core_1.EventEmitter();
104 /**
105 * This even is fired when the Polyline is right-clicked on.
106 */
107 this.lineRightClick = new core_1.EventEmitter();
108 this._polylineAddedToManager = false;
109 this._subscriptions = [];
110 this._id = (polylineId++).toString();
111 }
112 /** @internal */
113 SebmGoogleMapPolyline.prototype.ngAfterContentInit = function () {
114 var _this = this;
115 if (this.points.length) {
116 this.points.forEach(function (point) {
117 var s = point.positionChanged.subscribe(function () { _this._polylineManager.updatePolylinePoints(_this); });
118 _this._subscriptions.push(s);
119 });
120 }
121 if (!this._polylineAddedToManager) {
122 this._init();
123 }
124 var s = this.points.changes.subscribe(function () { return _this._polylineManager.updatePolylinePoints(_this); });
125 this._subscriptions.push(s);
126 this._polylineManager.updatePolylinePoints(this);
127 };
128 SebmGoogleMapPolyline.prototype.ngOnChanges = function (changes) {
129 if (!this._polylineAddedToManager) {
130 this._init();
131 return;
132 }
133 var options = {};
134 var optionKeys = Object.keys(changes).filter(function (k) { return SebmGoogleMapPolyline._polylineOptionsAttributes.indexOf(k) !== -1; });
135 optionKeys.forEach(function (k) { return options[k] = changes[k].currentValue; });
136 this._polylineManager.setPolylineOptions(this, options);
137 };
138 SebmGoogleMapPolyline.prototype._init = function () {
139 this._polylineManager.addPolyline(this);
140 this._polylineAddedToManager = true;
141 this._addEventListeners();
142 };
143 SebmGoogleMapPolyline.prototype._addEventListeners = function () {
144 var _this = this;
145 var handlers = [
146 { name: 'click', handler: function (ev) { return _this.lineClick.emit(ev); } },
147 { name: 'dbclick', handler: function (ev) { return _this.lineDblClick.emit(ev); } },
148 { name: 'drag', handler: function (ev) { return _this.lineDrag.emit(ev); } },
149 { name: 'dragend', handler: function (ev) { return _this.lineDragEnd.emit(ev); } },
150 { name: 'dragstart', handler: function (ev) { return _this.lineDragStart.emit(ev); } },
151 { name: 'mousedown', handler: function (ev) { return _this.lineMouseDown.emit(ev); } },
152 { name: 'mousemove', handler: function (ev) { return _this.lineMouseMove.emit(ev); } },
153 { name: 'mouseout', handler: function (ev) { return _this.lineMouseOut.emit(ev); } },
154 { name: 'mouseover', handler: function (ev) { return _this.lineMouseOver.emit(ev); } },
155 { name: 'mouseup', handler: function (ev) { return _this.lineMouseUp.emit(ev); } },
156 { name: 'rightclick', handler: function (ev) { return _this.lineRightClick.emit(ev); } },
157 ];
158 handlers.forEach(function (obj) {
159 var os = _this._polylineManager.createEventObservable(obj.name, _this).subscribe(obj.handler);
160 _this._subscriptions.push(os);
161 });
162 };
163 /** @internal */
164 SebmGoogleMapPolyline.prototype._getPoints = function () {
165 if (this.points) {
166 return this.points.toArray();
167 }
168 return [];
169 };
170 /** @internal */
171 SebmGoogleMapPolyline.prototype.id = function () { return this._id; };
172 /** @internal */
173 SebmGoogleMapPolyline.prototype.ngOnDestroy = function () {
174 this._polylineManager.deletePolyline(this);
175 // unsubscribe all registered observable subscriptions
176 this._subscriptions.forEach(function (s) { return s.unsubscribe(); });
177 };
178 SebmGoogleMapPolyline._polylineOptionsAttributes = [
179 'draggable', 'editable', 'visible', 'geodesic', 'strokeColor', 'strokeOpacity', 'strokeWeight',
180 'zIndex'
181 ];
182 SebmGoogleMapPolyline.decorators = [
183 { type: core_1.Directive, args: [{
184 selector: 'sebm-google-map-polyline',
185 inputs: [
186 'clickable', 'draggable: polylineDraggable', 'editable', 'geodesic', 'strokeColor',
187 'strokeWeight', 'strokeOpacity', 'visible', 'zIndex'
188 ],
189 outputs: [
190 'lineClick', 'lineDblClick', 'lineDrag', 'lineDragEnd', 'lineMouseDown', 'lineMouseMove',
191 'lineMouseOut', 'lineMouseOver', 'lineMouseUp', 'lineRightClick'
192 ]
193 },] },
194 ];
195 /** @nocollapse */
196 SebmGoogleMapPolyline.ctorParameters = function () { return [
197 { type: polyline_manager_1.PolylineManager, },
198 ]; };
199 SebmGoogleMapPolyline.propDecorators = {
200 'points': [{ type: core_1.ContentChildren, args: [google_map_polyline_point_1.SebmGoogleMapPolylinePoint,] },],
201 };
202 return SebmGoogleMapPolyline;
203}());
204exports.SebmGoogleMapPolyline = SebmGoogleMapPolyline;
205//# sourceMappingURL=google-map-polyline.js.map
\No newline at end of file