@react-google-maps/marker-clusterer 2.16.0 → 2.19.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
@@ -166,18 +166,18 @@
166
166
  this.visible = false;
167
167
  };
168
168
  ClusterIcon.prototype.show = function () {
169
- var _a, _b, _c, _d;
169
+ var _a, _b, _c, _d, _e, _f;
170
170
  if (this.div && this.center) {
171
171
  var divTitle = this.sums === null ||
172
172
  typeof this.sums.title === 'undefined' ||
173
173
  this.sums.title === '' ? this.cluster.getClusterer().getTitle() : this.sums.title;
174
174
  // NOTE: values must be specified in px units
175
175
  var bp = this.backgroundPosition.split(' ');
176
- var spriteH = parseInt(bp[0].replace(/^\s+|\s+$/g, ''), 10);
177
- var spriteV = parseInt(bp[1].replace(/^\s+|\s+$/g, ''), 10);
176
+ var spriteH = parseInt(((_a = bp[0]) === null || _a === void 0 ? void 0 : _a.replace(/^\s+|\s+$/g, '')) || '0', 10);
177
+ var spriteV = parseInt(((_b = bp[1]) === null || _b === void 0 ? void 0 : _b.replace(/^\s+|\s+$/g, '')) || '0', 10);
178
178
  var pos = this.getPosFromLatLng(this.center);
179
179
  this.div.className = this.className;
180
- this.div.setAttribute('style', "cursor: 'pointer'; position: 'absolute'; top: ".concat(pos !== null ? "".concat(pos.y, "px") : '0', "; left: ").concat(pos !== null ? "".concat(pos.x, "px") : '0', "; width: ").concat(this.width, "px; height: ").concat(this.height, "px; "));
180
+ this.div.setAttribute('style', "cursor: pointer; position: absolute; top: ".concat(pos !== null ? "".concat(pos.y, "px") : '0', "; left: ").concat(pos !== null ? "".concat(pos.x, "px") : '0', "; width: ").concat(this.width, "px; height: ").concat(this.height, "px; "));
181
181
  var img = document.createElement('img');
182
182
  img.alt = divTitle;
183
183
  img.src = this.url;
@@ -189,10 +189,10 @@
189
189
  }
190
190
  var textElm = document.createElement('div');
191
191
  textElm.setAttribute('style', "position: absolute; top: ".concat(this.anchorText[0], "px; left: ").concat(this.anchorText[1], "px; color: ").concat(this.textColor, "; font-size: ").concat(this.textSize, "px; font-family: ").concat(this.fontFamily, "; font-weight: ").concat(this.fontWeight, "; fontStyle: ").concat(this.fontStyle, "; text-decoration: ").concat(this.textDecoration, "; text-align: center; width: ").concat(this.width, "px; line-height: ").concat(this.height, "px"));
192
- if ((_a = this.sums) === null || _a === void 0 ? void 0 : _a.text)
193
- textElm.innerText = "".concat((_b = this.sums) === null || _b === void 0 ? void 0 : _b.text);
194
- if ((_c = this.sums) === null || _c === void 0 ? void 0 : _c.html)
195
- textElm.innerHTML = "".concat((_d = this.sums) === null || _d === void 0 ? void 0 : _d.html);
192
+ if ((_c = this.sums) === null || _c === void 0 ? void 0 : _c.text)
193
+ textElm.innerText = "".concat((_d = this.sums) === null || _d === void 0 ? void 0 : _d.text);
194
+ if ((_e = this.sums) === null || _e === void 0 ? void 0 : _e.html)
195
+ textElm.innerHTML = "".concat((_f = this.sums) === null || _f === void 0 ? void 0 : _f.html);
196
196
  this.div.innerHTML = '';
197
197
  this.div.appendChild(img);
198
198
  this.div.appendChild(textElm);
@@ -205,20 +205,23 @@
205
205
  this.sums = sums;
206
206
  var styles = this.cluster.getClusterer().getStyles();
207
207
  var style = styles[Math.min(styles.length - 1, Math.max(0, sums.index - 1))];
208
- this.url = style.url;
209
- this.height = style.height;
210
- this.width = style.width;
211
- if (style.className)
212
- this.className = "".concat(this.clusterClassName, " ").concat(style.className);
213
- this.anchorText = style.anchorText || [0, 0];
214
- this.anchorIcon = style.anchorIcon || [this.height / 2, this.width / 2];
215
- this.textColor = style.textColor || 'black';
216
- this.textSize = style.textSize || 11;
217
- this.textDecoration = style.textDecoration || 'none';
218
- this.fontWeight = style.fontWeight || 'bold';
219
- this.fontStyle = style.fontStyle || 'normal';
220
- this.fontFamily = style.fontFamily || 'Arial,sans-serif';
221
- this.backgroundPosition = style.backgroundPosition || '0 0';
208
+ if (style) {
209
+ this.url = style.url;
210
+ this.height = style.height;
211
+ this.width = style.width;
212
+ if (style.className) {
213
+ this.className = "".concat(this.clusterClassName, " ").concat(style.className);
214
+ }
215
+ this.anchorText = style.anchorText || [0, 0];
216
+ this.anchorIcon = style.anchorIcon || [this.height / 2, this.width / 2];
217
+ this.textColor = style.textColor || 'black';
218
+ this.textSize = style.textSize || 11;
219
+ this.textDecoration = style.textDecoration || 'none';
220
+ this.fontWeight = style.fontWeight || 'bold';
221
+ this.fontStyle = style.fontStyle || 'normal';
222
+ this.fontFamily = style.fontFamily || 'Arial,sans-serif';
223
+ this.backgroundPosition = style.backgroundPosition || '0 0';
224
+ }
222
225
  };
223
226
  ClusterIcon.prototype.setCenter = function (center) {
224
227
  this.center = center;
@@ -234,6 +237,7 @@
234
237
  return ClusterIcon;
235
238
  }());
236
239
 
240
+ /* global google */
237
241
  var Cluster = /** @class */ (function () {
238
242
  function Cluster(markerClusterer) {
239
243
  this.markerClusterer = markerClusterer;
@@ -276,8 +280,9 @@
276
280
  Cluster.prototype.getBounds = function () {
277
281
  var bounds = new google.maps.LatLngBounds(this.center, this.center);
278
282
  var markers = this.getMarkers();
279
- for (var i = 0; i < markers.length; i++) {
280
- var position = markers[i].getPosition();
283
+ for (var _i = 0, markers_1 = markers; _i < markers_1.length; _i++) {
284
+ var marker = markers_1[_i];
285
+ var position = marker.getPosition();
281
286
  if (position) {
282
287
  bounds.extend(position);
283
288
  }
@@ -332,8 +337,9 @@
332
337
  }
333
338
  else if (mCount === this.minClusterSize) {
334
339
  // Hide the markers that were showing.
335
- for (var i = 0; i < mCount; i++) {
336
- this.markers[i].setMap(null);
340
+ for (var _i = 0, _b = this.markers; _i < _b.length; _i++) {
341
+ var markerElement = _b[_i];
342
+ markerElement.setMap(null);
337
343
  }
338
344
  }
339
345
  else {
@@ -540,19 +546,22 @@
540
546
  };
541
547
  Clusterer.prototype.onRemove = function () {
542
548
  // Put all the managed markers back on the map:
543
- for (var i = 0; i < this.markers.length; i++) {
544
- if (this.markers[i].getMap() !== this.activeMap) {
545
- this.markers[i].setMap(this.activeMap);
549
+ for (var _i = 0, _a = this.markers; _i < _a.length; _i++) {
550
+ var marker = _a[_i];
551
+ if (marker.getMap() !== this.activeMap) {
552
+ marker.setMap(this.activeMap);
546
553
  }
547
554
  }
548
555
  // Remove all clusters:
549
- for (var i = 0; i < this.clusters.length; i++) {
550
- this.clusters[i].remove();
556
+ for (var _b = 0, _c = this.clusters; _b < _c.length; _b++) {
557
+ var cluster = _c[_b];
558
+ cluster.remove();
551
559
  }
552
560
  this.clusters = [];
553
561
  // Remove map event listeners:
554
- for (var i = 0; i < this.listeners.length; i++) {
555
- google.maps.event.removeListener(this.listeners[i]);
562
+ for (var _d = 0, _e = this.listeners; _d < _e.length; _d++) {
563
+ var listener = _e[_d];
564
+ google.maps.event.removeListener(listener);
556
565
  }
557
566
  this.listeners = [];
558
567
  this.activeMap = null;
@@ -566,16 +575,17 @@
566
575
  for (var i = 0; i < this.imageSizes.length; i++) {
567
576
  this.styles.push({
568
577
  url: "".concat(this.imagePath + (i + 1), ".").concat(this.imageExtension),
569
- height: this.imageSizes[i],
570
- width: this.imageSizes[i],
578
+ height: this.imageSizes[i] || 0,
579
+ width: this.imageSizes[i] || 0,
571
580
  });
572
581
  }
573
582
  };
574
583
  Clusterer.prototype.fitMapToMarkers = function () {
575
584
  var markers = this.getMarkers();
576
585
  var bounds = new google.maps.LatLngBounds();
577
- for (var i = 0; i < markers.length; i++) {
578
- var position = markers[i].getPosition();
586
+ for (var _i = 0, markers_1 = markers; _i < markers_1.length; _i++) {
587
+ var marker = markers_1[_i];
588
+ var position = marker.getPosition();
579
589
  if (position) {
580
590
  bounds.extend(position);
581
591
  }
@@ -696,7 +706,10 @@
696
706
  Clusterer.prototype.addMarkers = function (markers, optNoDraw) {
697
707
  for (var key in markers) {
698
708
  if (Object.prototype.hasOwnProperty.call(markers, key)) {
699
- this.pushMarkerTo(markers[key]);
709
+ var marker = markers[key];
710
+ if (marker) {
711
+ this.pushMarkerTo(marker);
712
+ }
700
713
  }
701
714
  }
702
715
  if (!optNoDraw) {
@@ -747,8 +760,9 @@
747
760
  };
748
761
  Clusterer.prototype.removeMarkers = function (markers, optNoDraw) {
749
762
  var removed = false;
750
- for (var i = 0; i < markers.length; i++) {
751
- removed = removed || this.removeMarker_(markers[i]);
763
+ for (var _i = 0, markers_2 = markers; _i < markers_2.length; _i++) {
764
+ var marker = markers_2[_i];
765
+ removed = removed || this.removeMarker_(marker);
752
766
  }
753
767
  if (!optNoDraw && removed) {
754
768
  this.repaint();
@@ -767,8 +781,9 @@
767
781
  // Remove the old clusters.
768
782
  // Do it in a timeout to prevent blinking effect.
769
783
  setTimeout(function timeout() {
770
- for (var i = 0; i < oldClusters.length; i++) {
771
- oldClusters[i].remove();
784
+ for (var _i = 0, oldClusters_1 = oldClusters; _i < oldClusters_1.length; _i++) {
785
+ var oldCluster = oldClusters_1[_i];
786
+ oldCluster.remove();
772
787
  }
773
788
  }, 0);
774
789
  };
@@ -812,13 +827,14 @@
812
827
  };
813
828
  Clusterer.prototype.resetViewport = function (optHide) {
814
829
  // Remove all the clusters
815
- for (var i = 0; i < this.clusters.length; i++) {
816
- this.clusters[i].remove();
830
+ for (var _i = 0, _a = this.clusters; _i < _a.length; _i++) {
831
+ var cluster = _a[_i];
832
+ cluster.remove();
817
833
  }
818
834
  this.clusters = [];
819
835
  // Reset the markers to not be added and to be removed from the map.
820
- for (var i = 0; i < this.markers.length; i++) {
821
- var marker = this.markers[i];
836
+ for (var _b = 0, _c = this.markers; _b < _c.length; _b++) {
837
+ var marker = _c[_b];
822
838
  marker.isAdded = false;
823
839
  if (optHide) {
824
840
  marker.setMap(null);
@@ -847,8 +863,9 @@
847
863
  var cluster;
848
864
  var distance = 40000; // Some large number
849
865
  var clusterToAddTo = null;
850
- for (var i = 0; i < this.clusters.length; i++) {
851
- cluster = this.clusters[i];
866
+ for (var _i = 0, _a = this.clusters; _i < _a.length; _i++) {
867
+ var clusterElement = _a[_i];
868
+ cluster = clusterElement;
852
869
  var center = cluster.getCenter();
853
870
  var position = marker.getPosition();
854
871
  if (center && position) {
@@ -904,7 +921,7 @@
904
921
  var iLast = Math.min(iFirst + this.batchSize, this.markers.length);
905
922
  for (var i = iFirst; i < iLast; i++) {
906
923
  var marker = this.markers[i];
907
- if (!marker.isAdded && this.isMarkerInBounds(marker, extendedMapBounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
924
+ if (marker && !marker.isAdded && this.isMarkerInBounds(marker, extendedMapBounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
908
925
  this.addToClosestCluster(marker);
909
926
  }
910
927
  }
@@ -923,18 +940,21 @@
923
940
  * @event
924
941
  */
925
942
  google.maps.event.trigger(this, 'clusteringend', this);
926
- for (var i = 0; i < this.clusters.length; i++) {
927
- this.clusters[i].updateIcon();
943
+ for (var _i = 0, _a = this.clusters; _i < _a.length; _i++) {
944
+ var cluster = _a[_i];
945
+ cluster.updateIcon();
928
946
  }
929
947
  }
930
948
  };
931
949
  Clusterer.prototype.extend = function (obj1, obj2) {
932
950
  return function applyExtend(object) {
933
951
  for (var property in object.prototype) {
952
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
934
953
  // @ts-ignore
935
954
  this.prototype[property] = object.prototype[property];
936
955
  }
937
956
  return this;
957
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
938
958
  }.apply(obj1, [obj2]);
939
959
  };
940
960
  return Clusterer;