1 | "use strict";
|
2 | var core_1 = require('@angular/core');
|
3 | var google_maps_api_wrapper_1 = require('../services/google-maps-api-wrapper');
|
4 | var circle_manager_1 = require('../services/managers/circle-manager');
|
5 | var info_window_manager_1 = require('../services/managers/info-window-manager');
|
6 | var marker_manager_1 = require('../services/managers/marker-manager');
|
7 | var polygon_manager_1 = require('../services/managers/polygon-manager');
|
8 | var polyline_manager_1 = require('../services/managers/polyline-manager');
|
9 | var kml_layer_manager_1 = require('./../services/managers/kml-layer-manager');
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | var SebmGoogleMap = (function () {
|
36 | function SebmGoogleMap(_elem, _mapsWrapper) {
|
37 | this._elem = _elem;
|
38 | this._mapsWrapper = _mapsWrapper;
|
39 | |
40 |
|
41 |
|
42 | this.longitude = 0;
|
43 | |
44 |
|
45 |
|
46 | this.latitude = 0;
|
47 | |
48 |
|
49 |
|
50 | this.zoom = 8;
|
51 | |
52 |
|
53 |
|
54 | this.draggable = true;
|
55 | |
56 |
|
57 |
|
58 | this.disableDoubleClickZoom = false;
|
59 | |
60 |
|
61 |
|
62 |
|
63 | this.disableDefaultUI = false;
|
64 | |
65 |
|
66 |
|
67 | this.scrollwheel = true;
|
68 | |
69 |
|
70 |
|
71 |
|
72 | this.keyboardShortcuts = true;
|
73 | |
74 |
|
75 |
|
76 | this.zoomControl = true;
|
77 | |
78 |
|
79 |
|
80 |
|
81 | this.styles = [];
|
82 | |
83 |
|
84 |
|
85 |
|
86 |
|
87 | this.usePanning = false;
|
88 | |
89 |
|
90 |
|
91 |
|
92 |
|
93 | this.streetViewControl = true;
|
94 | |
95 |
|
96 |
|
97 | this.fitBounds = null;
|
98 | |
99 |
|
100 |
|
101 | this.scaleControl = false;
|
102 | |
103 |
|
104 |
|
105 | this.mapTypeControl = false;
|
106 | this._observableSubscriptions = [];
|
107 | |
108 |
|
109 |
|
110 |
|
111 | this.mapClick = new core_1.EventEmitter();
|
112 | |
113 |
|
114 |
|
115 |
|
116 | this.mapRightClick = new core_1.EventEmitter();
|
117 | |
118 |
|
119 |
|
120 |
|
121 | this.mapDblClick = new core_1.EventEmitter();
|
122 | |
123 |
|
124 |
|
125 | this.centerChange = new core_1.EventEmitter();
|
126 | |
127 |
|
128 |
|
129 | this.boundsChange = new core_1.EventEmitter();
|
130 | |
131 |
|
132 |
|
133 | this.idle = new core_1.EventEmitter();
|
134 | |
135 |
|
136 |
|
137 | this.zoomChange = new core_1.EventEmitter();
|
138 | }
|
139 |
|
140 | SebmGoogleMap.prototype.ngOnInit = function () {
|
141 |
|
142 | var container = this._elem.nativeElement.querySelector('.sebm-google-map-container-inner');
|
143 | this._initMapInstance(container);
|
144 | };
|
145 | SebmGoogleMap.prototype._initMapInstance = function (el) {
|
146 | this._mapsWrapper.createMap(el, {
|
147 | center: { lat: this.latitude || 0, lng: this.longitude || 0 },
|
148 | zoom: this.zoom,
|
149 | minZoom: this.minZoom,
|
150 | maxZoom: this.maxZoom,
|
151 | disableDefaultUI: this.disableDefaultUI,
|
152 | backgroundColor: this.backgroundColor,
|
153 | draggable: this.draggable,
|
154 | draggableCursor: this.draggableCursor,
|
155 | draggingCursor: this.draggingCursor,
|
156 | keyboardShortcuts: this.keyboardShortcuts,
|
157 | zoomControl: this.zoomControl,
|
158 | styles: this.styles,
|
159 | streetViewControl: this.streetViewControl,
|
160 | scaleControl: this.scaleControl,
|
161 | mapTypeControl: this.mapTypeControl
|
162 | });
|
163 |
|
164 | this._handleMapCenterChange();
|
165 | this._handleMapZoomChange();
|
166 | this._handleMapMouseEvents();
|
167 | this._handleBoundsChange();
|
168 | this._handleIdleEvent();
|
169 | };
|
170 |
|
171 | SebmGoogleMap.prototype.ngOnDestroy = function () {
|
172 |
|
173 | this._observableSubscriptions.forEach(function (s) { return s.unsubscribe(); });
|
174 | };
|
175 |
|
176 | SebmGoogleMap.prototype.ngOnChanges = function (changes) {
|
177 | this._updateMapOptionsChanges(changes);
|
178 | this._updatePosition(changes);
|
179 | };
|
180 | SebmGoogleMap.prototype._updateMapOptionsChanges = function (changes) {
|
181 | var options = {};
|
182 | var optionKeys = Object.keys(changes).filter(function (k) { return SebmGoogleMap._mapOptionsAttributes.indexOf(k) !== -1; });
|
183 | optionKeys.forEach(function (k) { options[k] = changes[k].currentValue; });
|
184 | this._mapsWrapper.setMapOptions(options);
|
185 | };
|
186 | |
187 |
|
188 |
|
189 |
|
190 | SebmGoogleMap.prototype.triggerResize = function () {
|
191 | var _this = this;
|
192 |
|
193 |
|
194 |
|
195 | return new Promise(function (resolve) {
|
196 | setTimeout(function () { return _this._mapsWrapper.triggerMapEvent('resize').then(function () { return resolve(); }); });
|
197 | });
|
198 | };
|
199 | SebmGoogleMap.prototype._updatePosition = function (changes) {
|
200 | if (changes['latitude'] == null && changes['longitude'] == null &&
|
201 | changes['fitBounds'] == null) {
|
202 |
|
203 | return;
|
204 | }
|
205 |
|
206 | if (changes['fitBounds'] && this.fitBounds != null) {
|
207 | this._fitBounds();
|
208 | return;
|
209 | }
|
210 | if (typeof this.latitude !== 'number' || typeof this.longitude !== 'number') {
|
211 | return;
|
212 | }
|
213 | var newCenter = {
|
214 | lat: this.latitude,
|
215 | lng: this.longitude,
|
216 | };
|
217 | if (this.usePanning) {
|
218 | this._mapsWrapper.panTo(newCenter);
|
219 | }
|
220 | else {
|
221 | this._mapsWrapper.setCenter(newCenter);
|
222 | }
|
223 | };
|
224 | SebmGoogleMap.prototype._fitBounds = function () {
|
225 | if (this.usePanning) {
|
226 | this._mapsWrapper.panToBounds(this.fitBounds);
|
227 | return;
|
228 | }
|
229 | this._mapsWrapper.fitBounds(this.fitBounds);
|
230 | };
|
231 | SebmGoogleMap.prototype._handleMapCenterChange = function () {
|
232 | var _this = this;
|
233 | var s = this._mapsWrapper.subscribeToMapEvent('center_changed').subscribe(function () {
|
234 | _this._mapsWrapper.getCenter().then(function (center) {
|
235 | _this.latitude = center.lat();
|
236 | _this.longitude = center.lng();
|
237 | _this.centerChange.emit({ lat: _this.latitude, lng: _this.longitude });
|
238 | });
|
239 | });
|
240 | this._observableSubscriptions.push(s);
|
241 | };
|
242 | SebmGoogleMap.prototype._handleBoundsChange = function () {
|
243 | var _this = this;
|
244 | var s = this._mapsWrapper.subscribeToMapEvent('bounds_changed').subscribe(function () {
|
245 | _this._mapsWrapper.getBounds().then(function (bounds) { _this.boundsChange.emit(bounds); });
|
246 | });
|
247 | this._observableSubscriptions.push(s);
|
248 | };
|
249 | SebmGoogleMap.prototype._handleMapZoomChange = function () {
|
250 | var _this = this;
|
251 | var s = this._mapsWrapper.subscribeToMapEvent('zoom_changed').subscribe(function () {
|
252 | _this._mapsWrapper.getZoom().then(function (z) {
|
253 | _this.zoom = z;
|
254 | _this.zoomChange.emit(z);
|
255 | });
|
256 | });
|
257 | this._observableSubscriptions.push(s);
|
258 | };
|
259 | SebmGoogleMap.prototype._handleIdleEvent = function () {
|
260 | var _this = this;
|
261 | var s = this._mapsWrapper.subscribeToMapEvent('idle').subscribe(function () { _this.idle.emit(void 0); });
|
262 | this._observableSubscriptions.push(s);
|
263 | };
|
264 | SebmGoogleMap.prototype._handleMapMouseEvents = function () {
|
265 | var _this = this;
|
266 | var events = [
|
267 | { name: 'click', emitter: this.mapClick },
|
268 | { name: 'rightclick', emitter: this.mapRightClick },
|
269 | ];
|
270 | events.forEach(function (e) {
|
271 | var s = _this._mapsWrapper.subscribeToMapEvent(e.name).subscribe(function (event) {
|
272 | var value = { coords: { lat: event.latLng.lat(), lng: event.latLng.lng() } };
|
273 | e.emitter.emit(value);
|
274 | });
|
275 | _this._observableSubscriptions.push(s);
|
276 | });
|
277 | };
|
278 | |
279 |
|
280 |
|
281 | SebmGoogleMap._mapOptionsAttributes = [
|
282 | 'disableDoubleClickZoom', 'scrollwheel', 'draggable', 'draggableCursor', 'draggingCursor',
|
283 | 'keyboardShortcuts', 'zoomControl', 'styles', 'streetViewControl', 'zoom', 'mapTypeControl',
|
284 | 'minZoom', 'maxZoom'
|
285 | ];
|
286 | SebmGoogleMap.decorators = [
|
287 | { type: core_1.Component, args: [{
|
288 | selector: 'sebm-google-map',
|
289 | providers: [
|
290 | google_maps_api_wrapper_1.GoogleMapsAPIWrapper, marker_manager_1.MarkerManager, info_window_manager_1.InfoWindowManager, circle_manager_1.CircleManager, polyline_manager_1.PolylineManager,
|
291 | polygon_manager_1.PolygonManager, kml_layer_manager_1.KmlLayerManager
|
292 | ],
|
293 | inputs: [
|
294 | 'longitude', 'latitude', 'zoom', 'minZoom', 'maxZoom', 'draggable: mapDraggable',
|
295 | 'disableDoubleClickZoom', 'disableDefaultUI', 'scrollwheel', 'backgroundColor', 'draggableCursor',
|
296 | 'draggingCursor', 'keyboardShortcuts', 'zoomControl', 'styles', 'usePanning', 'streetViewControl',
|
297 | 'fitBounds', 'scaleControl', 'mapTypeControl'
|
298 | ],
|
299 | outputs: [
|
300 | 'mapClick', 'mapRightClick', 'mapDblClick', 'centerChange', 'idle', 'boundsChange', 'zoomChange'
|
301 | ],
|
302 | host: { '[class.sebm-google-map-container]': 'true' },
|
303 | styles: ["\n .sebm-google-map-container-inner {\n width: inherit;\n height: inherit;\n }\n .sebm-google-map-content {\n display:none;\n }\n "],
|
304 | template: "\n <div class='sebm-google-map-container-inner'></div>\n <div class='sebm-google-map-content'>\n <ng-content></ng-content>\n </div>\n "
|
305 | },] },
|
306 | ];
|
307 |
|
308 | SebmGoogleMap.ctorParameters = function () { return [
|
309 | { type: core_1.ElementRef, },
|
310 | { type: google_maps_api_wrapper_1.GoogleMapsAPIWrapper, },
|
311 | ]; };
|
312 | return SebmGoogleMap;
|
313 | }());
|
314 | exports.SebmGoogleMap = SebmGoogleMap;
|
315 |
|
\ | No newline at end of file |