@react-google-maps/marker-clusterer 2.10.1 → 2.11.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 CHANGED
@@ -4,36 +4,68 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.markerClusterer = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- var ClusterIcon = /** @class */ (function () {
7
+ /******************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+ /* global Reflect, Promise */
22
+
23
+ var extendStatics = function(d, b) {
24
+ extendStatics = Object.setPrototypeOf ||
25
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
26
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
27
+ return extendStatics(d, b);
28
+ };
29
+
30
+ function __extends(d, b) {
31
+ if (typeof b !== "function" && b !== null)
32
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
33
+ extendStatics(d, b);
34
+ function __() { this.constructor = d; }
35
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36
+ }
37
+
38
+ var ClusterIcon = /** @class */ (function (_super) {
39
+ __extends(ClusterIcon, _super);
8
40
  function ClusterIcon(cluster, styles) {
41
+ var _this = _super.call(this) || this;
9
42
  cluster.getClusterer().extend(ClusterIcon, google.maps.OverlayView);
10
- this.cluster = cluster;
11
- this.clusterClassName = this.cluster.getClusterer().getClusterClass();
12
- this.className = this.clusterClassName;
13
- this.styles = styles;
14
- this.center = undefined;
15
- this.div = null;
16
- this.sums = null;
17
- this.visible = false;
18
- this.boundsChangedListener = null;
19
- this.url = '';
20
- this.height = 0;
21
- this.width = 0;
22
- this.anchorText = [0, 0];
23
- this.anchorIcon = [0, 0];
24
- this.textColor = 'black';
25
- this.textSize = 11;
26
- this.textDecoration = 'none';
27
- this.fontWeight = 'bold';
28
- this.fontStyle = 'normal';
29
- this.fontFamily = 'Arial,sans-serif';
30
- this.backgroundPosition = '0 0';
31
- this.cMouseDownInCluster = null;
32
- this.cDraggingMapByCluster = null;
33
- this.timeOut = null;
34
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
35
- // @ts-ignore
36
- this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
43
+ _this.cluster = cluster;
44
+ _this.clusterClassName = _this.cluster.getClusterer().getClusterClass();
45
+ _this.className = _this.clusterClassName;
46
+ _this.styles = styles;
47
+ _this.center = undefined;
48
+ _this.div = null;
49
+ _this.sums = null;
50
+ _this.visible = false;
51
+ _this.boundsChangedListener = null;
52
+ _this.url = '';
53
+ _this.height = 0;
54
+ _this.width = 0;
55
+ _this.anchorText = [0, 0];
56
+ _this.anchorIcon = [0, 0];
57
+ _this.textColor = 'black';
58
+ _this.textSize = 11;
59
+ _this.textDecoration = 'none';
60
+ _this.fontWeight = 'bold';
61
+ _this.fontStyle = 'normal';
62
+ _this.fontFamily = 'Arial,sans-serif';
63
+ _this.backgroundPosition = '0 0';
64
+ _this.cMouseDownInCluster = null;
65
+ _this.cDraggingMapByCluster = null;
66
+ _this.timeOut = null;
67
+ _this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
68
+ return _this;
37
69
  }
38
70
  ClusterIcon.prototype.onBoundsChanged = function () {
39
71
  this.cDraggingMapByCluster = this.cMouseDownInCluster;
@@ -143,9 +175,9 @@
143
175
  };
144
176
  ClusterIcon.prototype.draw = function () {
145
177
  if (this.visible && this.div !== null && this.center) {
146
- var _a = this.getPosFromLatLng(this.center), x = _a.x, y = _a.y;
147
- this.div.style.top = "".concat(y, "px");
148
- this.div.style.left = "".concat(x, "px");
178
+ var pos = this.getPosFromLatLng(this.center);
179
+ this.div.style.top = pos !== null ? "".concat(pos.y, "px") : '0';
180
+ this.div.style.left = pos !== null ? "".concat(pos.x, "px") : '0';
149
181
  }
150
182
  };
151
183
  ClusterIcon.prototype.hide = function () {
@@ -173,8 +205,8 @@
173
205
  }
174
206
  this.div.style.cursor = 'pointer';
175
207
  this.div.style.position = 'absolute';
176
- this.div.style.top = "".concat(pos.y, "px");
177
- this.div.style.left = "".concat(pos.x, "px");
208
+ this.div.style.top = pos !== null ? "".concat(pos.y, "px") : '0';
209
+ this.div.style.left = pos !== null ? "".concat(pos.x, "px") : '0';
178
210
  this.div.style.width = "".concat(this.width, "px");
179
211
  this.div.style.height = "".concat(this.height, "px");
180
212
  var img = document.createElement('img');
@@ -231,14 +263,15 @@
231
263
  this.center = center;
232
264
  };
233
265
  ClusterIcon.prototype.getPosFromLatLng = function (latlng) {
234
- // @ts-ignore
235
266
  var pos = this.getProjection().fromLatLngToDivPixel(latlng);
236
- pos.x -= this.anchorIcon[1];
237
- pos.y -= this.anchorIcon[0];
267
+ if (pos !== null) {
268
+ pos.x -= this.anchorIcon[1];
269
+ pos.y -= this.anchorIcon[0];
270
+ }
238
271
  return pos;
239
272
  };
240
273
  return ClusterIcon;
241
- }());
274
+ }(google.maps.OverlayView));
242
275
 
243
276
  var Cluster = /** @class */ (function () {
244
277
  function Cluster(markerClusterer) {
@@ -383,7 +416,6 @@
383
416
  return Cluster;
384
417
  }());
385
418
 
386
- /* global google */
387
419
  /**
388
420
  * Supports up to 9007199254740991 (Number.MAX_SAFE_INTEGER) markers
389
421
  * which is not a problem as max array length is 4294967296 (2**32)
@@ -404,91 +436,86 @@
404
436
  var IMAGE_EXTENSION = 'png';
405
437
  var IMAGE_SIZES = [53, 56, 66, 78, 90];
406
438
  var CLUSTERER_CLASS = 'cluster';
407
- var Clusterer = /** @class */ (function () {
439
+ var Clusterer = /** @class */ (function (_super) {
440
+ __extends(Clusterer, _super);
408
441
  function Clusterer(map, optMarkers, optOptions) {
409
442
  if (optMarkers === void 0) { optMarkers = []; }
410
443
  if (optOptions === void 0) { optOptions = {}; }
411
- this.extend(Clusterer, google.maps.OverlayView);
412
- this.markers = [];
413
- this.clusters = [];
414
- this.listeners = [];
415
- this.activeMap = null;
416
- this.ready = false;
417
- this.gridSize = optOptions.gridSize || 60;
418
- this.minClusterSize = optOptions.minimumClusterSize || 2;
419
- this.maxZoom = optOptions.maxZoom || null;
420
- this.styles = optOptions.styles || [];
421
- this.title = optOptions.title || '';
422
- this.zoomOnClick = true;
444
+ var _this = _super.call(this) || this;
445
+ _this.extend(Clusterer, google.maps.OverlayView);
446
+ _this.markers = [];
447
+ _this.clusters = [];
448
+ _this.listeners = [];
449
+ _this.activeMap = null;
450
+ _this.ready = false;
451
+ _this.gridSize = optOptions.gridSize || 60;
452
+ _this.minClusterSize = optOptions.minimumClusterSize || 2;
453
+ _this.maxZoom = optOptions.maxZoom || null;
454
+ _this.styles = optOptions.styles || [];
455
+ _this.title = optOptions.title || '';
456
+ _this.zoomOnClick = true;
423
457
  if (optOptions.zoomOnClick !== undefined) {
424
- this.zoomOnClick = optOptions.zoomOnClick;
458
+ _this.zoomOnClick = optOptions.zoomOnClick;
425
459
  }
426
- this.averageCenter = false;
460
+ _this.averageCenter = false;
427
461
  if (optOptions.averageCenter !== undefined) {
428
- this.averageCenter = optOptions.averageCenter;
462
+ _this.averageCenter = optOptions.averageCenter;
429
463
  }
430
- this.ignoreHidden = false;
464
+ _this.ignoreHidden = false;
431
465
  if (optOptions.ignoreHidden !== undefined) {
432
- this.ignoreHidden = optOptions.ignoreHidden;
466
+ _this.ignoreHidden = optOptions.ignoreHidden;
433
467
  }
434
- this.enableRetinaIcons = false;
468
+ _this.enableRetinaIcons = false;
435
469
  if (optOptions.enableRetinaIcons !== undefined) {
436
- this.enableRetinaIcons = optOptions.enableRetinaIcons;
437
- }
438
- this.imagePath = optOptions.imagePath || IMAGE_PATH;
439
- this.imageExtension = optOptions.imageExtension || IMAGE_EXTENSION;
440
- this.imageSizes = optOptions.imageSizes || IMAGE_SIZES;
441
- this.calculator = optOptions.calculator || CALCULATOR;
442
- this.batchSize = optOptions.batchSize || BATCH_SIZE;
443
- this.batchSizeIE = optOptions.batchSizeIE || BATCH_SIZE_IE;
444
- this.clusterClass = optOptions.clusterClass || CLUSTERER_CLASS;
470
+ _this.enableRetinaIcons = optOptions.enableRetinaIcons;
471
+ }
472
+ _this.imagePath = optOptions.imagePath || IMAGE_PATH;
473
+ _this.imageExtension = optOptions.imageExtension || IMAGE_EXTENSION;
474
+ _this.imageSizes = optOptions.imageSizes || IMAGE_SIZES;
475
+ _this.calculator = optOptions.calculator || CALCULATOR;
476
+ _this.batchSize = optOptions.batchSize || BATCH_SIZE;
477
+ _this.batchSizeIE = optOptions.batchSizeIE || BATCH_SIZE_IE;
478
+ _this.clusterClass = optOptions.clusterClass || CLUSTERER_CLASS;
445
479
  if (navigator.userAgent.toLowerCase().indexOf('msie') !== -1) {
446
480
  // Try to avoid IE timeout when processing a huge number of markers:
447
- this.batchSize = this.batchSizeIE;
481
+ _this.batchSize = _this.batchSizeIE;
448
482
  }
449
- this.timerRefStatic = null;
450
- this.setupStyles();
451
- this.addMarkers(optMarkers, true);
483
+ _this.timerRefStatic = null;
484
+ _this.setupStyles();
485
+ _this.addMarkers(optMarkers, true);
452
486
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
453
487
  // @ts-ignore
454
- this.setMap(map); // Note: this causes onAdd to be called
488
+ _this.setMap(map); // Note: this causes onAdd to be called
489
+ return _this;
455
490
  }
491
+ Clusterer.prototype.onZoomChanged = function () {
492
+ var _a, _b;
493
+ this.resetViewport(false);
494
+ // Workaround for this Google bug: when map is at level 0 and "-" of
495
+ // zoom slider is clicked, a "zoom_changed" event is fired even though
496
+ // the map doesn't zoom out any further. In this situation, no "idle"
497
+ // event is triggered so the cluster markers that have been removed
498
+ // do not get redrawn. Same goes for a zoom in at maxZoom.
499
+ if (((_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.getZoom()) === (this.get('minZoom') || 0) ||
500
+ ((_b = this.getMap()) === null || _b === void 0 ? void 0 : _b.getZoom()) === this.get('maxZoom')) {
501
+ google.maps.event.trigger(this, 'idle');
502
+ }
503
+ };
504
+ Clusterer.prototype.onIdle = function () {
505
+ this.redraw();
506
+ };
456
507
  Clusterer.prototype.onAdd = function () {
457
- var _this = this;
458
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
459
- // @ts-ignore
460
- this.activeMap = this.getMap();
508
+ var map = this.getMap();
509
+ this.activeMap = map;
461
510
  this.ready = true;
462
511
  this.repaint();
463
- // Add the map event listeners
464
- this.listeners = [
465
- google.maps.event.addListener(
466
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
467
- // @ts-ignore
468
- this.getMap(), 'zoom_changed', function () {
469
- _this.resetViewport(false);
470
- // Workaround for this Google bug: when map is at level 0 and "-" of
471
- // zoom slider is clicked, a "zoom_changed" event is fired even though
472
- // the map doesn't zoom out any further. In this situation, no "idle"
473
- // event is triggered so the cluster markers that have been removed
474
- // do not get redrawn. Same goes for a zoom in at maxZoom.
475
- if (
476
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
477
- // @ts-ignore
478
- _this.getMap().getZoom() === (_this.get('minZoom') || 0) ||
479
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
480
- // @ts-ignore
481
- _this.getMap().getZoom() === _this.get('maxZoom')) {
482
- google.maps.event.trigger(_this, 'idle');
483
- }
484
- }),
485
- google.maps.event.addListener(
486
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
487
- // @ts-ignore
488
- this.getMap(), 'idle', function () {
489
- _this.redraw();
490
- }),
491
- ];
512
+ if (map !== null) {
513
+ // Add the map event listeners
514
+ this.listeners = [
515
+ google.maps.event.addListener(map, 'zoom_changed', this.onZoomChanged),
516
+ google.maps.event.addListener(map, 'idle', this.onIdle),
517
+ ];
518
+ }
492
519
  };
493
520
  Clusterer.prototype.onRemove = function () {
494
521
  // Put all the managed markers back on the map:
@@ -732,20 +759,32 @@
732
759
  var trPix = projection.fromLatLngToDivPixel(
733
760
  // Turn the bounds into latlng.
734
761
  new google.maps.LatLng(bounds.getNorthEast().lat(), bounds.getNorthEast().lng()));
735
- trPix.x += this.gridSize;
736
- trPix.y -= this.gridSize;
762
+ if (trPix !== null) {
763
+ trPix.x += this.gridSize;
764
+ trPix.y -= this.gridSize;
765
+ }
737
766
  var blPix = projection.fromLatLngToDivPixel(
738
767
  // Turn the bounds into latlng.
739
768
  new google.maps.LatLng(bounds.getSouthWest().lat(), bounds.getSouthWest().lng()));
740
- blPix.x -= this.gridSize;
741
- blPix.y += this.gridSize;
769
+ if (blPix !== null) {
770
+ blPix.x -= this.gridSize;
771
+ blPix.y += this.gridSize;
772
+ }
742
773
  // Extend the bounds to contain the new bounds.
743
- bounds.extend(
744
- // Convert the pixel points back to LatLng nw
745
- projection.fromDivPixelToLatLng(trPix));
746
- bounds.extend(
747
- // Convert the pixel points back to LatLng sw
748
- projection.fromDivPixelToLatLng(blPix));
774
+ if (trPix !== null) {
775
+ // Convert the pixel points back to LatLng nw
776
+ var point1 = projection.fromDivPixelToLatLng(trPix);
777
+ if (point1 !== null) {
778
+ bounds.extend(point1);
779
+ }
780
+ }
781
+ if (blPix !== null) {
782
+ // Convert the pixel points back to LatLng sw
783
+ var point2 = projection.fromDivPixelToLatLng(blPix);
784
+ if (point2 !== null) {
785
+ bounds.extend(point2);
786
+ }
787
+ }
749
788
  return bounds;
750
789
  };
751
790
  Clusterer.prototype.redraw = function () {
@@ -832,6 +871,8 @@
832
871
  delete this.timerRefStatic;
833
872
  }
834
873
  }
874
+ var map = this.getMap();
875
+ var bounds = map !== null && 'getBounds' in map ? map.getBounds() : null;
835
876
  // Get our current map view bounds.
836
877
  // Create a new bounds object so we don't affect the map.
837
878
  //
@@ -839,24 +880,14 @@
839
880
  var mapBounds =
840
881
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
841
882
  // @ts-ignore
842
- this.getMap().getZoom() > 3
843
- ? new google.maps.LatLngBounds(
844
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
845
- // @ts-ignore
846
- this.getMap()
847
- .getBounds()
848
- .getSouthWest(),
849
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
850
- // @ts-ignore
851
- this.getMap()
852
- .getBounds()
853
- .getNorthEast())
883
+ map.getZoom() > 3
884
+ ? new google.maps.LatLngBounds(bounds === null || bounds === void 0 ? void 0 : bounds.getSouthWest(), bounds === null || bounds === void 0 ? void 0 : bounds.getNorthEast())
854
885
  : new google.maps.LatLngBounds(new google.maps.LatLng(85.02070771743472, -178.48388434375), new google.maps.LatLng(-85.08136444384544, 178.00048865625));
855
- var bounds = this.getExtendedBounds(mapBounds);
886
+ var extendedMapBounds = this.getExtendedBounds(mapBounds);
856
887
  var iLast = Math.min(iFirst + this.batchSize, this.markers.length);
857
888
  for (var i = iFirst; i < iLast; i++) {
858
889
  var marker = this.markers[i];
859
- if (!marker.isAdded && this.isMarkerInBounds(marker, bounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
890
+ if (!marker.isAdded && this.isMarkerInBounds(marker, extendedMapBounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
860
891
  this.addToClosestCluster(marker);
861
892
  }
862
893
  }
@@ -882,19 +913,14 @@
882
913
  };
883
914
  Clusterer.prototype.extend = function (obj1, obj2) {
884
915
  return function applyExtend(object) {
885
- // eslint-disable-next-line guard-for-in
886
916
  for (var property in object.prototype) {
887
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
888
- // @ts-ignore
889
- this.prototype[property] = object.prototype[property];
917
+ this.prototype.set(property, object.prototype.get(property));
890
918
  }
891
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
892
- // @ts-ignore
893
919
  return this;
894
920
  }.apply(obj1, [obj2]);
895
921
  };
896
922
  return Clusterer;
897
- }());
923
+ }(google.maps.OverlayView));
898
924
 
899
925
  exports.Cluster = Cluster;
900
926
  exports.ClusterIcon = ClusterIcon;