@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/cjs.js CHANGED
@@ -2,36 +2,68 @@
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
- this.cMouseDownInCluster = null;
30
- this.cDraggingMapByCluster = null;
31
- this.timeOut = null;
32
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
33
- // @ts-ignore
34
- 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;
35
67
  }
36
68
  ClusterIcon.prototype.onBoundsChanged = function () {
37
69
  this.cDraggingMapByCluster = this.cMouseDownInCluster;
@@ -141,9 +173,9 @@ var ClusterIcon = /** @class */ (function () {
141
173
  };
142
174
  ClusterIcon.prototype.draw = function () {
143
175
  if (this.visible && this.div !== null && this.center) {
144
- var _a = this.getPosFromLatLng(this.center), x = _a.x, y = _a.y;
145
- this.div.style.top = "".concat(y, "px");
146
- this.div.style.left = "".concat(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';
147
179
  }
148
180
  };
149
181
  ClusterIcon.prototype.hide = function () {
@@ -171,8 +203,8 @@ var ClusterIcon = /** @class */ (function () {
171
203
  }
172
204
  this.div.style.cursor = 'pointer';
173
205
  this.div.style.position = 'absolute';
174
- this.div.style.top = "".concat(pos.y, "px");
175
- 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';
176
208
  this.div.style.width = "".concat(this.width, "px");
177
209
  this.div.style.height = "".concat(this.height, "px");
178
210
  var img = document.createElement('img');
@@ -229,14 +261,15 @@ var ClusterIcon = /** @class */ (function () {
229
261
  this.center = center;
230
262
  };
231
263
  ClusterIcon.prototype.getPosFromLatLng = function (latlng) {
232
- // @ts-ignore
233
264
  var pos = this.getProjection().fromLatLngToDivPixel(latlng);
234
- pos.x -= this.anchorIcon[1];
235
- pos.y -= this.anchorIcon[0];
265
+ if (pos !== null) {
266
+ pos.x -= this.anchorIcon[1];
267
+ pos.y -= this.anchorIcon[0];
268
+ }
236
269
  return pos;
237
270
  };
238
271
  return ClusterIcon;
239
- }());
272
+ }(google.maps.OverlayView));
240
273
 
241
274
  var Cluster = /** @class */ (function () {
242
275
  function Cluster(markerClusterer) {
@@ -381,7 +414,6 @@ var Cluster = /** @class */ (function () {
381
414
  return Cluster;
382
415
  }());
383
416
 
384
- /* global google */
385
417
  /**
386
418
  * Supports up to 9007199254740991 (Number.MAX_SAFE_INTEGER) markers
387
419
  * which is not a problem as max array length is 4294967296 (2**32)
@@ -402,91 +434,86 @@ var IMAGE_PATH = 'https://developers.google.com/maps/documentation/javascript/ex
402
434
  var IMAGE_EXTENSION = 'png';
403
435
  var IMAGE_SIZES = [53, 56, 66, 78, 90];
404
436
  var CLUSTERER_CLASS = 'cluster';
405
- var Clusterer = /** @class */ (function () {
437
+ var Clusterer = /** @class */ (function (_super) {
438
+ __extends(Clusterer, _super);
406
439
  function Clusterer(map, optMarkers, optOptions) {
407
440
  if (optMarkers === void 0) { optMarkers = []; }
408
441
  if (optOptions === void 0) { optOptions = {}; }
409
- this.extend(Clusterer, google.maps.OverlayView);
410
- this.markers = [];
411
- this.clusters = [];
412
- this.listeners = [];
413
- this.activeMap = null;
414
- this.ready = false;
415
- this.gridSize = optOptions.gridSize || 60;
416
- this.minClusterSize = optOptions.minimumClusterSize || 2;
417
- this.maxZoom = optOptions.maxZoom || null;
418
- this.styles = optOptions.styles || [];
419
- this.title = optOptions.title || '';
420
- this.zoomOnClick = true;
442
+ var _this = _super.call(this) || this;
443
+ _this.extend(Clusterer, google.maps.OverlayView);
444
+ _this.markers = [];
445
+ _this.clusters = [];
446
+ _this.listeners = [];
447
+ _this.activeMap = null;
448
+ _this.ready = false;
449
+ _this.gridSize = optOptions.gridSize || 60;
450
+ _this.minClusterSize = optOptions.minimumClusterSize || 2;
451
+ _this.maxZoom = optOptions.maxZoom || null;
452
+ _this.styles = optOptions.styles || [];
453
+ _this.title = optOptions.title || '';
454
+ _this.zoomOnClick = true;
421
455
  if (optOptions.zoomOnClick !== undefined) {
422
- this.zoomOnClick = optOptions.zoomOnClick;
456
+ _this.zoomOnClick = optOptions.zoomOnClick;
423
457
  }
424
- this.averageCenter = false;
458
+ _this.averageCenter = false;
425
459
  if (optOptions.averageCenter !== undefined) {
426
- this.averageCenter = optOptions.averageCenter;
460
+ _this.averageCenter = optOptions.averageCenter;
427
461
  }
428
- this.ignoreHidden = false;
462
+ _this.ignoreHidden = false;
429
463
  if (optOptions.ignoreHidden !== undefined) {
430
- this.ignoreHidden = optOptions.ignoreHidden;
464
+ _this.ignoreHidden = optOptions.ignoreHidden;
431
465
  }
432
- this.enableRetinaIcons = false;
466
+ _this.enableRetinaIcons = false;
433
467
  if (optOptions.enableRetinaIcons !== undefined) {
434
- this.enableRetinaIcons = optOptions.enableRetinaIcons;
435
- }
436
- this.imagePath = optOptions.imagePath || IMAGE_PATH;
437
- this.imageExtension = optOptions.imageExtension || IMAGE_EXTENSION;
438
- this.imageSizes = optOptions.imageSizes || IMAGE_SIZES;
439
- this.calculator = optOptions.calculator || CALCULATOR;
440
- this.batchSize = optOptions.batchSize || BATCH_SIZE;
441
- this.batchSizeIE = optOptions.batchSizeIE || BATCH_SIZE_IE;
442
- this.clusterClass = optOptions.clusterClass || CLUSTERER_CLASS;
468
+ _this.enableRetinaIcons = optOptions.enableRetinaIcons;
469
+ }
470
+ _this.imagePath = optOptions.imagePath || IMAGE_PATH;
471
+ _this.imageExtension = optOptions.imageExtension || IMAGE_EXTENSION;
472
+ _this.imageSizes = optOptions.imageSizes || IMAGE_SIZES;
473
+ _this.calculator = optOptions.calculator || CALCULATOR;
474
+ _this.batchSize = optOptions.batchSize || BATCH_SIZE;
475
+ _this.batchSizeIE = optOptions.batchSizeIE || BATCH_SIZE_IE;
476
+ _this.clusterClass = optOptions.clusterClass || CLUSTERER_CLASS;
443
477
  if (navigator.userAgent.toLowerCase().indexOf('msie') !== -1) {
444
478
  // Try to avoid IE timeout when processing a huge number of markers:
445
- this.batchSize = this.batchSizeIE;
479
+ _this.batchSize = _this.batchSizeIE;
446
480
  }
447
- this.timerRefStatic = null;
448
- this.setupStyles();
449
- this.addMarkers(optMarkers, true);
481
+ _this.timerRefStatic = null;
482
+ _this.setupStyles();
483
+ _this.addMarkers(optMarkers, true);
450
484
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
451
485
  // @ts-ignore
452
- this.setMap(map); // Note: this causes onAdd to be called
486
+ _this.setMap(map); // Note: this causes onAdd to be called
487
+ return _this;
453
488
  }
489
+ Clusterer.prototype.onZoomChanged = function () {
490
+ var _a, _b;
491
+ this.resetViewport(false);
492
+ // Workaround for this Google bug: when map is at level 0 and "-" of
493
+ // zoom slider is clicked, a "zoom_changed" event is fired even though
494
+ // the map doesn't zoom out any further. In this situation, no "idle"
495
+ // event is triggered so the cluster markers that have been removed
496
+ // do not get redrawn. Same goes for a zoom in at maxZoom.
497
+ if (((_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.getZoom()) === (this.get('minZoom') || 0) ||
498
+ ((_b = this.getMap()) === null || _b === void 0 ? void 0 : _b.getZoom()) === this.get('maxZoom')) {
499
+ google.maps.event.trigger(this, 'idle');
500
+ }
501
+ };
502
+ Clusterer.prototype.onIdle = function () {
503
+ this.redraw();
504
+ };
454
505
  Clusterer.prototype.onAdd = function () {
455
- var _this = this;
456
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
457
- // @ts-ignore
458
- this.activeMap = this.getMap();
506
+ var map = this.getMap();
507
+ this.activeMap = map;
459
508
  this.ready = true;
460
509
  this.repaint();
461
- // Add the map event listeners
462
- this.listeners = [
463
- google.maps.event.addListener(
464
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
465
- // @ts-ignore
466
- this.getMap(), 'zoom_changed', function () {
467
- _this.resetViewport(false);
468
- // Workaround for this Google bug: when map is at level 0 and "-" of
469
- // zoom slider is clicked, a "zoom_changed" event is fired even though
470
- // the map doesn't zoom out any further. In this situation, no "idle"
471
- // event is triggered so the cluster markers that have been removed
472
- // do not get redrawn. Same goes for a zoom in at maxZoom.
473
- if (
474
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
475
- // @ts-ignore
476
- _this.getMap().getZoom() === (_this.get('minZoom') || 0) ||
477
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
478
- // @ts-ignore
479
- _this.getMap().getZoom() === _this.get('maxZoom')) {
480
- google.maps.event.trigger(_this, 'idle');
481
- }
482
- }),
483
- google.maps.event.addListener(
484
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
485
- // @ts-ignore
486
- this.getMap(), 'idle', function () {
487
- _this.redraw();
488
- }),
489
- ];
510
+ if (map !== null) {
511
+ // Add the map event listeners
512
+ this.listeners = [
513
+ google.maps.event.addListener(map, 'zoom_changed', this.onZoomChanged),
514
+ google.maps.event.addListener(map, 'idle', this.onIdle),
515
+ ];
516
+ }
490
517
  };
491
518
  Clusterer.prototype.onRemove = function () {
492
519
  // Put all the managed markers back on the map:
@@ -730,20 +757,32 @@ var Clusterer = /** @class */ (function () {
730
757
  var trPix = projection.fromLatLngToDivPixel(
731
758
  // Turn the bounds into latlng.
732
759
  new google.maps.LatLng(bounds.getNorthEast().lat(), bounds.getNorthEast().lng()));
733
- trPix.x += this.gridSize;
734
- trPix.y -= this.gridSize;
760
+ if (trPix !== null) {
761
+ trPix.x += this.gridSize;
762
+ trPix.y -= this.gridSize;
763
+ }
735
764
  var blPix = projection.fromLatLngToDivPixel(
736
765
  // Turn the bounds into latlng.
737
766
  new google.maps.LatLng(bounds.getSouthWest().lat(), bounds.getSouthWest().lng()));
738
- blPix.x -= this.gridSize;
739
- blPix.y += this.gridSize;
767
+ if (blPix !== null) {
768
+ blPix.x -= this.gridSize;
769
+ blPix.y += this.gridSize;
770
+ }
740
771
  // Extend the bounds to contain the new bounds.
741
- bounds.extend(
742
- // Convert the pixel points back to LatLng nw
743
- projection.fromDivPixelToLatLng(trPix));
744
- bounds.extend(
745
- // Convert the pixel points back to LatLng sw
746
- projection.fromDivPixelToLatLng(blPix));
772
+ if (trPix !== null) {
773
+ // Convert the pixel points back to LatLng nw
774
+ var point1 = projection.fromDivPixelToLatLng(trPix);
775
+ if (point1 !== null) {
776
+ bounds.extend(point1);
777
+ }
778
+ }
779
+ if (blPix !== null) {
780
+ // Convert the pixel points back to LatLng sw
781
+ var point2 = projection.fromDivPixelToLatLng(blPix);
782
+ if (point2 !== null) {
783
+ bounds.extend(point2);
784
+ }
785
+ }
747
786
  return bounds;
748
787
  };
749
788
  Clusterer.prototype.redraw = function () {
@@ -830,6 +869,8 @@ var Clusterer = /** @class */ (function () {
830
869
  delete this.timerRefStatic;
831
870
  }
832
871
  }
872
+ var map = this.getMap();
873
+ var bounds = map !== null && 'getBounds' in map ? map.getBounds() : null;
833
874
  // Get our current map view bounds.
834
875
  // Create a new bounds object so we don't affect the map.
835
876
  //
@@ -837,24 +878,14 @@ var Clusterer = /** @class */ (function () {
837
878
  var mapBounds =
838
879
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
839
880
  // @ts-ignore
840
- this.getMap().getZoom() > 3
841
- ? new google.maps.LatLngBounds(
842
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
843
- // @ts-ignore
844
- this.getMap()
845
- .getBounds()
846
- .getSouthWest(),
847
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
848
- // @ts-ignore
849
- this.getMap()
850
- .getBounds()
851
- .getNorthEast())
881
+ map.getZoom() > 3
882
+ ? new google.maps.LatLngBounds(bounds === null || bounds === void 0 ? void 0 : bounds.getSouthWest(), bounds === null || bounds === void 0 ? void 0 : bounds.getNorthEast())
852
883
  : new google.maps.LatLngBounds(new google.maps.LatLng(85.02070771743472, -178.48388434375), new google.maps.LatLng(-85.08136444384544, 178.00048865625));
853
- var bounds = this.getExtendedBounds(mapBounds);
884
+ var extendedMapBounds = this.getExtendedBounds(mapBounds);
854
885
  var iLast = Math.min(iFirst + this.batchSize, this.markers.length);
855
886
  for (var i = iFirst; i < iLast; i++) {
856
887
  var marker = this.markers[i];
857
- if (!marker.isAdded && this.isMarkerInBounds(marker, bounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
888
+ if (!marker.isAdded && this.isMarkerInBounds(marker, extendedMapBounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
858
889
  this.addToClosestCluster(marker);
859
890
  }
860
891
  }
@@ -880,19 +911,14 @@ var Clusterer = /** @class */ (function () {
880
911
  };
881
912
  Clusterer.prototype.extend = function (obj1, obj2) {
882
913
  return function applyExtend(object) {
883
- // eslint-disable-next-line guard-for-in
884
914
  for (var property in object.prototype) {
885
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
886
- // @ts-ignore
887
- this.prototype[property] = object.prototype[property];
915
+ this.prototype.set(property, object.prototype.get(property));
888
916
  }
889
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
890
- // @ts-ignore
891
917
  return this;
892
918
  }.apply(obj1, [obj2]);
893
919
  };
894
920
  return Clusterer;
895
- }());
921
+ }(google.maps.OverlayView));
896
922
 
897
923
  exports.Cluster = Cluster;
898
924
  exports.ClusterIcon = ClusterIcon;