@react-google-maps/marker-clusterer 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/umd.js ADDED
@@ -0,0 +1,948 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.markerClusterer = {}));
5
+ }(this, (function (exports) { 'use strict';
6
+
7
+ var ClusterIcon = /** @class */ (function () {
8
+ function ClusterIcon(cluster, styles) {
9
+ cluster.getClusterer().extend(ClusterIcon, google.maps.OverlayView);
10
+ this.cluster = cluster;
11
+ this.className = this.cluster.getClusterer().getClusterClass();
12
+ this.styles = styles;
13
+ this.center = undefined;
14
+ this.div = null;
15
+ this.sums = null;
16
+ this.visible = false;
17
+ this.boundsChangedListener = null;
18
+ this.url = '';
19
+ this.height = 0;
20
+ this.width = 0;
21
+ this.anchorText = [0, 0];
22
+ this.anchorIcon = [0, 0];
23
+ this.textColor = 'black';
24
+ this.textSize = 11;
25
+ this.textDecoration = 'none';
26
+ this.fontWeight = 'bold';
27
+ this.fontStyle = 'normal';
28
+ this.fontFamily = 'Arial,sans-serif';
29
+ this.backgroundPosition = '0 0';
30
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
31
+ // @ts-ignore
32
+ this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
33
+ }
34
+ ClusterIcon.prototype.onAdd = function () {
35
+ var _this = this;
36
+ var cMouseDownInCluster;
37
+ var cDraggingMapByCluster;
38
+ this.div = document.createElement('div');
39
+ this.div.className = this.className;
40
+ if (this.visible) {
41
+ this.show();
42
+ }
43
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
44
+ // @ts-ignore
45
+ this.getPanes().overlayMouseTarget.appendChild(this.div);
46
+ // Fix for Issue 157
47
+ this.boundsChangedListener = google.maps.event.addListener(
48
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
49
+ // @ts-ignore
50
+ this.getMap(), 'boundschanged', function boundsChanged() {
51
+ cDraggingMapByCluster = cMouseDownInCluster;
52
+ });
53
+ google.maps.event.addDomListener(this.div, 'mousedown', function onMouseDown() {
54
+ cMouseDownInCluster = true;
55
+ cDraggingMapByCluster = false;
56
+ });
57
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
58
+ google.maps.event.addDomListener(this.div, 'click',
59
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
60
+ function (event) {
61
+ cMouseDownInCluster = false;
62
+ if (!cDraggingMapByCluster) {
63
+ var markerClusterer_1 = _this.cluster.getClusterer();
64
+ /**
65
+ * This event is fired when a cluster marker is clicked.
66
+ * @name MarkerClusterer#click
67
+ * @param {Cluster} c The cluster that was clicked.
68
+ * @event
69
+ */
70
+ google.maps.event.trigger(markerClusterer_1, 'click', _this.cluster);
71
+ google.maps.event.trigger(markerClusterer_1, 'clusterclick', _this.cluster); // deprecated name
72
+ // The default click handler follows. Disable it by setting
73
+ // the zoomOnClick property to false.
74
+ if (markerClusterer_1.getZoomOnClick()) {
75
+ // Zoom into the cluster.
76
+ var maxZoom_1 = markerClusterer_1.getMaxZoom();
77
+ var bounds_1 = _this.cluster.getBounds();
78
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
79
+ // @ts-ignore
80
+ markerClusterer_1.getMap().fitBounds(bounds_1);
81
+ // There is a fix for Issue 170 here:
82
+ setTimeout(function timeout() {
83
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
84
+ // @ts-ignore
85
+ markerClusterer_1.getMap().fitBounds(bounds_1);
86
+ // Don't zoom beyond the max zoom level
87
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
88
+ // @ts-ignore
89
+ if (maxZoom_1 !== null && markerClusterer_1.getMap().getZoom() > maxZoom_1) {
90
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
91
+ // @ts-ignore
92
+ markerClusterer_1.getMap().setZoom(maxZoom_1 + 1);
93
+ }
94
+ }, 100);
95
+ }
96
+ // Prevent event propagation to the map:
97
+ event.cancelBubble = true;
98
+ if (event.stopPropagation) {
99
+ event.stopPropagation();
100
+ }
101
+ }
102
+ });
103
+ google.maps.event.addDomListener(this.div, 'mouseover',
104
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
105
+ function () {
106
+ /**
107
+ * This event is fired when the mouse moves over a cluster marker.
108
+ * @name MarkerClusterer#mouseover
109
+ * @param {Cluster} c The cluster that the mouse moved over.
110
+ * @event
111
+ */
112
+ google.maps.event.trigger(_this.cluster.getClusterer(), 'mouseover', _this.cluster);
113
+ });
114
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
115
+ google.maps.event.addDomListener(this.div, 'mouseout',
116
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
117
+ function () {
118
+ /**
119
+ * This event is fired when the mouse moves out of a cluster marker.
120
+ * @name MarkerClusterer#mouseout
121
+ * @param {Cluster} c The cluster that the mouse moved out of.
122
+ * @event
123
+ */
124
+ google.maps.event.trigger(_this.cluster.getClusterer(), 'mouseout', _this.cluster);
125
+ });
126
+ };
127
+ ClusterIcon.prototype.onRemove = function () {
128
+ if (this.div && this.div.parentNode) {
129
+ this.hide();
130
+ if (this.boundsChangedListener !== null) {
131
+ google.maps.event.removeListener(this.boundsChangedListener);
132
+ }
133
+ google.maps.event.clearInstanceListeners(this.div);
134
+ this.div.parentNode.removeChild(this.div);
135
+ this.div = null;
136
+ }
137
+ };
138
+ ClusterIcon.prototype.draw = function () {
139
+ if (this.visible && this.div !== null && this.center) {
140
+ var _a = this.getPosFromLatLng(this.center), x = _a.x, y = _a.y;
141
+ this.div.style.top = y + 'px';
142
+ this.div.style.left = x + 'px';
143
+ }
144
+ };
145
+ ClusterIcon.prototype.hide = function () {
146
+ if (this.div) {
147
+ this.div.style.display = 'none';
148
+ }
149
+ this.visible = false;
150
+ };
151
+ ClusterIcon.prototype.show = function () {
152
+ if (this.div && this.center) {
153
+ var img = '', divTitle = '';
154
+ // NOTE: values must be specified in px units
155
+ var bp = this.backgroundPosition.split(' ');
156
+ var spriteH = parseInt(bp[0].replace(/^\s+|\s+$/g, ''), 10);
157
+ var spriteV = parseInt(bp[1].replace(/^\s+|\s+$/g, ''), 10);
158
+ var pos = this.getPosFromLatLng(this.center);
159
+ if (this.sums === null || typeof this.sums.title === 'undefined' || this.sums.title === '') {
160
+ divTitle = this.cluster.getClusterer().getTitle();
161
+ }
162
+ else {
163
+ divTitle = this.sums.title;
164
+ }
165
+ this.div.style.cssText = this.createCss(pos);
166
+ img =
167
+ "<img alt='" +
168
+ divTitle +
169
+ "' src='" +
170
+ this.url +
171
+ "' style='position: absolute; top: " +
172
+ spriteV +
173
+ 'px; left: ' +
174
+ spriteH +
175
+ 'px; ';
176
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
177
+ //@ts-ignore
178
+ if (!this.cluster.getClusterer().enableRetinaIcons) {
179
+ img +=
180
+ 'clip: rect(' +
181
+ -1 * spriteV +
182
+ 'px, ' +
183
+ (-1 * spriteH + this.width) +
184
+ 'px, ' +
185
+ (-1 * spriteV + this.height) +
186
+ 'px, ' +
187
+ -1 * spriteH +
188
+ 'px);';
189
+ }
190
+ img += "'>";
191
+ this.div.innerHTML =
192
+ img +
193
+ "<div style='" +
194
+ 'position: absolute;' +
195
+ 'top: ' +
196
+ this.anchorText[0] +
197
+ 'px;' +
198
+ 'left: ' +
199
+ this.anchorText[1] +
200
+ 'px;' +
201
+ 'color: ' +
202
+ this.textColor +
203
+ ';' +
204
+ 'font-size: ' +
205
+ this.textSize +
206
+ 'px;' +
207
+ 'font-family: ' +
208
+ this.fontFamily +
209
+ ';' +
210
+ 'font-weight: ' +
211
+ this.fontWeight +
212
+ ';' +
213
+ 'font-style: ' +
214
+ this.fontStyle +
215
+ ';' +
216
+ 'text-decoration: ' +
217
+ this.textDecoration +
218
+ ';' +
219
+ 'text-align: center;' +
220
+ 'width: ' +
221
+ this.width +
222
+ 'px;' +
223
+ 'line-height:' +
224
+ this.height +
225
+ 'px;' +
226
+ "'>" +
227
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
228
+ // @ts-ignore
229
+ this.sums.text +
230
+ '</div>';
231
+ this.div.title = divTitle;
232
+ this.div.style.display = '';
233
+ }
234
+ this.visible = true;
235
+ };
236
+ ClusterIcon.prototype.useStyle = function (sums) {
237
+ this.sums = sums;
238
+ var style = this.styles[Math.min(this.styles.length - 1, Math.max(0, sums.index - 1))];
239
+ this.url = style.url;
240
+ this.height = style.height;
241
+ this.width = style.width;
242
+ if (style.className)
243
+ this.className = this.className + " " + style.className;
244
+ this.anchorText = style.anchorText || [0, 0];
245
+ this.anchorIcon = style.anchorIcon || [this.height / 2, this.width / 2];
246
+ this.textColor = style.textColor || 'black';
247
+ this.textSize = style.textSize || 11;
248
+ this.textDecoration = style.textDecoration || 'none';
249
+ this.fontWeight = style.fontWeight || 'bold';
250
+ this.fontStyle = style.fontStyle || 'normal';
251
+ this.fontFamily = style.fontFamily || 'Arial,sans-serif';
252
+ this.backgroundPosition = style.backgroundPosition || '0 0';
253
+ };
254
+ ClusterIcon.prototype.setCenter = function (center) {
255
+ this.center = center;
256
+ };
257
+ ClusterIcon.prototype.createCss = function (pos) {
258
+ var style = [];
259
+ style.push('cursor: pointer;');
260
+ style.push('position: absolute; top: ' + pos.y + 'px; left: ' + pos.x + 'px;');
261
+ style.push('width: ' + this.width + 'px; height: ' + this.height + 'px;');
262
+ return style.join('');
263
+ };
264
+ ClusterIcon.prototype.getPosFromLatLng = function (latlng) {
265
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
266
+ // @ts-ignore
267
+ var pos = this.getProjection().fromLatLngToDivPixel(latlng);
268
+ pos.x -= this.anchorIcon[1];
269
+ pos.y -= this.anchorIcon[0];
270
+ // pos.x = pos.x
271
+ // pos.y = pos.y
272
+ return pos;
273
+ };
274
+ return ClusterIcon;
275
+ }());
276
+
277
+ var Cluster = /** @class */ (function () {
278
+ function Cluster(markerClusterer) {
279
+ this.markerClusterer = markerClusterer;
280
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
281
+ // @ts-ignore
282
+ this.map = this.markerClusterer.getMap();
283
+ this.gridSize = this.markerClusterer.getGridSize();
284
+ this.minClusterSize = this.markerClusterer.getMinimumClusterSize();
285
+ this.averageCenter = this.markerClusterer.getAverageCenter();
286
+ this.markers = [];
287
+ this.center = undefined;
288
+ this.bounds = null;
289
+ this.clusterIcon = new ClusterIcon(this, this.markerClusterer.getStyles());
290
+ }
291
+ Cluster.prototype.getSize = function () {
292
+ return this.markers.length;
293
+ };
294
+ Cluster.prototype.getMarkers = function () {
295
+ return this.markers;
296
+ };
297
+ Cluster.prototype.getCenter = function () {
298
+ return this.center;
299
+ };
300
+ Cluster.prototype.getMap = function () {
301
+ return this.map;
302
+ };
303
+ Cluster.prototype.getClusterer = function () {
304
+ return this.markerClusterer;
305
+ };
306
+ Cluster.prototype.getBounds = function () {
307
+ var bounds = new google.maps.LatLngBounds(this.center, this.center);
308
+ var markers = this.getMarkers();
309
+ for (var i = 0; i < markers.length; i++) {
310
+ var position = markers[i].getPosition();
311
+ if (position) {
312
+ bounds.extend(position);
313
+ }
314
+ }
315
+ return bounds;
316
+ };
317
+ Cluster.prototype.remove = function () {
318
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
319
+ // @ts-ignore
320
+ this.clusterIcon.setMap(null);
321
+ this.markers = [];
322
+ // @ts-ignore
323
+ delete this.markers;
324
+ };
325
+ Cluster.prototype.addMarker = function (marker) {
326
+ if (this.isMarkerAlreadyAdded(marker)) {
327
+ return false;
328
+ }
329
+ if (!this.center) {
330
+ var position = marker.getPosition();
331
+ if (position) {
332
+ this.center = position;
333
+ this.calculateBounds();
334
+ }
335
+ }
336
+ else {
337
+ if (this.averageCenter) {
338
+ var position = marker.getPosition();
339
+ if (position) {
340
+ var length_1 = this.markers.length + 1;
341
+ this.center = new google.maps.LatLng((this.center.lat() * (length_1 - 1) + position.lat()) / length_1, (this.center.lng() * (length_1 - 1) + position.lng()) / length_1);
342
+ this.calculateBounds();
343
+ }
344
+ }
345
+ }
346
+ marker.isAdded = true;
347
+ this.markers.push(marker);
348
+ var mCount = this.markers.length;
349
+ var maxZoom = this.markerClusterer.getMaxZoom();
350
+ if (maxZoom !== null && this.map.getZoom() > maxZoom) {
351
+ // Zoomed in past max zoom, so show the marker.
352
+ if (marker.getMap() !== this.map) {
353
+ marker.setMap(this.map);
354
+ }
355
+ }
356
+ else if (mCount < this.minClusterSize) {
357
+ // Min cluster size not reached so show the marker.
358
+ if (marker.getMap() !== this.map) {
359
+ marker.setMap(this.map);
360
+ }
361
+ }
362
+ else if (mCount === this.minClusterSize) {
363
+ // Hide the markers that were showing.
364
+ for (var i = 0; i < mCount; i++) {
365
+ this.markers[i].setMap(null);
366
+ }
367
+ }
368
+ else {
369
+ marker.setMap(null);
370
+ }
371
+ return true;
372
+ };
373
+ Cluster.prototype.isMarkerInClusterBounds = function (marker) {
374
+ if (this.bounds !== null) {
375
+ var position = marker.getPosition();
376
+ if (position) {
377
+ return this.bounds.contains(position);
378
+ }
379
+ }
380
+ return false;
381
+ };
382
+ Cluster.prototype.calculateBounds = function () {
383
+ this.bounds = this.markerClusterer.getExtendedBounds(new google.maps.LatLngBounds(this.center, this.center));
384
+ };
385
+ Cluster.prototype.updateIcon = function () {
386
+ var mCount = this.markers.length;
387
+ var maxZoom = this.markerClusterer.getMaxZoom();
388
+ if (maxZoom !== null && this.map.getZoom() > maxZoom) {
389
+ this.clusterIcon.hide();
390
+ return;
391
+ }
392
+ if (mCount < this.minClusterSize) {
393
+ // Min cluster size not yet reached.
394
+ this.clusterIcon.hide();
395
+ return;
396
+ }
397
+ if (this.center) {
398
+ this.clusterIcon.setCenter(this.center);
399
+ }
400
+ this.clusterIcon.useStyle(this.markerClusterer.getCalculator()(this.markers, this.markerClusterer.getStyles().length));
401
+ this.clusterIcon.show();
402
+ };
403
+ Cluster.prototype.isMarkerAlreadyAdded = function (marker) {
404
+ if (this.markers.includes) {
405
+ return this.markers.includes(marker);
406
+ }
407
+ else {
408
+ for (var i = 0; i < this.markers.length; i++) {
409
+ if (marker === this.markers[i]) {
410
+ return true;
411
+ }
412
+ }
413
+ }
414
+ return false;
415
+ };
416
+ return Cluster;
417
+ }());
418
+
419
+ /* global google */
420
+ /**
421
+ * Supports up to 9007199254740991 (Number.MAX_SAFE_INTEGER) markers
422
+ * which is not a problem as max array length is 4294967296 (2**32)
423
+ */
424
+ var CALCULATOR = function CALCULATOR(markers, numStyles) {
425
+ var count = markers.length;
426
+ var numberOfDigits = count.toString().length;
427
+ var index = Math.min(numberOfDigits, numStyles);
428
+ return {
429
+ text: count.toString(),
430
+ index: index,
431
+ title: '',
432
+ };
433
+ };
434
+ var BATCH_SIZE = 2000;
435
+ var BATCH_SIZE_IE = 500;
436
+ var IMAGE_PATH = 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m';
437
+ var IMAGE_EXTENSION = 'png';
438
+ var IMAGE_SIZES = [53, 56, 66, 78, 90];
439
+ var CLUSTERER_CLASS = 'cluster';
440
+ var Clusterer = /** @class */ (function () {
441
+ function Clusterer(map, optMarkers, optOptions) {
442
+ if (optMarkers === void 0) { optMarkers = []; }
443
+ if (optOptions === void 0) { optOptions = {}; }
444
+ this.extend(Clusterer, google.maps.OverlayView);
445
+ this.markers = [];
446
+ this.clusters = [];
447
+ this.listeners = [];
448
+ this.activeMap = null;
449
+ this.ready = false;
450
+ this.gridSize = optOptions.gridSize || 60;
451
+ this.minClusterSize = optOptions.minimumClusterSize || 2;
452
+ this.maxZoom = optOptions.maxZoom || null;
453
+ this.styles = optOptions.styles || [];
454
+ this.title = optOptions.title || '';
455
+ this.zoomOnClick = true;
456
+ if (optOptions.zoomOnClick !== undefined) {
457
+ this.zoomOnClick = optOptions.zoomOnClick;
458
+ }
459
+ this.averageCenter = false;
460
+ if (optOptions.averageCenter !== undefined) {
461
+ this.averageCenter = optOptions.averageCenter;
462
+ }
463
+ this.ignoreHidden = false;
464
+ if (optOptions.ignoreHidden !== undefined) {
465
+ this.ignoreHidden = optOptions.ignoreHidden;
466
+ }
467
+ this.enableRetinaIcons = false;
468
+ if (optOptions.enableRetinaIcons !== undefined) {
469
+ this.enableRetinaIcons = optOptions.enableRetinaIcons;
470
+ }
471
+ this.imagePath = optOptions.imagePath || IMAGE_PATH;
472
+ this.imageExtension = optOptions.imageExtension || IMAGE_EXTENSION;
473
+ this.imageSizes = optOptions.imageSizes || IMAGE_SIZES;
474
+ this.calculator = optOptions.calculator || CALCULATOR;
475
+ this.batchSize = optOptions.batchSize || BATCH_SIZE;
476
+ this.batchSizeIE = optOptions.batchSizeIE || BATCH_SIZE_IE;
477
+ this.clusterClass = optOptions.clusterClass || CLUSTERER_CLASS;
478
+ if (navigator.userAgent.toLowerCase().indexOf('msie') !== -1) {
479
+ // Try to avoid IE timeout when processing a huge number of markers:
480
+ this.batchSize = this.batchSizeIE;
481
+ }
482
+ this.timerRefStatic = null;
483
+ this.setupStyles();
484
+ this.addMarkers(optMarkers, true);
485
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
486
+ // @ts-ignore
487
+ this.setMap(map); // Note: this causes onAdd to be called
488
+ }
489
+ Clusterer.prototype.onAdd = function () {
490
+ var _this = this;
491
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
492
+ // @ts-ignore
493
+ this.activeMap = this.getMap();
494
+ this.ready = true;
495
+ this.repaint();
496
+ // Add the map event listeners
497
+ this.listeners = [
498
+ google.maps.event.addListener(
499
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
500
+ // @ts-ignore
501
+ this.getMap(), 'zoom_changed',
502
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
503
+ function () {
504
+ _this.resetViewport(false);
505
+ // Workaround for this Google bug: when map is at level 0 and "-" of
506
+ // zoom slider is clicked, a "zoom_changed" event is fired even though
507
+ // the map doesn't zoom out any further. In this situation, no "idle"
508
+ // event is triggered so the cluster markers that have been removed
509
+ // do not get redrawn. Same goes for a zoom in at maxZoom.
510
+ if (
511
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
512
+ // @ts-ignore
513
+ _this.getMap().getZoom() === (_this.get('minZoom') || 0) ||
514
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
515
+ // @ts-ignore
516
+ _this.getMap().getZoom() === _this.get('maxZoom')) {
517
+ google.maps.event.trigger(_this, 'idle');
518
+ }
519
+ }),
520
+ google.maps.event.addListener(
521
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
522
+ // @ts-ignore
523
+ this.getMap(), 'idle',
524
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
525
+ function () {
526
+ _this.redraw();
527
+ }),
528
+ ];
529
+ };
530
+ // eslint-disable-next-line @getify/proper-arrows/this
531
+ Clusterer.prototype.onRemove = function () {
532
+ // Put all the managed markers back on the map:
533
+ for (var i = 0; i < this.markers.length; i++) {
534
+ if (this.markers[i].getMap() !== this.activeMap) {
535
+ this.markers[i].setMap(this.activeMap);
536
+ }
537
+ }
538
+ // Remove all clusters:
539
+ for (var i = 0; i < this.clusters.length; i++) {
540
+ this.clusters[i].remove();
541
+ }
542
+ this.clusters = [];
543
+ // Remove map event listeners:
544
+ for (var i = 0; i < this.listeners.length; i++) {
545
+ google.maps.event.removeListener(this.listeners[i]);
546
+ }
547
+ this.listeners = [];
548
+ this.activeMap = null;
549
+ this.ready = false;
550
+ };
551
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
552
+ Clusterer.prototype.draw = function () { };
553
+ Clusterer.prototype.setupStyles = function () {
554
+ if (this.styles.length > 0) {
555
+ return;
556
+ }
557
+ for (var i = 0; i < this.imageSizes.length; i++) {
558
+ this.styles.push({
559
+ url: this.imagePath + (i + 1) + '.' + this.imageExtension,
560
+ height: this.imageSizes[i],
561
+ width: this.imageSizes[i],
562
+ });
563
+ }
564
+ };
565
+ Clusterer.prototype.fitMapToMarkers = function () {
566
+ var markers = this.getMarkers();
567
+ var bounds = new google.maps.LatLngBounds();
568
+ for (var i = 0; i < markers.length; i++) {
569
+ var position = markers[i].getPosition();
570
+ if (position) {
571
+ bounds.extend(position);
572
+ }
573
+ }
574
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
575
+ // @ts-ignore
576
+ this.getMap().fitBounds(bounds);
577
+ };
578
+ Clusterer.prototype.getGridSize = function () {
579
+ return this.gridSize;
580
+ };
581
+ Clusterer.prototype.setGridSize = function (gridSize) {
582
+ this.gridSize = gridSize;
583
+ };
584
+ Clusterer.prototype.getMinimumClusterSize = function () {
585
+ return this.minClusterSize;
586
+ };
587
+ Clusterer.prototype.setMinimumClusterSize = function (minimumClusterSize) {
588
+ this.minClusterSize = minimumClusterSize;
589
+ };
590
+ Clusterer.prototype.getMaxZoom = function () {
591
+ return this.maxZoom;
592
+ };
593
+ Clusterer.prototype.setMaxZoom = function (maxZoom) {
594
+ this.maxZoom = maxZoom;
595
+ };
596
+ Clusterer.prototype.getStyles = function () {
597
+ return this.styles;
598
+ };
599
+ Clusterer.prototype.setStyles = function (styles) {
600
+ this.styles = styles;
601
+ };
602
+ Clusterer.prototype.getTitle = function () {
603
+ return this.title;
604
+ };
605
+ Clusterer.prototype.setTitle = function (title) {
606
+ this.title = title;
607
+ };
608
+ Clusterer.prototype.getZoomOnClick = function () {
609
+ return this.zoomOnClick;
610
+ };
611
+ Clusterer.prototype.setZoomOnClick = function (zoomOnClick) {
612
+ this.zoomOnClick = zoomOnClick;
613
+ };
614
+ Clusterer.prototype.getAverageCenter = function () {
615
+ return this.averageCenter;
616
+ };
617
+ Clusterer.prototype.setAverageCenter = function (averageCenter) {
618
+ this.averageCenter = averageCenter;
619
+ };
620
+ Clusterer.prototype.getIgnoreHidden = function () {
621
+ return this.ignoreHidden;
622
+ };
623
+ Clusterer.prototype.setIgnoreHidden = function (ignoreHidden) {
624
+ this.ignoreHidden = ignoreHidden;
625
+ };
626
+ Clusterer.prototype.getEnableRetinaIcons = function () {
627
+ return this.enableRetinaIcons;
628
+ };
629
+ Clusterer.prototype.setEnableRetinaIcons = function (enableRetinaIcons) {
630
+ this.enableRetinaIcons = enableRetinaIcons;
631
+ };
632
+ Clusterer.prototype.getImageExtension = function () {
633
+ return this.imageExtension;
634
+ };
635
+ Clusterer.prototype.setImageExtension = function (imageExtension) {
636
+ this.imageExtension = imageExtension;
637
+ };
638
+ Clusterer.prototype.getImagePath = function () {
639
+ return this.imagePath;
640
+ };
641
+ Clusterer.prototype.setImagePath = function (imagePath) {
642
+ this.imagePath = imagePath;
643
+ };
644
+ Clusterer.prototype.getImageSizes = function () {
645
+ return this.imageSizes;
646
+ };
647
+ Clusterer.prototype.setImageSizes = function (imageSizes) {
648
+ this.imageSizes = imageSizes;
649
+ };
650
+ Clusterer.prototype.getCalculator = function () {
651
+ return this.calculator;
652
+ };
653
+ Clusterer.prototype.setCalculator = function (calculator) {
654
+ this.calculator = calculator;
655
+ };
656
+ Clusterer.prototype.getBatchSizeIE = function () {
657
+ return this.batchSizeIE;
658
+ };
659
+ Clusterer.prototype.setBatchSizeIE = function (batchSizeIE) {
660
+ this.batchSizeIE = batchSizeIE;
661
+ };
662
+ Clusterer.prototype.getClusterClass = function () {
663
+ return this.clusterClass;
664
+ };
665
+ Clusterer.prototype.setClusterClass = function (clusterClass) {
666
+ this.clusterClass = clusterClass;
667
+ };
668
+ Clusterer.prototype.getMarkers = function () {
669
+ return this.markers;
670
+ };
671
+ Clusterer.prototype.getTotalMarkers = function () {
672
+ return this.markers.length;
673
+ };
674
+ Clusterer.prototype.getClusters = function () {
675
+ return this.clusters;
676
+ };
677
+ Clusterer.prototype.getTotalClusters = function () {
678
+ return this.clusters.length;
679
+ };
680
+ Clusterer.prototype.addMarker = function (marker, optNoDraw) {
681
+ this.pushMarkerTo(marker);
682
+ if (!optNoDraw) {
683
+ this.redraw();
684
+ }
685
+ };
686
+ Clusterer.prototype.addMarkers = function (markers, optNoDraw) {
687
+ for (var key in markers) {
688
+ if (markers.hasOwnProperty(key)) {
689
+ this.pushMarkerTo(markers[key]);
690
+ }
691
+ }
692
+ if (!optNoDraw) {
693
+ this.redraw();
694
+ }
695
+ };
696
+ Clusterer.prototype.pushMarkerTo = function (marker) {
697
+ var _this = this;
698
+ // If the marker is draggable add a listener so we can update the clusters on the dragend:
699
+ if (marker.getDraggable()) {
700
+ // eslint-disable-next-line @getify/proper-arrows/name, @getify/proper-arrows/this
701
+ google.maps.event.addListener(marker, 'dragend', function () {
702
+ if (_this.ready) {
703
+ marker.isAdded = false;
704
+ _this.repaint();
705
+ }
706
+ });
707
+ }
708
+ marker.isAdded = false;
709
+ this.markers.push(marker);
710
+ };
711
+ Clusterer.prototype.removeMarker_ = function (marker) {
712
+ var index = -1;
713
+ if (this.markers.indexOf) {
714
+ index = this.markers.indexOf(marker);
715
+ }
716
+ else {
717
+ for (var i = 0; i < this.markers.length; i++) {
718
+ if (marker === this.markers[i]) {
719
+ index = i;
720
+ break;
721
+ }
722
+ }
723
+ }
724
+ if (index === -1) {
725
+ // Marker is not in our list of markers, so do nothing:
726
+ return false;
727
+ }
728
+ marker.setMap(null);
729
+ this.markers.splice(index, 1); // Remove the marker from the list of managed markers
730
+ return true;
731
+ };
732
+ Clusterer.prototype.removeMarker = function (marker, optNoDraw) {
733
+ var removed = this.removeMarker_(marker);
734
+ if (!optNoDraw && removed) {
735
+ this.repaint();
736
+ }
737
+ return removed;
738
+ };
739
+ Clusterer.prototype.removeMarkers = function (markers, optNoDraw) {
740
+ var removed = false;
741
+ for (var i = 0; i < markers.length; i++) {
742
+ removed = removed || this.removeMarker_(markers[i]);
743
+ }
744
+ if (!optNoDraw && removed) {
745
+ this.repaint();
746
+ }
747
+ return removed;
748
+ };
749
+ Clusterer.prototype.clearMarkers = function () {
750
+ this.resetViewport(true);
751
+ this.markers = [];
752
+ };
753
+ Clusterer.prototype.repaint = function () {
754
+ var oldClusters = this.clusters.slice();
755
+ this.clusters = [];
756
+ this.resetViewport(false);
757
+ this.redraw();
758
+ // Remove the old clusters.
759
+ // Do it in a timeout to prevent blinking effect.
760
+ setTimeout(function timeout() {
761
+ for (var i = 0; i < oldClusters.length; i++) {
762
+ oldClusters[i].remove();
763
+ }
764
+ }, 0);
765
+ };
766
+ Clusterer.prototype.getExtendedBounds = function (bounds) {
767
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
768
+ // @ts-ignore
769
+ var projection = this.getProjection();
770
+ // Convert the points to pixels and the extend out by the grid size.
771
+ var trPix = projection.fromLatLngToDivPixel(
772
+ // Turn the bounds into latlng.
773
+ new google.maps.LatLng(bounds.getNorthEast().lat(), bounds.getNorthEast().lng()));
774
+ trPix.x += this.gridSize;
775
+ trPix.y -= this.gridSize;
776
+ var blPix = projection.fromLatLngToDivPixel(
777
+ // Turn the bounds into latlng.
778
+ new google.maps.LatLng(bounds.getSouthWest().lat(), bounds.getSouthWest().lng()));
779
+ blPix.x -= this.gridSize;
780
+ blPix.y += this.gridSize;
781
+ // Extend the bounds to contain the new bounds.
782
+ bounds.extend(
783
+ // Convert the pixel points back to LatLng nw
784
+ projection.fromDivPixelToLatLng(trPix));
785
+ bounds.extend(
786
+ // Convert the pixel points back to LatLng sw
787
+ projection.fromDivPixelToLatLng(blPix));
788
+ return bounds;
789
+ };
790
+ Clusterer.prototype.redraw = function () {
791
+ // Redraws all the clusters.
792
+ this.createClusters(0);
793
+ };
794
+ Clusterer.prototype.resetViewport = function (optHide) {
795
+ // Remove all the clusters
796
+ for (var i = 0; i < this.clusters.length; i++) {
797
+ this.clusters[i].remove();
798
+ }
799
+ this.clusters = [];
800
+ // Reset the markers to not be added and to be removed from the map.
801
+ for (var i = 0; i < this.markers.length; i++) {
802
+ var marker = this.markers[i];
803
+ marker.isAdded = false;
804
+ if (optHide) {
805
+ marker.setMap(null);
806
+ }
807
+ }
808
+ };
809
+ Clusterer.prototype.distanceBetweenPoints = function (p1, p2) {
810
+ var R = 6371; // Radius of the Earth in km
811
+ var dLat = ((p2.lat() - p1.lat()) * Math.PI) / 180;
812
+ var dLon = ((p2.lng() - p1.lng()) * Math.PI) / 180;
813
+ var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
814
+ Math.cos((p1.lat() * Math.PI) / 180) *
815
+ Math.cos((p2.lat() * Math.PI) / 180) *
816
+ Math.sin(dLon / 2) *
817
+ Math.sin(dLon / 2);
818
+ return R * (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
819
+ };
820
+ Clusterer.prototype.isMarkerInBounds = function (marker, bounds) {
821
+ var position = marker.getPosition();
822
+ if (position) {
823
+ return bounds.contains(position);
824
+ }
825
+ return false;
826
+ };
827
+ Clusterer.prototype.addToClosestCluster = function (marker) {
828
+ var cluster;
829
+ var distance = 40000; // Some large number
830
+ var clusterToAddTo = null;
831
+ for (var i = 0; i < this.clusters.length; i++) {
832
+ cluster = this.clusters[i];
833
+ var center = cluster.getCenter();
834
+ var position = marker.getPosition();
835
+ if (center && position) {
836
+ var d = this.distanceBetweenPoints(center, position);
837
+ if (d < distance) {
838
+ distance = d;
839
+ clusterToAddTo = cluster;
840
+ }
841
+ }
842
+ }
843
+ if (clusterToAddTo && clusterToAddTo.isMarkerInClusterBounds(marker)) {
844
+ clusterToAddTo.addMarker(marker);
845
+ }
846
+ else {
847
+ cluster = new Cluster(this);
848
+ cluster.addMarker(marker);
849
+ this.clusters.push(cluster);
850
+ }
851
+ };
852
+ Clusterer.prototype.createClusters = function (iFirst) {
853
+ var _this = this;
854
+ if (!this.ready) {
855
+ return;
856
+ }
857
+ // Cancel previous batch processing if we're working on the first batch:
858
+ if (iFirst === 0) {
859
+ /**
860
+ * This event is fired when the <code>Clusterer</code> begins
861
+ * clustering markers.
862
+ * @name Clusterer#clusteringbegin
863
+ * @param {Clusterer} mc The Clusterer whose markers are being clustered.
864
+ * @event
865
+ */
866
+ google.maps.event.trigger(this, 'clusteringbegin', this);
867
+ if (this.timerRefStatic !== null) {
868
+ window.clearTimeout(this.timerRefStatic);
869
+ // @ts-ignore
870
+ delete this.timerRefStatic;
871
+ }
872
+ }
873
+ // Get our current map view bounds.
874
+ // Create a new bounds object so we don't affect the map.
875
+ //
876
+ // See Comments 9 & 11 on Issue 3651 relating to this workaround for a Google Maps bug:
877
+ var mapBounds =
878
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
879
+ // @ts-ignore
880
+ this.getMap().getZoom() > 3
881
+ ? new google.maps.LatLngBounds(
882
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
883
+ // @ts-ignore
884
+ this.getMap()
885
+ .getBounds()
886
+ .getSouthWest(),
887
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
888
+ // @ts-ignore
889
+ this.getMap()
890
+ .getBounds()
891
+ .getNorthEast())
892
+ : new google.maps.LatLngBounds(new google.maps.LatLng(85.02070771743472, -178.48388434375), new google.maps.LatLng(-85.08136444384544, 178.00048865625));
893
+ var bounds = this.getExtendedBounds(mapBounds);
894
+ var iLast = Math.min(iFirst + this.batchSize, this.markers.length);
895
+ for (var i = iFirst; i < iLast; i++) {
896
+ var marker = this.markers[i];
897
+ if (!marker.isAdded && this.isMarkerInBounds(marker, bounds)) {
898
+ if (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible())) {
899
+ this.addToClosestCluster(marker);
900
+ }
901
+ }
902
+ }
903
+ if (iLast < this.markers.length) {
904
+ this.timerRefStatic = window.setTimeout(
905
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
906
+ function () {
907
+ _this.createClusters(iLast);
908
+ }, 0);
909
+ }
910
+ else {
911
+ this.timerRefStatic = null;
912
+ /**
913
+ * This event is fired when the <code>Clusterer</code> stops
914
+ * clustering markers.
915
+ * @name Clusterer#clusteringend
916
+ * @param {Clusterer} mc The Clusterer whose markers are being clustered.
917
+ * @event
918
+ */
919
+ google.maps.event.trigger(this, 'clusteringend', this);
920
+ for (var i = 0; i < this.clusters.length; i++) {
921
+ this.clusters[i].updateIcon();
922
+ }
923
+ }
924
+ };
925
+ Clusterer.prototype.extend = function (obj1, obj2) {
926
+ return function applyExtend(object) {
927
+ // eslint-disable-next-line guard-for-in
928
+ for (var property in object.prototype) {
929
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
930
+ // @ts-ignore
931
+ this.prototype[property] = object.prototype[property];
932
+ }
933
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
934
+ // @ts-ignore
935
+ return this;
936
+ }.apply(obj1, [obj2]);
937
+ };
938
+ return Clusterer;
939
+ }());
940
+
941
+ exports.Cluster = Cluster;
942
+ exports.ClusterIcon = ClusterIcon;
943
+ exports.Clusterer = Clusterer;
944
+
945
+ Object.defineProperty(exports, '__esModule', { value: true });
946
+
947
+ })));
948
+ //# sourceMappingURL=umd.js.map