1 | import { __extends, __read, __decorate, __metadata } from 'tslib';
|
2 | import { NgZone, Injectable, EventEmitter, Input, Output, Directive, NgModule } from '@angular/core';
|
3 | import { GoogleMapsAPIWrapper, MarkerManager, InfoWindowManager, AgmCoreModule } from '@agm/core';
|
4 | import { Observable } from 'rxjs';
|
5 | import 'js-marker-clusterer';
|
6 |
|
7 | var ClusterManager = (function (_super) {
|
8 | __extends(ClusterManager, _super);
|
9 | function ClusterManager(_mapsWrapper, _zone) {
|
10 | var _this = _super.call(this, _mapsWrapper, _zone) || this;
|
11 | _this._mapsWrapper = _mapsWrapper;
|
12 | _this._zone = _zone;
|
13 | _this._clustererInstance = new Promise(function (resolver) {
|
14 | _this._resolver = resolver;
|
15 | });
|
16 | return _this;
|
17 | }
|
18 | ClusterManager.prototype.init = function (options) {
|
19 | var _this = this;
|
20 | this._mapsWrapper.getNativeMap().then(function (map) {
|
21 | var clusterer = new MarkerClusterer(map, [], options);
|
22 | _this._resolver(clusterer);
|
23 | });
|
24 | };
|
25 | ClusterManager.prototype.getClustererInstance = function () {
|
26 | return this._clustererInstance;
|
27 | };
|
28 | ClusterManager.prototype.addMarker = function (marker) {
|
29 | var clusterPromise = this.getClustererInstance();
|
30 | var markerPromise = this._mapsWrapper
|
31 | .createMarker({
|
32 | position: {
|
33 | lat: marker.latitude,
|
34 | lng: marker.longitude,
|
35 | },
|
36 | label: marker.label,
|
37 | draggable: marker.draggable,
|
38 | icon: marker.iconUrl,
|
39 | opacity: marker.opacity,
|
40 | visible: marker.visible,
|
41 | zIndex: marker.zIndex,
|
42 | title: marker.title,
|
43 | clickable: marker.clickable,
|
44 | }, false);
|
45 | Promise
|
46 | .all([clusterPromise, markerPromise])
|
47 | .then(function (_a) {
|
48 | var _b = __read(_a, 2), cluster = _b[0], marker = _b[1];
|
49 | return cluster.addMarker(marker);
|
50 | });
|
51 | this._markers.set(marker, markerPromise);
|
52 | };
|
53 | ClusterManager.prototype.deleteMarker = function (marker) {
|
54 | var _this = this;
|
55 | var m = this._markers.get(marker);
|
56 | if (m == null) {
|
57 |
|
58 | return Promise.resolve();
|
59 | }
|
60 | return m.then(function (m) {
|
61 | _this._zone.run(function () {
|
62 | m.setMap(null);
|
63 | _this.getClustererInstance().then(function (cluster) {
|
64 | cluster.removeMarker(m);
|
65 | _this._markers.delete(marker);
|
66 | });
|
67 | });
|
68 | });
|
69 | };
|
70 | ClusterManager.prototype.clearMarkers = function () {
|
71 | return this.getClustererInstance().then(function (cluster) {
|
72 | cluster.clearMarkers();
|
73 | });
|
74 | };
|
75 | ClusterManager.prototype.setGridSize = function (c) {
|
76 | this.getClustererInstance().then(function (cluster) {
|
77 | cluster.setGridSize(c.gridSize);
|
78 | });
|
79 | };
|
80 | ClusterManager.prototype.setMaxZoom = function (c) {
|
81 | this.getClustererInstance().then(function (cluster) {
|
82 | cluster.setMaxZoom(c.maxZoom);
|
83 | });
|
84 | };
|
85 | ClusterManager.prototype.setStyles = function (c) {
|
86 | this.getClustererInstance().then(function (cluster) {
|
87 | cluster.setStyles(c.styles);
|
88 | });
|
89 | };
|
90 | ClusterManager.prototype.setZoomOnClick = function (c) {
|
91 | this.getClustererInstance().then(function (cluster) {
|
92 | if (c.zoomOnClick !== undefined) {
|
93 | cluster.zoomOnClick_ = c.zoomOnClick;
|
94 | }
|
95 | });
|
96 | };
|
97 | ClusterManager.prototype.setAverageCenter = function (c) {
|
98 | this.getClustererInstance().then(function (cluster) {
|
99 | if (c.averageCenter !== undefined) {
|
100 | cluster.averageCenter_ = c.averageCenter;
|
101 | }
|
102 | });
|
103 | };
|
104 | ClusterManager.prototype.setImagePath = function (c) {
|
105 | this.getClustererInstance().then(function (cluster) {
|
106 | if (c.imagePath !== undefined) {
|
107 | cluster.imagePath_ = c.imagePath;
|
108 | }
|
109 | });
|
110 | };
|
111 | ClusterManager.prototype.setMinimumClusterSize = function (c) {
|
112 | this.getClustererInstance().then(function (cluster) {
|
113 | if (c.minimumClusterSize !== undefined) {
|
114 | cluster.minimumClusterSize_ = c.minimumClusterSize;
|
115 | }
|
116 | });
|
117 | };
|
118 | ClusterManager.prototype.setImageExtension = function (c) {
|
119 | this.getClustererInstance().then(function (cluster) {
|
120 | if (c.imageExtension !== undefined) {
|
121 | cluster.imageExtension_ = c.imageExtension;
|
122 | }
|
123 | });
|
124 | };
|
125 | ClusterManager.prototype.createClusterEventObservable = function (eventName) {
|
126 | var _this = this;
|
127 | return Observable.create(function (observer) {
|
128 | _this._zone.runOutsideAngular(function () {
|
129 | _this._clustererInstance.then(function (m) {
|
130 | m.addListener(eventName, function (e) { return _this._zone.run(function () { return observer.next(e); }); });
|
131 | });
|
132 | });
|
133 | });
|
134 | };
|
135 | ClusterManager.prototype.setCalculator = function (c) {
|
136 | this.getClustererInstance().then(function (cluster) {
|
137 | if (typeof c.calculator === 'function') {
|
138 | cluster.setCalculator(c.calculator);
|
139 | }
|
140 | });
|
141 | };
|
142 | ClusterManager.ctorParameters = function () { return [
|
143 | { type: GoogleMapsAPIWrapper },
|
144 | { type: NgZone }
|
145 | ]; };
|
146 | ClusterManager = __decorate([
|
147 | Injectable(),
|
148 | __metadata("design:paramtypes", [GoogleMapsAPIWrapper, NgZone])
|
149 | ], ClusterManager);
|
150 | return ClusterManager;
|
151 | }(MarkerManager));
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | var AgmMarkerCluster = (function () {
|
181 | function AgmMarkerCluster(_clusterManager) {
|
182 | this._clusterManager = _clusterManager;
|
183 | this.clusterClick = new EventEmitter();
|
184 | this._observableSubscriptions = [];
|
185 | }
|
186 |
|
187 | AgmMarkerCluster.prototype.ngOnDestroy = function () {
|
188 | this._clusterManager.clearMarkers();
|
189 | this._observableSubscriptions.forEach(function (s) { return s.unsubscribe(); });
|
190 | };
|
191 |
|
192 | AgmMarkerCluster.prototype.ngOnChanges = function (changes) {
|
193 | if (changes['gridSize']) {
|
194 | this._clusterManager.setGridSize(this);
|
195 | }
|
196 | if (changes['maxZoom']) {
|
197 | this._clusterManager.setMaxZoom(this);
|
198 | }
|
199 | if (changes['zoomOnClick']) {
|
200 | this._clusterManager.setZoomOnClick(this);
|
201 | }
|
202 | if (changes['averageCenter']) {
|
203 | this._clusterManager.setAverageCenter(this);
|
204 | }
|
205 | if (changes['minimumClusterSize']) {
|
206 | this._clusterManager.setMinimumClusterSize(this);
|
207 | }
|
208 | if (changes['imagePath']) {
|
209 | this._clusterManager.setImagePath(this);
|
210 | }
|
211 | if (changes['imageExtension']) {
|
212 | this._clusterManager.setImageExtension(this);
|
213 | }
|
214 | if (changes['calculator']) {
|
215 | this._clusterManager.setCalculator(this);
|
216 | }
|
217 | if (changes['styles']) {
|
218 | this._clusterManager.setStyles(this);
|
219 | }
|
220 | };
|
221 | AgmMarkerCluster.prototype._addEventListeners = function () {
|
222 | var _this = this;
|
223 | var handlers = [
|
224 | {
|
225 | name: 'clusterclick',
|
226 | handler: function () { return _this.clusterClick.emit(); },
|
227 | },
|
228 | ];
|
229 | handlers.forEach(function (obj) {
|
230 | var os = _this._clusterManager.createClusterEventObservable(obj.name).subscribe(obj.handler);
|
231 | _this._observableSubscriptions.push(os);
|
232 | });
|
233 | };
|
234 |
|
235 | AgmMarkerCluster.prototype.ngOnInit = function () {
|
236 | this._addEventListeners();
|
237 | this._clusterManager.init({
|
238 | gridSize: this.gridSize,
|
239 | maxZoom: this.maxZoom,
|
240 | zoomOnClick: this.zoomOnClick,
|
241 | averageCenter: this.averageCenter,
|
242 | minimumClusterSize: this.minimumClusterSize,
|
243 | styles: this.styles,
|
244 | imagePath: this.imagePath,
|
245 | imageExtension: this.imageExtension,
|
246 | calculator: this.calculator,
|
247 | });
|
248 | };
|
249 | AgmMarkerCluster.ctorParameters = function () { return [
|
250 | { type: ClusterManager }
|
251 | ]; };
|
252 | __decorate([
|
253 | Input(),
|
254 | __metadata("design:type", Number)
|
255 | ], AgmMarkerCluster.prototype, "gridSize", void 0);
|
256 | __decorate([
|
257 | Input(),
|
258 | __metadata("design:type", Number)
|
259 | ], AgmMarkerCluster.prototype, "maxZoom", void 0);
|
260 | __decorate([
|
261 | Input(),
|
262 | __metadata("design:type", Boolean)
|
263 | ], AgmMarkerCluster.prototype, "zoomOnClick", void 0);
|
264 | __decorate([
|
265 | Input(),
|
266 | __metadata("design:type", Boolean)
|
267 | ], AgmMarkerCluster.prototype, "averageCenter", void 0);
|
268 | __decorate([
|
269 | Input(),
|
270 | __metadata("design:type", Number)
|
271 | ], AgmMarkerCluster.prototype, "minimumClusterSize", void 0);
|
272 | __decorate([
|
273 | Input(),
|
274 | __metadata("design:type", Array)
|
275 | ], AgmMarkerCluster.prototype, "styles", void 0);
|
276 | __decorate([
|
277 | Input(),
|
278 | __metadata("design:type", Function)
|
279 | ], AgmMarkerCluster.prototype, "calculator", void 0);
|
280 | __decorate([
|
281 | Input(),
|
282 | __metadata("design:type", String)
|
283 | ], AgmMarkerCluster.prototype, "imagePath", void 0);
|
284 | __decorate([
|
285 | Input(),
|
286 | __metadata("design:type", String)
|
287 | ], AgmMarkerCluster.prototype, "imageExtension", void 0);
|
288 | __decorate([
|
289 | Output(),
|
290 | __metadata("design:type", EventEmitter)
|
291 | ], AgmMarkerCluster.prototype, "clusterClick", void 0);
|
292 | AgmMarkerCluster = __decorate([
|
293 | Directive({
|
294 | selector: 'agm-marker-cluster',
|
295 | providers: [
|
296 | ClusterManager,
|
297 | { provide: MarkerManager, useExisting: ClusterManager },
|
298 | InfoWindowManager,
|
299 | ],
|
300 | }),
|
301 | __metadata("design:paramtypes", [ClusterManager])
|
302 | ], AgmMarkerCluster);
|
303 | return AgmMarkerCluster;
|
304 | }());
|
305 |
|
306 | var AgmJsMarkerClustererModule = (function () {
|
307 | function AgmJsMarkerClustererModule() {
|
308 | }
|
309 | AgmJsMarkerClustererModule = __decorate([
|
310 | NgModule({
|
311 | imports: [AgmCoreModule],
|
312 | declarations: [AgmMarkerCluster],
|
313 | exports: [AgmMarkerCluster],
|
314 | })
|
315 | ], AgmJsMarkerClustererModule);
|
316 | return AgmJsMarkerClustererModule;
|
317 | }());
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 | export { AgmJsMarkerClustererModule, AgmMarkerCluster, ClusterManager };
|
326 |
|