UNPKG

8.03 kBJavaScriptView Raw
1"use strict";
2var core_1 = require('@angular/core');
3var circle_manager_1 = require('../services/managers/circle-manager');
4var SebmGoogleMapCircle = (function () {
5 function SebmGoogleMapCircle(_manager) {
6 this._manager = _manager;
7 /**
8 * Indicates whether this Circle handles mouse events. Defaults to true.
9 */
10 this.clickable = true;
11 /**
12 * If set to true, the user can drag this circle over the map. Defaults to false.
13 */
14 this.draggable = false;
15 /**
16 * If set to true, the user can edit this circle by dragging the control points shown at
17 * the center and around the circumference of the circle. Defaults to false.
18 */
19 this.editable = false;
20 /**
21 * The radius in meters on the Earth's surface.
22 */
23 this.radius = 0;
24 /**
25 * The stroke position. Defaults to CENTER.
26 * This property is not supported on Internet Explorer 8 and earlier.
27 */
28 this.strokePosition = 'CENTER';
29 /**
30 * The stroke width in pixels.
31 */
32 this.strokeWeight = 0;
33 /**
34 * Whether this circle is visible on the map. Defaults to true.
35 */
36 this.visible = true;
37 /**
38 * This event is fired when the circle's center is changed.
39 */
40 this.centerChange = new core_1.EventEmitter();
41 /**
42 * This event emitter gets emitted when the user clicks on the circle.
43 */
44 this.circleClick = new core_1.EventEmitter();
45 /**
46 * This event emitter gets emitted when the user clicks on the circle.
47 */
48 this.circleDblClick = new core_1.EventEmitter();
49 /**
50 * This event is repeatedly fired while the user drags the circle.
51 */
52 this.drag = new core_1.EventEmitter();
53 /**
54 * This event is fired when the user stops dragging the circle.
55 */
56 this.dragEnd = new core_1.EventEmitter();
57 /**
58 * This event is fired when the user starts dragging the circle.
59 */
60 this.dragStart = new core_1.EventEmitter();
61 /**
62 * This event is fired when the DOM mousedown event is fired on the circle.
63 */
64 this.mouseDown = new core_1.EventEmitter();
65 /**
66 * This event is fired when the DOM mousemove event is fired on the circle.
67 */
68 this.mouseMove = new core_1.EventEmitter();
69 /**
70 * This event is fired on circle mouseout.
71 */
72 this.mouseOut = new core_1.EventEmitter();
73 /**
74 * This event is fired on circle mouseover.
75 */
76 this.mouseOver = new core_1.EventEmitter();
77 /**
78 * This event is fired when the DOM mouseup event is fired on the circle.
79 */
80 this.mouseUp = new core_1.EventEmitter();
81 /**
82 * This event is fired when the circle's radius is changed.
83 */
84 this.radiusChange = new core_1.EventEmitter();
85 /**
86 * This event is fired when the circle is right-clicked on.
87 */
88 this.rightClick = new core_1.EventEmitter();
89 this._circleAddedToManager = false;
90 this._eventSubscriptions = [];
91 }
92 /** @internal */
93 SebmGoogleMapCircle.prototype.ngOnInit = function () {
94 this._manager.addCircle(this);
95 this._circleAddedToManager = true;
96 this._registerEventListeners();
97 };
98 /** @internal */
99 SebmGoogleMapCircle.prototype.ngOnChanges = function (changes) {
100 if (!this._circleAddedToManager) {
101 return;
102 }
103 if (changes['latitude'] || changes['longitude']) {
104 this._manager.setCenter(this);
105 }
106 if (changes['editable']) {
107 this._manager.setEditable(this);
108 }
109 if (changes['draggable']) {
110 this._manager.setDraggable(this);
111 }
112 if (changes['visible']) {
113 this._manager.setVisible(this);
114 }
115 if (changes['radius']) {
116 this._manager.setRadius(this);
117 }
118 this._updateCircleOptionsChanges(changes);
119 };
120 SebmGoogleMapCircle.prototype._updateCircleOptionsChanges = function (changes) {
121 var options = {};
122 var optionKeys = Object.keys(changes).filter(function (k) { return SebmGoogleMapCircle._mapOptions.indexOf(k) !== -1; });
123 optionKeys.forEach(function (k) { options[k] = changes[k].currentValue; });
124 if (optionKeys.length > 0) {
125 this._manager.setOptions(this, options);
126 }
127 };
128 SebmGoogleMapCircle.prototype._registerEventListeners = function () {
129 var _this = this;
130 var events = new Map();
131 events.set('center_changed', this.centerChange);
132 events.set('click', this.circleClick);
133 events.set('dblclick', this.circleDblClick);
134 events.set('drag', this.drag);
135 events.set('dragend', this.dragEnd);
136 events.set('dragStart', this.dragStart);
137 events.set('mousedown', this.mouseDown);
138 events.set('mousemove', this.mouseMove);
139 events.set('mouseout', this.mouseOut);
140 events.set('mouseover', this.mouseOver);
141 events.set('mouseup', this.mouseUp);
142 events.set('radius_changed', this.radiusChange);
143 events.set('rightclick', this.rightClick);
144 events.forEach(function (eventEmitter, eventName) {
145 _this._eventSubscriptions.push(_this._manager.createEventObservable(eventName, _this).subscribe(function (value) {
146 switch (eventName) {
147 case 'radius_changed':
148 _this._manager.getRadius(_this).then(function (radius) { return eventEmitter.emit(radius); });
149 break;
150 case 'center_changed':
151 _this._manager.getCenter(_this).then(function (center) {
152 return eventEmitter.emit({ lat: center.lat(), lng: center.lng() });
153 });
154 break;
155 default:
156 eventEmitter.emit({ coords: { lat: value.latLng.lat(), lng: value.latLng.lng() } });
157 }
158 }));
159 });
160 };
161 /** @internal */
162 SebmGoogleMapCircle.prototype.ngOnDestroy = function () {
163 this._eventSubscriptions.forEach(function (s) { s.unsubscribe(); });
164 this._eventSubscriptions = null;
165 this._manager.removeCircle(this);
166 };
167 /**
168 * Gets the LatLngBounds of this Circle.
169 */
170 SebmGoogleMapCircle.prototype.getBounds = function () { return this._manager.getBounds(this); };
171 SebmGoogleMapCircle.prototype.getCenter = function () { return this._manager.getCenter(this); };
172 SebmGoogleMapCircle._mapOptions = [
173 'fillColor', 'fillOpacity', 'strokeColor', 'strokeOpacity', 'strokePosition', 'strokeWeight',
174 'visible', 'zIndex'
175 ];
176 SebmGoogleMapCircle.decorators = [
177 { type: core_1.Directive, args: [{
178 selector: 'sebm-google-map-circle',
179 inputs: [
180 'latitude', 'longitude', 'clickable', 'draggable: circleDraggable', 'editable', 'fillColor',
181 'fillOpacity', 'radius', 'strokeColor', 'strokeOpacity', 'strokePosition', 'strokeWeight',
182 'visible', 'zIndex'
183 ],
184 outputs: [
185 'centerChange', 'circleClick', 'circleDblClick', 'drag', 'dragEnd', 'dragStart', 'mouseDown',
186 'mouseMove', 'mouseOut', 'mouseOver', 'mouseUp', 'radiusChange', 'rightClick'
187 ]
188 },] },
189 ];
190 /** @nocollapse */
191 SebmGoogleMapCircle.ctorParameters = function () { return [
192 { type: circle_manager_1.CircleManager, },
193 ]; };
194 return SebmGoogleMapCircle;
195}());
196exports.SebmGoogleMapCircle = SebmGoogleMapCircle;
197//# sourceMappingURL=google-map-circle.js.map
\No newline at end of file