@react-google-maps/marker-clusterer 2.10.0 → 2.11.1

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/cjs.js CHANGED
@@ -2,111 +2,156 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var ClusterIcon = /** @class */ (function () {
5
+ /******************************************************************************
6
+ Copyright (c) Microsoft Corporation.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ ***************************************************************************** */
19
+ /* global Reflect, Promise */
20
+
21
+ var extendStatics = function(d, b) {
22
+ extendStatics = Object.setPrototypeOf ||
23
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
24
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
25
+ return extendStatics(d, b);
26
+ };
27
+
28
+ function __extends(d, b) {
29
+ if (typeof b !== "function" && b !== null)
30
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
31
+ extendStatics(d, b);
32
+ function __() { this.constructor = d; }
33
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34
+ }
35
+
36
+ var ClusterIcon = /** @class */ (function (_super) {
37
+ __extends(ClusterIcon, _super);
6
38
  function ClusterIcon(cluster, styles) {
39
+ var _this = _super.call(this) || this;
7
40
  cluster.getClusterer().extend(ClusterIcon, google.maps.OverlayView);
8
- this.cluster = cluster;
9
- this.clusterClassName = this.cluster.getClusterer().getClusterClass();
10
- this.className = this.clusterClassName;
11
- this.styles = styles;
12
- this.center = undefined;
13
- this.div = null;
14
- this.sums = null;
15
- this.visible = false;
16
- this.boundsChangedListener = null;
17
- this.url = '';
18
- this.height = 0;
19
- this.width = 0;
20
- this.anchorText = [0, 0];
21
- this.anchorIcon = [0, 0];
22
- this.textColor = 'black';
23
- this.textSize = 11;
24
- this.textDecoration = 'none';
25
- this.fontWeight = 'bold';
26
- this.fontStyle = 'normal';
27
- this.fontFamily = 'Arial,sans-serif';
28
- this.backgroundPosition = '0 0';
29
- // @ts-ignore
30
- this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
41
+ _this.cluster = cluster;
42
+ _this.clusterClassName = _this.cluster.getClusterer().getClusterClass();
43
+ _this.className = _this.clusterClassName;
44
+ _this.styles = styles;
45
+ _this.center = undefined;
46
+ _this.div = null;
47
+ _this.sums = null;
48
+ _this.visible = false;
49
+ _this.boundsChangedListener = null;
50
+ _this.url = '';
51
+ _this.height = 0;
52
+ _this.width = 0;
53
+ _this.anchorText = [0, 0];
54
+ _this.anchorIcon = [0, 0];
55
+ _this.textColor = 'black';
56
+ _this.textSize = 11;
57
+ _this.textDecoration = 'none';
58
+ _this.fontWeight = 'bold';
59
+ _this.fontStyle = 'normal';
60
+ _this.fontFamily = 'Arial,sans-serif';
61
+ _this.backgroundPosition = '0 0';
62
+ _this.cMouseDownInCluster = null;
63
+ _this.cDraggingMapByCluster = null;
64
+ _this.timeOut = null;
65
+ _this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
66
+ return _this;
31
67
  }
68
+ ClusterIcon.prototype.onBoundsChanged = function () {
69
+ this.cDraggingMapByCluster = this.cMouseDownInCluster;
70
+ };
71
+ ClusterIcon.prototype.onMouseDown = function () {
72
+ this.cMouseDownInCluster = true;
73
+ this.cDraggingMapByCluster = false;
74
+ };
75
+ ClusterIcon.prototype.onClick = function (event) {
76
+ this.cMouseDownInCluster = false;
77
+ if (!this.cDraggingMapByCluster) {
78
+ var markerClusterer_1 = this.cluster.getClusterer();
79
+ /**
80
+ * This event is fired when a cluster marker is clicked.
81
+ * @name MarkerClusterer#click
82
+ * @param {Cluster} c The cluster that was clicked.
83
+ * @event
84
+ */
85
+ google.maps.event.trigger(markerClusterer_1, 'click', this.cluster);
86
+ google.maps.event.trigger(markerClusterer_1, 'clusterclick', this.cluster); // deprecated name
87
+ // The default click handler follows. Disable it by setting
88
+ // the zoomOnClick property to false.
89
+ if (markerClusterer_1.getZoomOnClick()) {
90
+ // Zoom into the cluster.
91
+ var maxZoom_1 = markerClusterer_1.getMaxZoom();
92
+ var bounds_1 = this.cluster.getBounds();
93
+ var map = markerClusterer_1.getMap();
94
+ if (map !== null && 'fitBounds' in map) {
95
+ map.fitBounds(bounds_1);
96
+ }
97
+ // There is a fix for Issue 170 here:
98
+ this.timeOut = window.setTimeout(function () {
99
+ var map = markerClusterer_1.getMap();
100
+ if (map !== null) {
101
+ if ('fitBounds' in map) {
102
+ map.fitBounds(bounds_1);
103
+ }
104
+ var zoom = map.getZoom() || 0;
105
+ // Don't zoom beyond the max zoom level
106
+ if (maxZoom_1 !== null &&
107
+ zoom > maxZoom_1) {
108
+ map.setZoom(maxZoom_1 + 1);
109
+ }
110
+ }
111
+ }, 100);
112
+ }
113
+ // Prevent event propagation to the map:
114
+ event.cancelBubble = true;
115
+ if (event.stopPropagation) {
116
+ event.stopPropagation();
117
+ }
118
+ }
119
+ };
120
+ ClusterIcon.prototype.onMouseOver = function () {
121
+ /**
122
+ * This event is fired when the mouse moves over a cluster marker.
123
+ * @name MarkerClusterer#mouseover
124
+ * @param {Cluster} c The cluster that the mouse moved over.
125
+ * @event
126
+ */
127
+ google.maps.event.trigger(this.cluster.getClusterer(), 'mouseover', this.cluster);
128
+ };
129
+ ClusterIcon.prototype.onMouseOut = function () {
130
+ /**
131
+ * This event is fired when the mouse moves out of a cluster marker.
132
+ * @name MarkerClusterer#mouseout
133
+ * @param {Cluster} c The cluster that the mouse moved out of.
134
+ * @event
135
+ */
136
+ google.maps.event.trigger(this.cluster.getClusterer(), 'mouseout', this.cluster);
137
+ };
32
138
  ClusterIcon.prototype.onAdd = function () {
33
- var _this = this;
34
- var cMouseDownInCluster;
35
- var cDraggingMapByCluster;
139
+ var _a;
36
140
  this.div = document.createElement('div');
37
141
  this.div.className = this.className;
38
142
  if (this.visible) {
39
143
  this.show();
40
144
  }
41
- // @ts-ignore
42
- this.getPanes().overlayMouseTarget.appendChild(this.div);
43
- // Fix for Issue 157
44
- this.boundsChangedListener = google.maps.event.addListener(
45
- // @ts-ignore
46
- this.getMap(), 'boundschanged', function boundsChanged() {
47
- cDraggingMapByCluster = cMouseDownInCluster;
48
- });
49
- google.maps.event.addListener(this.div, 'mousedown', function onMouseDown() {
50
- cMouseDownInCluster = true;
51
- cDraggingMapByCluster = false;
52
- });
53
- google.maps.event.addListener(this.div, 'click', function (event) {
54
- cMouseDownInCluster = false;
55
- if (!cDraggingMapByCluster) {
56
- var markerClusterer_1 = _this.cluster.getClusterer();
57
- /**
58
- * This event is fired when a cluster marker is clicked.
59
- * @name MarkerClusterer#click
60
- * @param {Cluster} c The cluster that was clicked.
61
- * @event
62
- */
63
- google.maps.event.trigger(markerClusterer_1, 'click', _this.cluster);
64
- google.maps.event.trigger(markerClusterer_1, 'clusterclick', _this.cluster); // deprecated name
65
- // The default click handler follows. Disable it by setting
66
- // the zoomOnClick property to false.
67
- if (markerClusterer_1.getZoomOnClick()) {
68
- // Zoom into the cluster.
69
- var maxZoom_1 = markerClusterer_1.getMaxZoom();
70
- var bounds_1 = _this.cluster.getBounds();
71
- // @ts-ignore
72
- markerClusterer_1.getMap().fitBounds(bounds_1);
73
- // There is a fix for Issue 170 here:
74
- setTimeout(function timeout() {
75
- // @ts-ignore
76
- markerClusterer_1.getMap().fitBounds(bounds_1);
77
- // Don't zoom beyond the max zoom level
78
- // @ts-ignore
79
- if (maxZoom_1 !== null && markerClusterer_1.getMap().getZoom() > maxZoom_1) {
80
- // @ts-ignore
81
- markerClusterer_1.getMap().setZoom(maxZoom_1 + 1);
82
- }
83
- }, 100);
84
- }
85
- // Prevent event propagation to the map:
86
- event.cancelBubble = true;
87
- if (event.stopPropagation) {
88
- event.stopPropagation();
89
- }
90
- }
91
- });
92
- google.maps.event.addListener(this.div, 'mouseover', function () {
93
- /**
94
- * This event is fired when the mouse moves over a cluster marker.
95
- * @name MarkerClusterer#mouseover
96
- * @param {Cluster} c The cluster that the mouse moved over.
97
- * @event
98
- */
99
- google.maps.event.trigger(_this.cluster.getClusterer(), 'mouseover', _this.cluster);
100
- });
101
- google.maps.event.addListener(this.div, 'mouseout', function () {
102
- /**
103
- * This event is fired when the mouse moves out of a cluster marker.
104
- * @name MarkerClusterer#mouseout
105
- * @param {Cluster} c The cluster that the mouse moved out of.
106
- * @event
107
- */
108
- google.maps.event.trigger(_this.cluster.getClusterer(), 'mouseout', _this.cluster);
109
- });
145
+ (_a = this.getPanes()) === null || _a === void 0 ? void 0 : _a.overlayMouseTarget.appendChild(this.div);
146
+ var map = this.getMap();
147
+ if (map !== null) {
148
+ // Fix for Issue 157
149
+ this.boundsChangedListener = google.maps.event.addListener(map, 'bounds_changed', this.onBoundsChanged);
150
+ this.div.addEventListener('mousedown', this.onMouseDown);
151
+ this.div.addEventListener('click', this.onClick);
152
+ this.div.addEventListener('mouseover', this.onMouseOver);
153
+ this.div.addEventListener('mouseout', this.onMouseOut);
154
+ }
110
155
  };
111
156
  ClusterIcon.prototype.onRemove = function () {
112
157
  if (this.div && this.div.parentNode) {
@@ -114,16 +159,23 @@ var ClusterIcon = /** @class */ (function () {
114
159
  if (this.boundsChangedListener !== null) {
115
160
  google.maps.event.removeListener(this.boundsChangedListener);
116
161
  }
117
- google.maps.event.clearInstanceListeners(this.div);
162
+ this.div.removeEventListener('mousedown', this.onMouseDown);
163
+ this.div.removeEventListener('click', this.onClick);
164
+ this.div.removeEventListener('mouseover', this.onMouseOver);
165
+ this.div.removeEventListener('mouseout', this.onMouseOut);
118
166
  this.div.parentNode.removeChild(this.div);
167
+ if (this.timeOut !== null) {
168
+ window.clearTimeout(this.timeOut);
169
+ this.timeOut = null;
170
+ }
119
171
  this.div = null;
120
172
  }
121
173
  };
122
174
  ClusterIcon.prototype.draw = function () {
123
175
  if (this.visible && this.div !== null && this.center) {
124
- var _a = this.getPosFromLatLng(this.center), x = _a.x, y = _a.y;
125
- this.div.style.top = y + 'px';
126
- this.div.style.left = x + 'px';
176
+ var pos = this.getPosFromLatLng(this.center);
177
+ this.div.style.top = pos !== null ? "".concat(pos.y, "px") : '0';
178
+ this.div.style.left = pos !== null ? "".concat(pos.x, "px") : '0';
127
179
  }
128
180
  };
129
181
  ClusterIcon.prototype.hide = function () {
@@ -141,7 +193,9 @@ var ClusterIcon = /** @class */ (function () {
141
193
  var spriteH = parseInt(bp[0].replace(/^\s+|\s+$/g, ''), 10);
142
194
  var spriteV = parseInt(bp[1].replace(/^\s+|\s+$/g, ''), 10);
143
195
  var pos = this.getPosFromLatLng(this.center);
144
- if (this.sums === null || typeof this.sums.title === 'undefined' || this.sums.title === '') {
196
+ if (this.sums === null ||
197
+ typeof this.sums.title === 'undefined' ||
198
+ this.sums.title === '') {
145
199
  divTitle = this.cluster.getClusterer().getTitle();
146
200
  }
147
201
  else {
@@ -149,8 +203,8 @@ var ClusterIcon = /** @class */ (function () {
149
203
  }
150
204
  this.div.style.cursor = 'pointer';
151
205
  this.div.style.position = 'absolute';
152
- this.div.style.top = "".concat(pos.y, "px");
153
- this.div.style.left = "".concat(pos.x, "px");
206
+ this.div.style.top = pos !== null ? "".concat(pos.y, "px") : '0';
207
+ this.div.style.left = pos !== null ? "".concat(pos.x, "px") : '0';
154
208
  this.div.style.width = "".concat(this.width, "px");
155
209
  this.div.style.height = "".concat(this.height, "px");
156
210
  var img = document.createElement('img');
@@ -207,22 +261,19 @@ var ClusterIcon = /** @class */ (function () {
207
261
  this.center = center;
208
262
  };
209
263
  ClusterIcon.prototype.getPosFromLatLng = function (latlng) {
210
- // @ts-ignore
211
264
  var pos = this.getProjection().fromLatLngToDivPixel(latlng);
212
- pos.x -= this.anchorIcon[1];
213
- pos.y -= this.anchorIcon[0];
214
- // pos.x = pos.x
215
- // pos.y = pos.y
265
+ if (pos !== null) {
266
+ pos.x -= this.anchorIcon[1];
267
+ pos.y -= this.anchorIcon[0];
268
+ }
216
269
  return pos;
217
270
  };
218
271
  return ClusterIcon;
219
- }());
272
+ }(google.maps.OverlayView));
220
273
 
221
274
  var Cluster = /** @class */ (function () {
222
275
  function Cluster(markerClusterer) {
223
276
  this.markerClusterer = markerClusterer;
224
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
225
- // @ts-ignore
226
277
  this.map = this.markerClusterer.getMap();
227
278
  this.gridSize = this.markerClusterer.getGridSize();
228
279
  this.minClusterSize = this.markerClusterer.getMinimumClusterSize();
@@ -259,8 +310,6 @@ var Cluster = /** @class */ (function () {
259
310
  return bounds;
260
311
  };
261
312
  Cluster.prototype.remove = function () {
262
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
263
- // @ts-ignore
264
313
  this.clusterIcon.setMap(null);
265
314
  this.markers = [];
266
315
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -268,6 +317,7 @@ var Cluster = /** @class */ (function () {
268
317
  delete this.markers;
269
318
  };
270
319
  Cluster.prototype.addMarker = function (marker) {
320
+ var _a;
271
321
  if (this.isMarkerAlreadyAdded(marker)) {
272
322
  return false;
273
323
  }
@@ -292,7 +342,7 @@ var Cluster = /** @class */ (function () {
292
342
  this.markers.push(marker);
293
343
  var mCount = this.markers.length;
294
344
  var maxZoom = this.markerClusterer.getMaxZoom();
295
- var zoom = this.map.getZoom();
345
+ var zoom = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getZoom();
296
346
  if (maxZoom !== null && typeof zoom !== 'undefined' && zoom > maxZoom) {
297
347
  // Zoomed in past max zoom, so show the marker.
298
348
  if (marker.getMap() !== this.map) {
@@ -329,9 +379,10 @@ var Cluster = /** @class */ (function () {
329
379
  this.bounds = this.markerClusterer.getExtendedBounds(new google.maps.LatLngBounds(this.center, this.center));
330
380
  };
331
381
  Cluster.prototype.updateIcon = function () {
382
+ var _a;
332
383
  var mCount = this.markers.length;
333
384
  var maxZoom = this.markerClusterer.getMaxZoom();
334
- var zoom = this.map.getZoom();
385
+ var zoom = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getZoom();
335
386
  if (maxZoom !== null && typeof zoom !== 'undefined' && zoom > maxZoom) {
336
387
  this.clusterIcon.hide();
337
388
  return;
@@ -361,7 +412,6 @@ var Cluster = /** @class */ (function () {
361
412
  return Cluster;
362
413
  }());
363
414
 
364
- /* global google */
365
415
  /**
366
416
  * Supports up to 9007199254740991 (Number.MAX_SAFE_INTEGER) markers
367
417
  * which is not a problem as max array length is 4294967296 (2**32)
@@ -382,91 +432,84 @@ var IMAGE_PATH = 'https://developers.google.com/maps/documentation/javascript/ex
382
432
  var IMAGE_EXTENSION = 'png';
383
433
  var IMAGE_SIZES = [53, 56, 66, 78, 90];
384
434
  var CLUSTERER_CLASS = 'cluster';
385
- var Clusterer = /** @class */ (function () {
435
+ var Clusterer = /** @class */ (function (_super) {
436
+ __extends(Clusterer, _super);
386
437
  function Clusterer(map, optMarkers, optOptions) {
387
438
  if (optMarkers === void 0) { optMarkers = []; }
388
439
  if (optOptions === void 0) { optOptions = {}; }
389
- this.extend(Clusterer, google.maps.OverlayView);
390
- this.markers = [];
391
- this.clusters = [];
392
- this.listeners = [];
393
- this.activeMap = null;
394
- this.ready = false;
395
- this.gridSize = optOptions.gridSize || 60;
396
- this.minClusterSize = optOptions.minimumClusterSize || 2;
397
- this.maxZoom = optOptions.maxZoom || null;
398
- this.styles = optOptions.styles || [];
399
- this.title = optOptions.title || '';
400
- this.zoomOnClick = true;
440
+ var _this = _super.call(this) || this;
441
+ _this.extend(Clusterer, google.maps.OverlayView);
442
+ _this.markers = [];
443
+ _this.clusters = [];
444
+ _this.listeners = [];
445
+ _this.activeMap = null;
446
+ _this.ready = false;
447
+ _this.gridSize = optOptions.gridSize || 60;
448
+ _this.minClusterSize = optOptions.minimumClusterSize || 2;
449
+ _this.maxZoom = optOptions.maxZoom || null;
450
+ _this.styles = optOptions.styles || [];
451
+ _this.title = optOptions.title || '';
452
+ _this.zoomOnClick = true;
401
453
  if (optOptions.zoomOnClick !== undefined) {
402
- this.zoomOnClick = optOptions.zoomOnClick;
454
+ _this.zoomOnClick = optOptions.zoomOnClick;
403
455
  }
404
- this.averageCenter = false;
456
+ _this.averageCenter = false;
405
457
  if (optOptions.averageCenter !== undefined) {
406
- this.averageCenter = optOptions.averageCenter;
458
+ _this.averageCenter = optOptions.averageCenter;
407
459
  }
408
- this.ignoreHidden = false;
460
+ _this.ignoreHidden = false;
409
461
  if (optOptions.ignoreHidden !== undefined) {
410
- this.ignoreHidden = optOptions.ignoreHidden;
462
+ _this.ignoreHidden = optOptions.ignoreHidden;
411
463
  }
412
- this.enableRetinaIcons = false;
464
+ _this.enableRetinaIcons = false;
413
465
  if (optOptions.enableRetinaIcons !== undefined) {
414
- this.enableRetinaIcons = optOptions.enableRetinaIcons;
415
- }
416
- this.imagePath = optOptions.imagePath || IMAGE_PATH;
417
- this.imageExtension = optOptions.imageExtension || IMAGE_EXTENSION;
418
- this.imageSizes = optOptions.imageSizes || IMAGE_SIZES;
419
- this.calculator = optOptions.calculator || CALCULATOR;
420
- this.batchSize = optOptions.batchSize || BATCH_SIZE;
421
- this.batchSizeIE = optOptions.batchSizeIE || BATCH_SIZE_IE;
422
- this.clusterClass = optOptions.clusterClass || CLUSTERER_CLASS;
466
+ _this.enableRetinaIcons = optOptions.enableRetinaIcons;
467
+ }
468
+ _this.imagePath = optOptions.imagePath || IMAGE_PATH;
469
+ _this.imageExtension = optOptions.imageExtension || IMAGE_EXTENSION;
470
+ _this.imageSizes = optOptions.imageSizes || IMAGE_SIZES;
471
+ _this.calculator = optOptions.calculator || CALCULATOR;
472
+ _this.batchSize = optOptions.batchSize || BATCH_SIZE;
473
+ _this.batchSizeIE = optOptions.batchSizeIE || BATCH_SIZE_IE;
474
+ _this.clusterClass = optOptions.clusterClass || CLUSTERER_CLASS;
423
475
  if (navigator.userAgent.toLowerCase().indexOf('msie') !== -1) {
424
476
  // Try to avoid IE timeout when processing a huge number of markers:
425
- this.batchSize = this.batchSizeIE;
477
+ _this.batchSize = _this.batchSizeIE;
426
478
  }
427
- this.timerRefStatic = null;
428
- this.setupStyles();
429
- this.addMarkers(optMarkers, true);
430
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
431
- // @ts-ignore
432
- this.setMap(map); // Note: this causes onAdd to be called
479
+ _this.timerRefStatic = null;
480
+ _this.setupStyles();
481
+ _this.addMarkers(optMarkers, true);
482
+ _this.setMap(map); // Note: this causes onAdd to be called
483
+ return _this;
433
484
  }
485
+ Clusterer.prototype.onZoomChanged = function () {
486
+ var _a, _b;
487
+ this.resetViewport(false);
488
+ // Workaround for this Google bug: when map is at level 0 and "-" of
489
+ // zoom slider is clicked, a "zoom_changed" event is fired even though
490
+ // the map doesn't zoom out any further. In this situation, no "idle"
491
+ // event is triggered so the cluster markers that have been removed
492
+ // do not get redrawn. Same goes for a zoom in at maxZoom.
493
+ if (((_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.getZoom()) === (this.get('minZoom') || 0) ||
494
+ ((_b = this.getMap()) === null || _b === void 0 ? void 0 : _b.getZoom()) === this.get('maxZoom')) {
495
+ google.maps.event.trigger(this, 'idle');
496
+ }
497
+ };
498
+ Clusterer.prototype.onIdle = function () {
499
+ this.redraw();
500
+ };
434
501
  Clusterer.prototype.onAdd = function () {
435
- var _this = this;
436
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
437
- // @ts-ignore
438
- this.activeMap = this.getMap();
502
+ var map = this.getMap();
503
+ this.activeMap = map;
439
504
  this.ready = true;
440
505
  this.repaint();
441
- // Add the map event listeners
442
- this.listeners = [
443
- google.maps.event.addListener(
444
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
445
- // @ts-ignore
446
- this.getMap(), 'zoom_changed', function () {
447
- _this.resetViewport(false);
448
- // Workaround for this Google bug: when map is at level 0 and "-" of
449
- // zoom slider is clicked, a "zoom_changed" event is fired even though
450
- // the map doesn't zoom out any further. In this situation, no "idle"
451
- // event is triggered so the cluster markers that have been removed
452
- // do not get redrawn. Same goes for a zoom in at maxZoom.
453
- if (
454
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
455
- // @ts-ignore
456
- _this.getMap().getZoom() === (_this.get('minZoom') || 0) ||
457
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
458
- // @ts-ignore
459
- _this.getMap().getZoom() === _this.get('maxZoom')) {
460
- google.maps.event.trigger(_this, 'idle');
461
- }
462
- }),
463
- google.maps.event.addListener(
464
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
465
- // @ts-ignore
466
- this.getMap(), 'idle', function () {
467
- _this.redraw();
468
- }),
469
- ];
506
+ if (map !== null) {
507
+ // Add the map event listeners
508
+ this.listeners = [
509
+ google.maps.event.addListener(map, 'zoom_changed', this.onZoomChanged),
510
+ google.maps.event.addListener(map, 'idle', this.onIdle),
511
+ ];
512
+ }
470
513
  };
471
514
  Clusterer.prototype.onRemove = function () {
472
515
  // Put all the managed markers back on the map:
@@ -511,9 +554,10 @@ var Clusterer = /** @class */ (function () {
511
554
  bounds.extend(position);
512
555
  }
513
556
  }
514
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
515
- // @ts-ignore
516
- this.getMap().fitBounds(bounds);
557
+ var map = this.getMap();
558
+ if (map !== null && 'fitBounds' in map) {
559
+ map.fitBounds(bounds);
560
+ }
517
561
  };
518
562
  Clusterer.prototype.getGridSize = function () {
519
563
  return this.gridSize;
@@ -703,27 +747,37 @@ var Clusterer = /** @class */ (function () {
703
747
  }, 0);
704
748
  };
705
749
  Clusterer.prototype.getExtendedBounds = function (bounds) {
706
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
707
- // @ts-ignore
708
750
  var projection = this.getProjection();
709
751
  // Convert the points to pixels and the extend out by the grid size.
710
752
  var trPix = projection.fromLatLngToDivPixel(
711
753
  // Turn the bounds into latlng.
712
754
  new google.maps.LatLng(bounds.getNorthEast().lat(), bounds.getNorthEast().lng()));
713
- trPix.x += this.gridSize;
714
- trPix.y -= this.gridSize;
755
+ if (trPix !== null) {
756
+ trPix.x += this.gridSize;
757
+ trPix.y -= this.gridSize;
758
+ }
715
759
  var blPix = projection.fromLatLngToDivPixel(
716
760
  // Turn the bounds into latlng.
717
761
  new google.maps.LatLng(bounds.getSouthWest().lat(), bounds.getSouthWest().lng()));
718
- blPix.x -= this.gridSize;
719
- blPix.y += this.gridSize;
762
+ if (blPix !== null) {
763
+ blPix.x -= this.gridSize;
764
+ blPix.y += this.gridSize;
765
+ }
720
766
  // Extend the bounds to contain the new bounds.
721
- bounds.extend(
722
- // Convert the pixel points back to LatLng nw
723
- projection.fromDivPixelToLatLng(trPix));
724
- bounds.extend(
725
- // Convert the pixel points back to LatLng sw
726
- projection.fromDivPixelToLatLng(blPix));
767
+ if (trPix !== null) {
768
+ // Convert the pixel points back to LatLng nw
769
+ var point1 = projection.fromDivPixelToLatLng(trPix);
770
+ if (point1 !== null) {
771
+ bounds.extend(point1);
772
+ }
773
+ }
774
+ if (blPix !== null) {
775
+ // Convert the pixel points back to LatLng sw
776
+ var point2 = projection.fromDivPixelToLatLng(blPix);
777
+ if (point2 !== null) {
778
+ bounds.extend(point2);
779
+ }
780
+ }
727
781
  return bounds;
728
782
  };
729
783
  Clusterer.prototype.redraw = function () {
@@ -810,31 +864,21 @@ var Clusterer = /** @class */ (function () {
810
864
  delete this.timerRefStatic;
811
865
  }
812
866
  }
867
+ var map = this.getMap();
868
+ var bounds = map !== null && 'getBounds' in map ? map.getBounds() : null;
869
+ var zoom = (map === null || map === void 0 ? void 0 : map.getZoom()) || 0;
813
870
  // Get our current map view bounds.
814
871
  // Create a new bounds object so we don't affect the map.
815
872
  //
816
873
  // See Comments 9 & 11 on Issue 3651 relating to this workaround for a Google Maps bug:
817
- var mapBounds =
818
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
819
- // @ts-ignore
820
- this.getMap().getZoom() > 3
821
- ? new google.maps.LatLngBounds(
822
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
823
- // @ts-ignore
824
- this.getMap()
825
- .getBounds()
826
- .getSouthWest(),
827
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
828
- // @ts-ignore
829
- this.getMap()
830
- .getBounds()
831
- .getNorthEast())
874
+ var mapBounds = zoom > 3
875
+ ? new google.maps.LatLngBounds(bounds === null || bounds === void 0 ? void 0 : bounds.getSouthWest(), bounds === null || bounds === void 0 ? void 0 : bounds.getNorthEast())
832
876
  : new google.maps.LatLngBounds(new google.maps.LatLng(85.02070771743472, -178.48388434375), new google.maps.LatLng(-85.08136444384544, 178.00048865625));
833
- var bounds = this.getExtendedBounds(mapBounds);
877
+ var extendedMapBounds = this.getExtendedBounds(mapBounds);
834
878
  var iLast = Math.min(iFirst + this.batchSize, this.markers.length);
835
879
  for (var i = iFirst; i < iLast; i++) {
836
880
  var marker = this.markers[i];
837
- if (!marker.isAdded && this.isMarkerInBounds(marker, bounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
881
+ if (!marker.isAdded && this.isMarkerInBounds(marker, extendedMapBounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
838
882
  this.addToClosestCluster(marker);
839
883
  }
840
884
  }
@@ -860,19 +904,14 @@ var Clusterer = /** @class */ (function () {
860
904
  };
861
905
  Clusterer.prototype.extend = function (obj1, obj2) {
862
906
  return function applyExtend(object) {
863
- // eslint-disable-next-line guard-for-in
864
907
  for (var property in object.prototype) {
865
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
866
- // @ts-ignore
867
- this.prototype[property] = object.prototype[property];
908
+ this.prototype.set(property, object.prototype.get(property));
868
909
  }
869
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
870
- // @ts-ignore
871
910
  return this;
872
911
  }.apply(obj1, [obj2]);
873
912
  };
874
913
  return Clusterer;
875
- }());
914
+ }(google.maps.OverlayView));
876
915
 
877
916
  exports.Cluster = Cluster;
878
917
  exports.ClusterIcon = ClusterIcon;