@react-google-maps/marker-clusterer 2.16.1 → 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.
@@ -0,0 +1,28 @@
1
+ /// <reference types="google.maps" />
2
+ import type { Clusterer } from './Clusterer';
3
+ import { ClusterIcon } from './ClusterIcon';
4
+ import type { MarkerExtended } from './types';
5
+ export declare class Cluster {
6
+ markerClusterer: Clusterer;
7
+ map: google.maps.Map | google.maps.StreetViewPanorama | null;
8
+ gridSize: number;
9
+ minClusterSize: number;
10
+ averageCenter: boolean;
11
+ markers: MarkerExtended[];
12
+ center: google.maps.LatLng | undefined;
13
+ bounds: google.maps.LatLngBounds | null;
14
+ clusterIcon: ClusterIcon;
15
+ constructor(markerClusterer: Clusterer);
16
+ getSize(): number;
17
+ getMarkers(): MarkerExtended[];
18
+ getCenter(): google.maps.LatLng | undefined;
19
+ getMap(): google.maps.Map | google.maps.StreetViewPanorama | null;
20
+ getClusterer(): Clusterer;
21
+ getBounds(): google.maps.LatLngBounds;
22
+ remove(): void;
23
+ addMarker(marker: MarkerExtended): boolean;
24
+ isMarkerInClusterBounds(marker: MarkerExtended): boolean;
25
+ calculateBounds(): void;
26
+ updateIcon(): void;
27
+ isMarkerAlreadyAdded(marker: MarkerExtended): boolean;
28
+ }
@@ -0,0 +1,43 @@
1
+ /// <reference types="google.maps" />
2
+ import type { Cluster } from './Cluster';
3
+ import type { ClusterIconStyle, ClusterIconInfo } from './types';
4
+ export declare class ClusterIcon {
5
+ cluster: Cluster;
6
+ className: string;
7
+ clusterClassName: string;
8
+ styles: ClusterIconStyle[];
9
+ center: google.maps.LatLng | undefined;
10
+ div: HTMLDivElement | null;
11
+ sums: ClusterIconInfo | null;
12
+ visible: boolean;
13
+ url: string;
14
+ height: number;
15
+ width: number;
16
+ anchorText: [number, number];
17
+ anchorIcon: [number, number];
18
+ textColor: string;
19
+ textSize: number;
20
+ textDecoration: string;
21
+ fontWeight: string;
22
+ fontStyle: string;
23
+ fontFamily: string;
24
+ backgroundPosition: string;
25
+ cMouseDownInCluster: boolean | null;
26
+ cDraggingMapByCluster: boolean | null;
27
+ timeOut: number | null;
28
+ boundsChangedListener: google.maps.MapsEventListener | null;
29
+ constructor(cluster: Cluster, styles: ClusterIconStyle[]);
30
+ onBoundsChanged(): void;
31
+ onMouseDown(): void;
32
+ onClick(event: Event): void;
33
+ onMouseOver(): void;
34
+ onMouseOut(): void;
35
+ onAdd(): void;
36
+ onRemove(): void;
37
+ draw(): void;
38
+ hide(): void;
39
+ show(): void;
40
+ useStyle(sums: ClusterIconInfo): void;
41
+ setCenter(center: google.maps.LatLng): void;
42
+ getPosFromLatLng(latlng: google.maps.LatLng): google.maps.Point | null;
43
+ }
@@ -0,0 +1,86 @@
1
+ /// <reference types="google.maps" />
2
+ import { Cluster } from './Cluster';
3
+ import type { ClusterIcon } from './ClusterIcon';
4
+ import type { MarkerExtended, ClustererOptions, ClusterIconStyle, TCalculator } from './types';
5
+ export declare class Clusterer {
6
+ markers: MarkerExtended[];
7
+ clusters: Cluster[];
8
+ listeners: google.maps.MapsEventListener[];
9
+ activeMap: google.maps.Map | google.maps.StreetViewPanorama | null;
10
+ ready: boolean;
11
+ gridSize: number;
12
+ minClusterSize: number;
13
+ maxZoom: number | null;
14
+ styles: ClusterIconStyle[];
15
+ title: string;
16
+ zoomOnClick: boolean;
17
+ averageCenter: boolean;
18
+ ignoreHidden: boolean;
19
+ enableRetinaIcons: boolean;
20
+ imagePath: string;
21
+ imageExtension: string;
22
+ imageSizes: number[];
23
+ calculator: TCalculator;
24
+ batchSize: number;
25
+ batchSizeIE: number;
26
+ clusterClass: string;
27
+ timerRefStatic: number | null;
28
+ constructor(map: google.maps.Map, optMarkers?: MarkerExtended[], optOptions?: ClustererOptions);
29
+ onZoomChanged(): void;
30
+ onIdle(): void;
31
+ onAdd(): void;
32
+ onRemove(): void;
33
+ draw(): void;
34
+ setupStyles(): void;
35
+ fitMapToMarkers(): void;
36
+ getGridSize(): number;
37
+ setGridSize(gridSize: number): void;
38
+ getMinimumClusterSize(): number;
39
+ setMinimumClusterSize(minimumClusterSize: number): void;
40
+ getMaxZoom(): number | null;
41
+ setMaxZoom(maxZoom: number): void;
42
+ getStyles(): ClusterIconStyle[];
43
+ setStyles(styles: ClusterIconStyle[]): void;
44
+ getTitle(): string;
45
+ setTitle(title: string): void;
46
+ getZoomOnClick(): boolean;
47
+ setZoomOnClick(zoomOnClick: boolean): void;
48
+ getAverageCenter(): boolean;
49
+ setAverageCenter(averageCenter: boolean): void;
50
+ getIgnoreHidden(): boolean;
51
+ setIgnoreHidden(ignoreHidden: boolean): void;
52
+ getEnableRetinaIcons(): boolean;
53
+ setEnableRetinaIcons(enableRetinaIcons: boolean): void;
54
+ getImageExtension(): string;
55
+ setImageExtension(imageExtension: string): void;
56
+ getImagePath(): string;
57
+ setImagePath(imagePath: string): void;
58
+ getImageSizes(): number[];
59
+ setImageSizes(imageSizes: number[]): void;
60
+ getCalculator(): TCalculator;
61
+ setCalculator(calculator: TCalculator): void;
62
+ getBatchSizeIE(): number;
63
+ setBatchSizeIE(batchSizeIE: number): void;
64
+ getClusterClass(): string;
65
+ setClusterClass(clusterClass: string): void;
66
+ getMarkers(): MarkerExtended[];
67
+ getTotalMarkers(): number;
68
+ getClusters(): Cluster[];
69
+ getTotalClusters(): number;
70
+ addMarker(marker: MarkerExtended, optNoDraw: boolean): void;
71
+ addMarkers(markers: MarkerExtended[], optNoDraw: boolean): void;
72
+ pushMarkerTo(marker: MarkerExtended): void;
73
+ removeMarker_(marker: MarkerExtended): boolean;
74
+ removeMarker(marker: MarkerExtended, optNoDraw: boolean): boolean;
75
+ removeMarkers(markers: MarkerExtended[], optNoDraw: boolean): boolean;
76
+ clearMarkers(): void;
77
+ repaint(): void;
78
+ getExtendedBounds(bounds: google.maps.LatLngBounds): google.maps.LatLngBounds;
79
+ redraw(): void;
80
+ resetViewport(optHide: boolean): void;
81
+ distanceBetweenPoints(p1: google.maps.LatLng, p2: google.maps.LatLng): number;
82
+ isMarkerInBounds(marker: MarkerExtended, bounds: google.maps.LatLngBounds): boolean;
83
+ addToClosestCluster(marker: MarkerExtended): void;
84
+ createClusters(iFirst: number): void;
85
+ extend<A extends typeof ClusterIcon | typeof Clusterer>(obj1: A, obj2: typeof google.maps.OverlayView): A;
86
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
package/dist/cjs.js CHANGED
@@ -164,15 +164,15 @@ var ClusterIcon = /** @class */ (function () {
164
164
  this.visible = false;
165
165
  };
166
166
  ClusterIcon.prototype.show = function () {
167
- var _a, _b, _c, _d;
167
+ var _a, _b, _c, _d, _e, _f;
168
168
  if (this.div && this.center) {
169
169
  var divTitle = this.sums === null ||
170
170
  typeof this.sums.title === 'undefined' ||
171
171
  this.sums.title === '' ? this.cluster.getClusterer().getTitle() : this.sums.title;
172
172
  // NOTE: values must be specified in px units
173
173
  var bp = this.backgroundPosition.split(' ');
174
- var spriteH = parseInt(bp[0].replace(/^\s+|\s+$/g, ''), 10);
175
- var spriteV = parseInt(bp[1].replace(/^\s+|\s+$/g, ''), 10);
174
+ var spriteH = parseInt(((_a = bp[0]) === null || _a === void 0 ? void 0 : _a.replace(/^\s+|\s+$/g, '')) || '0', 10);
175
+ var spriteV = parseInt(((_b = bp[1]) === null || _b === void 0 ? void 0 : _b.replace(/^\s+|\s+$/g, '')) || '0', 10);
176
176
  var pos = this.getPosFromLatLng(this.center);
177
177
  this.div.className = this.className;
178
178
  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; "));
@@ -187,10 +187,10 @@ var ClusterIcon = /** @class */ (function () {
187
187
  }
188
188
  var textElm = document.createElement('div');
189
189
  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"));
190
- if ((_a = this.sums) === null || _a === void 0 ? void 0 : _a.text)
191
- textElm.innerText = "".concat((_b = this.sums) === null || _b === void 0 ? void 0 : _b.text);
192
- if ((_c = this.sums) === null || _c === void 0 ? void 0 : _c.html)
193
- textElm.innerHTML = "".concat((_d = this.sums) === null || _d === void 0 ? void 0 : _d.html);
190
+ if ((_c = this.sums) === null || _c === void 0 ? void 0 : _c.text)
191
+ textElm.innerText = "".concat((_d = this.sums) === null || _d === void 0 ? void 0 : _d.text);
192
+ if ((_e = this.sums) === null || _e === void 0 ? void 0 : _e.html)
193
+ textElm.innerHTML = "".concat((_f = this.sums) === null || _f === void 0 ? void 0 : _f.html);
194
194
  this.div.innerHTML = '';
195
195
  this.div.appendChild(img);
196
196
  this.div.appendChild(textElm);
@@ -203,20 +203,23 @@ var ClusterIcon = /** @class */ (function () {
203
203
  this.sums = sums;
204
204
  var styles = this.cluster.getClusterer().getStyles();
205
205
  var style = styles[Math.min(styles.length - 1, Math.max(0, sums.index - 1))];
206
- this.url = style.url;
207
- this.height = style.height;
208
- this.width = style.width;
209
- if (style.className)
210
- this.className = "".concat(this.clusterClassName, " ").concat(style.className);
211
- this.anchorText = style.anchorText || [0, 0];
212
- this.anchorIcon = style.anchorIcon || [this.height / 2, this.width / 2];
213
- this.textColor = style.textColor || 'black';
214
- this.textSize = style.textSize || 11;
215
- this.textDecoration = style.textDecoration || 'none';
216
- this.fontWeight = style.fontWeight || 'bold';
217
- this.fontStyle = style.fontStyle || 'normal';
218
- this.fontFamily = style.fontFamily || 'Arial,sans-serif';
219
- this.backgroundPosition = style.backgroundPosition || '0 0';
206
+ if (style) {
207
+ this.url = style.url;
208
+ this.height = style.height;
209
+ this.width = style.width;
210
+ if (style.className) {
211
+ this.className = "".concat(this.clusterClassName, " ").concat(style.className);
212
+ }
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';
222
+ }
220
223
  };
221
224
  ClusterIcon.prototype.setCenter = function (center) {
222
225
  this.center = center;
@@ -232,6 +235,7 @@ var ClusterIcon = /** @class */ (function () {
232
235
  return ClusterIcon;
233
236
  }());
234
237
 
238
+ /* global google */
235
239
  var Cluster = /** @class */ (function () {
236
240
  function Cluster(markerClusterer) {
237
241
  this.markerClusterer = markerClusterer;
@@ -274,8 +278,9 @@ var Cluster = /** @class */ (function () {
274
278
  Cluster.prototype.getBounds = function () {
275
279
  var bounds = new google.maps.LatLngBounds(this.center, this.center);
276
280
  var markers = this.getMarkers();
277
- for (var i = 0; i < markers.length; i++) {
278
- var position = markers[i].getPosition();
281
+ for (var _i = 0, markers_1 = markers; _i < markers_1.length; _i++) {
282
+ var marker = markers_1[_i];
283
+ var position = marker.getPosition();
279
284
  if (position) {
280
285
  bounds.extend(position);
281
286
  }
@@ -330,8 +335,9 @@ var Cluster = /** @class */ (function () {
330
335
  }
331
336
  else if (mCount === this.minClusterSize) {
332
337
  // Hide the markers that were showing.
333
- for (var i = 0; i < mCount; i++) {
334
- this.markers[i].setMap(null);
338
+ for (var _i = 0, _b = this.markers; _i < _b.length; _i++) {
339
+ var markerElement = _b[_i];
340
+ markerElement.setMap(null);
335
341
  }
336
342
  }
337
343
  else {
@@ -538,19 +544,22 @@ var Clusterer = /** @class */ (function () {
538
544
  };
539
545
  Clusterer.prototype.onRemove = function () {
540
546
  // Put all the managed markers back on the map:
541
- for (var i = 0; i < this.markers.length; i++) {
542
- if (this.markers[i].getMap() !== this.activeMap) {
543
- this.markers[i].setMap(this.activeMap);
547
+ for (var _i = 0, _a = this.markers; _i < _a.length; _i++) {
548
+ var marker = _a[_i];
549
+ if (marker.getMap() !== this.activeMap) {
550
+ marker.setMap(this.activeMap);
544
551
  }
545
552
  }
546
553
  // Remove all clusters:
547
- for (var i = 0; i < this.clusters.length; i++) {
548
- this.clusters[i].remove();
554
+ for (var _b = 0, _c = this.clusters; _b < _c.length; _b++) {
555
+ var cluster = _c[_b];
556
+ cluster.remove();
549
557
  }
550
558
  this.clusters = [];
551
559
  // Remove map event listeners:
552
- for (var i = 0; i < this.listeners.length; i++) {
553
- google.maps.event.removeListener(this.listeners[i]);
560
+ for (var _d = 0, _e = this.listeners; _d < _e.length; _d++) {
561
+ var listener = _e[_d];
562
+ google.maps.event.removeListener(listener);
554
563
  }
555
564
  this.listeners = [];
556
565
  this.activeMap = null;
@@ -564,16 +573,17 @@ var Clusterer = /** @class */ (function () {
564
573
  for (var i = 0; i < this.imageSizes.length; i++) {
565
574
  this.styles.push({
566
575
  url: "".concat(this.imagePath + (i + 1), ".").concat(this.imageExtension),
567
- height: this.imageSizes[i],
568
- width: this.imageSizes[i],
576
+ height: this.imageSizes[i] || 0,
577
+ width: this.imageSizes[i] || 0,
569
578
  });
570
579
  }
571
580
  };
572
581
  Clusterer.prototype.fitMapToMarkers = function () {
573
582
  var markers = this.getMarkers();
574
583
  var bounds = new google.maps.LatLngBounds();
575
- for (var i = 0; i < markers.length; i++) {
576
- var position = markers[i].getPosition();
584
+ for (var _i = 0, markers_1 = markers; _i < markers_1.length; _i++) {
585
+ var marker = markers_1[_i];
586
+ var position = marker.getPosition();
577
587
  if (position) {
578
588
  bounds.extend(position);
579
589
  }
@@ -694,7 +704,10 @@ var Clusterer = /** @class */ (function () {
694
704
  Clusterer.prototype.addMarkers = function (markers, optNoDraw) {
695
705
  for (var key in markers) {
696
706
  if (Object.prototype.hasOwnProperty.call(markers, key)) {
697
- this.pushMarkerTo(markers[key]);
707
+ var marker = markers[key];
708
+ if (marker) {
709
+ this.pushMarkerTo(marker);
710
+ }
698
711
  }
699
712
  }
700
713
  if (!optNoDraw) {
@@ -745,8 +758,9 @@ var Clusterer = /** @class */ (function () {
745
758
  };
746
759
  Clusterer.prototype.removeMarkers = function (markers, optNoDraw) {
747
760
  var removed = false;
748
- for (var i = 0; i < markers.length; i++) {
749
- removed = removed || this.removeMarker_(markers[i]);
761
+ for (var _i = 0, markers_2 = markers; _i < markers_2.length; _i++) {
762
+ var marker = markers_2[_i];
763
+ removed = removed || this.removeMarker_(marker);
750
764
  }
751
765
  if (!optNoDraw && removed) {
752
766
  this.repaint();
@@ -765,8 +779,9 @@ var Clusterer = /** @class */ (function () {
765
779
  // Remove the old clusters.
766
780
  // Do it in a timeout to prevent blinking effect.
767
781
  setTimeout(function timeout() {
768
- for (var i = 0; i < oldClusters.length; i++) {
769
- oldClusters[i].remove();
782
+ for (var _i = 0, oldClusters_1 = oldClusters; _i < oldClusters_1.length; _i++) {
783
+ var oldCluster = oldClusters_1[_i];
784
+ oldCluster.remove();
770
785
  }
771
786
  }, 0);
772
787
  };
@@ -810,13 +825,14 @@ var Clusterer = /** @class */ (function () {
810
825
  };
811
826
  Clusterer.prototype.resetViewport = function (optHide) {
812
827
  // Remove all the clusters
813
- for (var i = 0; i < this.clusters.length; i++) {
814
- this.clusters[i].remove();
828
+ for (var _i = 0, _a = this.clusters; _i < _a.length; _i++) {
829
+ var cluster = _a[_i];
830
+ cluster.remove();
815
831
  }
816
832
  this.clusters = [];
817
833
  // Reset the markers to not be added and to be removed from the map.
818
- for (var i = 0; i < this.markers.length; i++) {
819
- var marker = this.markers[i];
834
+ for (var _b = 0, _c = this.markers; _b < _c.length; _b++) {
835
+ var marker = _c[_b];
820
836
  marker.isAdded = false;
821
837
  if (optHide) {
822
838
  marker.setMap(null);
@@ -845,8 +861,9 @@ var Clusterer = /** @class */ (function () {
845
861
  var cluster;
846
862
  var distance = 40000; // Some large number
847
863
  var clusterToAddTo = null;
848
- for (var i = 0; i < this.clusters.length; i++) {
849
- cluster = this.clusters[i];
864
+ for (var _i = 0, _a = this.clusters; _i < _a.length; _i++) {
865
+ var clusterElement = _a[_i];
866
+ cluster = clusterElement;
850
867
  var center = cluster.getCenter();
851
868
  var position = marker.getPosition();
852
869
  if (center && position) {
@@ -902,7 +919,7 @@ var Clusterer = /** @class */ (function () {
902
919
  var iLast = Math.min(iFirst + this.batchSize, this.markers.length);
903
920
  for (var i = iFirst; i < iLast; i++) {
904
921
  var marker = this.markers[i];
905
- if (!marker.isAdded && this.isMarkerInBounds(marker, extendedMapBounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
922
+ if (marker && !marker.isAdded && this.isMarkerInBounds(marker, extendedMapBounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
906
923
  this.addToClosestCluster(marker);
907
924
  }
908
925
  }
@@ -921,18 +938,21 @@ var Clusterer = /** @class */ (function () {
921
938
  * @event
922
939
  */
923
940
  google.maps.event.trigger(this, 'clusteringend', this);
924
- for (var i = 0; i < this.clusters.length; i++) {
925
- this.clusters[i].updateIcon();
941
+ for (var _i = 0, _a = this.clusters; _i < _a.length; _i++) {
942
+ var cluster = _a[_i];
943
+ cluster.updateIcon();
926
944
  }
927
945
  }
928
946
  };
929
947
  Clusterer.prototype.extend = function (obj1, obj2) {
930
948
  return function applyExtend(object) {
931
949
  for (var property in object.prototype) {
950
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
932
951
  // @ts-ignore
933
952
  this.prototype[property] = object.prototype[property];
934
953
  }
935
954
  return this;
955
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
936
956
  }.apply(obj1, [obj2]);
937
957
  };
938
958
  return Clusterer;