@react-google-maps/marker-clusterer 2.8.0 → 2.10.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
@@ -26,87 +26,100 @@ var ClusterIcon = /** @class */ (function () {
26
26
  this.fontStyle = 'normal';
27
27
  this.fontFamily = 'Arial,sans-serif';
28
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
29
33
  // @ts-ignore
30
34
  this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
31
35
  }
36
+ ClusterIcon.prototype.onBoundsChanged = function () {
37
+ this.cDraggingMapByCluster = this.cMouseDownInCluster;
38
+ };
39
+ ClusterIcon.prototype.onMouseDown = function () {
40
+ this.cMouseDownInCluster = true;
41
+ this.cDraggingMapByCluster = false;
42
+ };
43
+ ClusterIcon.prototype.onClick = function (event) {
44
+ this.cMouseDownInCluster = false;
45
+ if (!this.cDraggingMapByCluster) {
46
+ var markerClusterer_1 = this.cluster.getClusterer();
47
+ /**
48
+ * This event is fired when a cluster marker is clicked.
49
+ * @name MarkerClusterer#click
50
+ * @param {Cluster} c The cluster that was clicked.
51
+ * @event
52
+ */
53
+ google.maps.event.trigger(markerClusterer_1, 'click', this.cluster);
54
+ google.maps.event.trigger(markerClusterer_1, 'clusterclick', this.cluster); // deprecated name
55
+ // The default click handler follows. Disable it by setting
56
+ // the zoomOnClick property to false.
57
+ if (markerClusterer_1.getZoomOnClick()) {
58
+ // Zoom into the cluster.
59
+ var maxZoom_1 = markerClusterer_1.getMaxZoom();
60
+ var bounds_1 = this.cluster.getBounds();
61
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
62
+ // @ts-ignore
63
+ markerClusterer_1.getMap().fitBounds(bounds_1);
64
+ // There is a fix for Issue 170 here:
65
+ this.timeOut = window.setTimeout(function () {
66
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
67
+ // @ts-ignore
68
+ markerClusterer_1.getMap().fitBounds(bounds_1);
69
+ // Don't zoom beyond the max zoom level
70
+ if (maxZoom_1 !== null &&
71
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
72
+ // @ts-ignore
73
+ markerClusterer_1.getMap().getZoom() > maxZoom_1) {
74
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
75
+ // @ts-ignore
76
+ markerClusterer_1.getMap().setZoom(maxZoom_1 + 1);
77
+ }
78
+ }, 100);
79
+ }
80
+ // Prevent event propagation to the map:
81
+ event.cancelBubble = true;
82
+ if (event.stopPropagation) {
83
+ event.stopPropagation();
84
+ }
85
+ }
86
+ };
87
+ ClusterIcon.prototype.onMouseOver = function () {
88
+ /**
89
+ * This event is fired when the mouse moves over a cluster marker.
90
+ * @name MarkerClusterer#mouseover
91
+ * @param {Cluster} c The cluster that the mouse moved over.
92
+ * @event
93
+ */
94
+ google.maps.event.trigger(this.cluster.getClusterer(), 'mouseover', this.cluster);
95
+ };
96
+ ClusterIcon.prototype.onMouseOut = function () {
97
+ /**
98
+ * This event is fired when the mouse moves out of a cluster marker.
99
+ * @name MarkerClusterer#mouseout
100
+ * @param {Cluster} c The cluster that the mouse moved out of.
101
+ * @event
102
+ */
103
+ google.maps.event.trigger(this.cluster.getClusterer(), 'mouseout', this.cluster);
104
+ };
32
105
  ClusterIcon.prototype.onAdd = function () {
33
- var _this = this;
34
- var cMouseDownInCluster;
35
- var cDraggingMapByCluster;
36
106
  this.div = document.createElement('div');
37
107
  this.div.className = this.className;
38
108
  if (this.visible) {
39
109
  this.show();
40
110
  }
111
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
41
112
  // @ts-ignore
42
113
  this.getPanes().overlayMouseTarget.appendChild(this.div);
43
114
  // Fix for Issue 157
44
115
  this.boundsChangedListener = google.maps.event.addListener(
116
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
45
117
  // @ts-ignore
46
- this.getMap(), 'boundschanged', function boundsChanged() {
47
- cDraggingMapByCluster = cMouseDownInCluster;
48
- });
49
- google.maps.event.addDomListener(this.div, 'mousedown', function onMouseDown() {
50
- cMouseDownInCluster = true;
51
- cDraggingMapByCluster = false;
52
- });
53
- google.maps.event.addDomListener(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.addDomListener(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.addDomListener(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
- });
118
+ this.getMap(), 'bounds_changed', this.onBoundsChanged);
119
+ this.div.addEventListener('mousedown', this.onMouseDown);
120
+ this.div.addEventListener('click', this.onClick);
121
+ this.div.addEventListener('mouseover', this.onMouseOver);
122
+ this.div.addEventListener('mouseout', this.onMouseOut);
110
123
  };
111
124
  ClusterIcon.prototype.onRemove = function () {
112
125
  if (this.div && this.div.parentNode) {
@@ -114,16 +127,23 @@ var ClusterIcon = /** @class */ (function () {
114
127
  if (this.boundsChangedListener !== null) {
115
128
  google.maps.event.removeListener(this.boundsChangedListener);
116
129
  }
117
- google.maps.event.clearInstanceListeners(this.div);
130
+ this.div.removeEventListener('mousedown', this.onMouseDown);
131
+ this.div.removeEventListener('click', this.onClick);
132
+ this.div.removeEventListener('mouseover', this.onMouseOver);
133
+ this.div.removeEventListener('mouseout', this.onMouseOut);
118
134
  this.div.parentNode.removeChild(this.div);
135
+ if (this.timeOut !== null) {
136
+ window.clearTimeout(this.timeOut);
137
+ this.timeOut = null;
138
+ }
119
139
  this.div = null;
120
140
  }
121
141
  };
122
142
  ClusterIcon.prototype.draw = function () {
123
143
  if (this.visible && this.div !== null && this.center) {
124
144
  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';
145
+ this.div.style.top = "".concat(y, "px");
146
+ this.div.style.left = "".concat(x, "px");
127
147
  }
128
148
  };
129
149
  ClusterIcon.prototype.hide = function () {
@@ -141,7 +161,9 @@ var ClusterIcon = /** @class */ (function () {
141
161
  var spriteH = parseInt(bp[0].replace(/^\s+|\s+$/g, ''), 10);
142
162
  var spriteV = parseInt(bp[1].replace(/^\s+|\s+$/g, ''), 10);
143
163
  var pos = this.getPosFromLatLng(this.center);
144
- if (this.sums === null || typeof this.sums.title === 'undefined' || this.sums.title === '') {
164
+ if (this.sums === null ||
165
+ typeof this.sums.title === 'undefined' ||
166
+ this.sums.title === '') {
145
167
  divTitle = this.cluster.getClusterer().getTitle();
146
168
  }
147
169
  else {
@@ -211,8 +233,6 @@ var ClusterIcon = /** @class */ (function () {
211
233
  var pos = this.getProjection().fromLatLngToDivPixel(latlng);
212
234
  pos.x -= this.anchorIcon[1];
213
235
  pos.y -= this.anchorIcon[0];
214
- // pos.x = pos.x
215
- // pos.y = pos.y
216
236
  return pos;
217
237
  };
218
238
  return ClusterIcon;
@@ -221,6 +241,7 @@ var ClusterIcon = /** @class */ (function () {
221
241
  var Cluster = /** @class */ (function () {
222
242
  function Cluster(markerClusterer) {
223
243
  this.markerClusterer = markerClusterer;
244
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
224
245
  // @ts-ignore
225
246
  this.map = this.markerClusterer.getMap();
226
247
  this.gridSize = this.markerClusterer.getGridSize();
@@ -258,9 +279,11 @@ var Cluster = /** @class */ (function () {
258
279
  return bounds;
259
280
  };
260
281
  Cluster.prototype.remove = function () {
282
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
261
283
  // @ts-ignore
262
284
  this.clusterIcon.setMap(null);
263
285
  this.markers = [];
286
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
264
287
  // @ts-ignore
265
288
  delete this.markers;
266
289
  };
@@ -348,11 +371,9 @@ var Cluster = /** @class */ (function () {
348
371
  if (this.markers.includes) {
349
372
  return this.markers.includes(marker);
350
373
  }
351
- else {
352
- for (var i = 0; i < this.markers.length; i++) {
353
- if (marker === this.markers[i]) {
354
- return true;
355
- }
374
+ for (var i = 0; i < this.markers.length; i++) {
375
+ if (marker === this.markers[i]) {
376
+ return true;
356
377
  }
357
378
  }
358
379
  return false;
@@ -426,11 +447,13 @@ var Clusterer = /** @class */ (function () {
426
447
  this.timerRefStatic = null;
427
448
  this.setupStyles();
428
449
  this.addMarkers(optMarkers, true);
450
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
429
451
  // @ts-ignore
430
452
  this.setMap(map); // Note: this causes onAdd to be called
431
453
  }
432
454
  Clusterer.prototype.onAdd = function () {
433
455
  var _this = this;
456
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
434
457
  // @ts-ignore
435
458
  this.activeMap = this.getMap();
436
459
  this.ready = true;
@@ -438,6 +461,7 @@ var Clusterer = /** @class */ (function () {
438
461
  // Add the map event listeners
439
462
  this.listeners = [
440
463
  google.maps.event.addListener(
464
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
441
465
  // @ts-ignore
442
466
  this.getMap(), 'zoom_changed', function () {
443
467
  _this.resetViewport(false);
@@ -447,14 +471,17 @@ var Clusterer = /** @class */ (function () {
447
471
  // event is triggered so the cluster markers that have been removed
448
472
  // do not get redrawn. Same goes for a zoom in at maxZoom.
449
473
  if (
474
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
450
475
  // @ts-ignore
451
476
  _this.getMap().getZoom() === (_this.get('minZoom') || 0) ||
477
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
452
478
  // @ts-ignore
453
479
  _this.getMap().getZoom() === _this.get('maxZoom')) {
454
480
  google.maps.event.trigger(_this, 'idle');
455
481
  }
456
482
  }),
457
483
  google.maps.event.addListener(
484
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
458
485
  // @ts-ignore
459
486
  this.getMap(), 'idle', function () {
460
487
  _this.redraw();
@@ -504,6 +531,7 @@ var Clusterer = /** @class */ (function () {
504
531
  bounds.extend(position);
505
532
  }
506
533
  }
534
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
507
535
  // @ts-ignore
508
536
  this.getMap().fitBounds(bounds);
509
537
  };
@@ -695,6 +723,7 @@ var Clusterer = /** @class */ (function () {
695
723
  }, 0);
696
724
  };
697
725
  Clusterer.prototype.getExtendedBounds = function (bounds) {
726
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
698
727
  // @ts-ignore
699
728
  var projection = this.getProjection();
700
729
  // Convert the points to pixels and the extend out by the grid size.
@@ -796,6 +825,7 @@ var Clusterer = /** @class */ (function () {
796
825
  google.maps.event.trigger(this, 'clusteringbegin', this);
797
826
  if (this.timerRefStatic !== null) {
798
827
  window.clearTimeout(this.timerRefStatic);
828
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
799
829
  // @ts-ignore
800
830
  delete this.timerRefStatic;
801
831
  }
@@ -805,13 +835,16 @@ var Clusterer = /** @class */ (function () {
805
835
  //
806
836
  // See Comments 9 & 11 on Issue 3651 relating to this workaround for a Google Maps bug:
807
837
  var mapBounds =
838
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
808
839
  // @ts-ignore
809
840
  this.getMap().getZoom() > 3
810
841
  ? new google.maps.LatLngBounds(
842
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
811
843
  // @ts-ignore
812
844
  this.getMap()
813
845
  .getBounds()
814
846
  .getSouthWest(),
847
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
815
848
  // @ts-ignore
816
849
  this.getMap()
817
850
  .getBounds()
@@ -821,10 +854,8 @@ var Clusterer = /** @class */ (function () {
821
854
  var iLast = Math.min(iFirst + this.batchSize, this.markers.length);
822
855
  for (var i = iFirst; i < iLast; i++) {
823
856
  var marker = this.markers[i];
824
- if (!marker.isAdded && this.isMarkerInBounds(marker, bounds)) {
825
- if (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible())) {
826
- this.addToClosestCluster(marker);
827
- }
857
+ if (!marker.isAdded && this.isMarkerInBounds(marker, bounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
858
+ this.addToClosestCluster(marker);
828
859
  }
829
860
  }
830
861
  if (iLast < this.markers.length) {
@@ -851,9 +882,11 @@ var Clusterer = /** @class */ (function () {
851
882
  return function applyExtend(object) {
852
883
  // eslint-disable-next-line guard-for-in
853
884
  for (var property in object.prototype) {
885
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
854
886
  // @ts-ignore
855
887
  this.prototype[property] = object.prototype[property];
856
888
  }
889
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
857
890
  // @ts-ignore
858
891
  return this;
859
892
  }.apply(obj1, [obj2]);