@react-google-maps/marker-clusterer 2.4.0 → 2.8.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 +44 -121
- package/dist/cjs.js.map +1 -1
- package/dist/cjs.min.js +1 -1
- package/dist/cjs.min.js.map +1 -1
- package/dist/esm.js +44 -121
- package/dist/esm.js.map +1 -1
- package/dist/esm.min.js +1 -1
- package/dist/esm.min.js.map +1 -1
- package/dist/index.d.ts +16 -16
- package/dist/umd.js +46 -123
- package/dist/umd.js.map +1 -1
- package/dist/umd.min.js +1 -1
- package/dist/umd.min.js.map +1 -1
- package/package.json +34 -27
- package/src/Cluster.tsx +0 -2
- package/src/ClusterIcon.tsx +40 -102
- package/src/Clusterer.tsx +2 -20
- package/src/__tests__/clusterer.test.ts +4 -0
- package/src/types.tsx +16 -16
package/dist/cjs.js
CHANGED
|
@@ -6,7 +6,8 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
6
6
|
function ClusterIcon(cluster, styles) {
|
|
7
7
|
cluster.getClusterer().extend(ClusterIcon, google.maps.OverlayView);
|
|
8
8
|
this.cluster = cluster;
|
|
9
|
-
this.
|
|
9
|
+
this.clusterClassName = this.cluster.getClusterer().getClusterClass();
|
|
10
|
+
this.className = this.clusterClassName;
|
|
10
11
|
this.styles = styles;
|
|
11
12
|
this.center = undefined;
|
|
12
13
|
this.div = null;
|
|
@@ -25,7 +26,6 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
25
26
|
this.fontStyle = 'normal';
|
|
26
27
|
this.fontFamily = 'Arial,sans-serif';
|
|
27
28
|
this.backgroundPosition = '0 0';
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
29
29
|
// @ts-ignore
|
|
30
30
|
this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
|
|
31
31
|
}
|
|
@@ -38,12 +38,10 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
38
38
|
if (this.visible) {
|
|
39
39
|
this.show();
|
|
40
40
|
}
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
42
41
|
// @ts-ignore
|
|
43
42
|
this.getPanes().overlayMouseTarget.appendChild(this.div);
|
|
44
43
|
// Fix for Issue 157
|
|
45
44
|
this.boundsChangedListener = google.maps.event.addListener(
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
47
45
|
// @ts-ignore
|
|
48
46
|
this.getMap(), 'boundschanged', function boundsChanged() {
|
|
49
47
|
cDraggingMapByCluster = cMouseDownInCluster;
|
|
@@ -52,10 +50,7 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
52
50
|
cMouseDownInCluster = true;
|
|
53
51
|
cDraggingMapByCluster = false;
|
|
54
52
|
});
|
|
55
|
-
|
|
56
|
-
google.maps.event.addDomListener(this.div, 'click',
|
|
57
|
-
// eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
|
|
58
|
-
function (event) {
|
|
53
|
+
google.maps.event.addDomListener(this.div, 'click', function (event) {
|
|
59
54
|
cMouseDownInCluster = false;
|
|
60
55
|
if (!cDraggingMapByCluster) {
|
|
61
56
|
var markerClusterer_1 = _this.cluster.getClusterer();
|
|
@@ -73,19 +68,15 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
73
68
|
// Zoom into the cluster.
|
|
74
69
|
var maxZoom_1 = markerClusterer_1.getMaxZoom();
|
|
75
70
|
var bounds_1 = _this.cluster.getBounds();
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
77
71
|
// @ts-ignore
|
|
78
72
|
markerClusterer_1.getMap().fitBounds(bounds_1);
|
|
79
73
|
// There is a fix for Issue 170 here:
|
|
80
74
|
setTimeout(function timeout() {
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
82
75
|
// @ts-ignore
|
|
83
76
|
markerClusterer_1.getMap().fitBounds(bounds_1);
|
|
84
77
|
// Don't zoom beyond the max zoom level
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
86
78
|
// @ts-ignore
|
|
87
79
|
if (maxZoom_1 !== null && markerClusterer_1.getMap().getZoom() > maxZoom_1) {
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
89
80
|
// @ts-ignore
|
|
90
81
|
markerClusterer_1.getMap().setZoom(maxZoom_1 + 1);
|
|
91
82
|
}
|
|
@@ -98,9 +89,7 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
98
89
|
}
|
|
99
90
|
}
|
|
100
91
|
});
|
|
101
|
-
google.maps.event.addDomListener(this.div, 'mouseover',
|
|
102
|
-
// eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
|
|
103
|
-
function () {
|
|
92
|
+
google.maps.event.addDomListener(this.div, 'mouseover', function () {
|
|
104
93
|
/**
|
|
105
94
|
* This event is fired when the mouse moves over a cluster marker.
|
|
106
95
|
* @name MarkerClusterer#mouseover
|
|
@@ -109,10 +98,7 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
109
98
|
*/
|
|
110
99
|
google.maps.event.trigger(_this.cluster.getClusterer(), 'mouseover', _this.cluster);
|
|
111
100
|
});
|
|
112
|
-
|
|
113
|
-
google.maps.event.addDomListener(this.div, 'mouseout',
|
|
114
|
-
// eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
|
|
115
|
-
function () {
|
|
101
|
+
google.maps.event.addDomListener(this.div, 'mouseout', function () {
|
|
116
102
|
/**
|
|
117
103
|
* This event is fired when the mouse moves out of a cluster marker.
|
|
118
104
|
* @name MarkerClusterer#mouseout
|
|
@@ -147,8 +133,9 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
147
133
|
this.visible = false;
|
|
148
134
|
};
|
|
149
135
|
ClusterIcon.prototype.show = function () {
|
|
136
|
+
var _a;
|
|
150
137
|
if (this.div && this.center) {
|
|
151
|
-
var
|
|
138
|
+
var divTitle = '';
|
|
152
139
|
// NOTE: values must be specified in px units
|
|
153
140
|
var bp = this.backgroundPosition.split(' ');
|
|
154
141
|
var spriteH = parseInt(bp[0].replace(/^\s+|\s+$/g, ''), 10);
|
|
@@ -160,72 +147,38 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
160
147
|
else {
|
|
161
148
|
divTitle = this.sums.title;
|
|
162
149
|
}
|
|
163
|
-
this.div.style.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
//@ts-ignore
|
|
150
|
+
this.div.style.cursor = 'pointer';
|
|
151
|
+
this.div.style.position = 'absolute';
|
|
152
|
+
this.div.style.top = "".concat(pos.y, "px");
|
|
153
|
+
this.div.style.left = "".concat(pos.x, "px");
|
|
154
|
+
this.div.style.width = "".concat(this.width, "px");
|
|
155
|
+
this.div.style.height = "".concat(this.height, "px");
|
|
156
|
+
var img = document.createElement('img');
|
|
157
|
+
img.alt = divTitle;
|
|
158
|
+
img.src = this.url;
|
|
159
|
+
img.style.position = 'absolute';
|
|
160
|
+
img.style.top = "".concat(spriteV, "px");
|
|
161
|
+
img.style.left = "".concat(spriteH, "px");
|
|
176
162
|
if (!this.cluster.getClusterer().enableRetinaIcons) {
|
|
177
|
-
img
|
|
178
|
-
'clip: rect(' +
|
|
179
|
-
-1 * spriteV +
|
|
180
|
-
'px, ' +
|
|
181
|
-
(-1 * spriteH + this.width) +
|
|
182
|
-
'px, ' +
|
|
183
|
-
(-1 * spriteV + this.height) +
|
|
184
|
-
'px, ' +
|
|
185
|
-
-1 * spriteH +
|
|
186
|
-
'px);';
|
|
163
|
+
img.style.clip = "rect(-".concat(spriteV, "px, -").concat(spriteH + this.width, "px, -").concat(spriteV + this.height, ", -").concat(spriteH, ")");
|
|
187
164
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
'font-family: ' +
|
|
206
|
-
this.fontFamily +
|
|
207
|
-
';' +
|
|
208
|
-
'font-weight: ' +
|
|
209
|
-
this.fontWeight +
|
|
210
|
-
';' +
|
|
211
|
-
'font-style: ' +
|
|
212
|
-
this.fontStyle +
|
|
213
|
-
';' +
|
|
214
|
-
'text-decoration: ' +
|
|
215
|
-
this.textDecoration +
|
|
216
|
-
';' +
|
|
217
|
-
'text-align: center;' +
|
|
218
|
-
'width: ' +
|
|
219
|
-
this.width +
|
|
220
|
-
'px;' +
|
|
221
|
-
'line-height:' +
|
|
222
|
-
this.height +
|
|
223
|
-
'px;' +
|
|
224
|
-
"'>" +
|
|
225
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
226
|
-
// @ts-ignore
|
|
227
|
-
this.sums.text +
|
|
228
|
-
'</div>';
|
|
165
|
+
var textElm = document.createElement('div');
|
|
166
|
+
textElm.style.position = 'absolute';
|
|
167
|
+
textElm.style.top = "".concat(this.anchorText[0], "px");
|
|
168
|
+
textElm.style.left = "".concat(this.anchorText[1], "px");
|
|
169
|
+
textElm.style.color = this.textColor;
|
|
170
|
+
textElm.style.fontSize = "".concat(this.textSize, "px");
|
|
171
|
+
textElm.style.fontFamily = this.fontFamily;
|
|
172
|
+
textElm.style.fontWeight = this.fontWeight;
|
|
173
|
+
textElm.style.fontStyle = this.fontStyle;
|
|
174
|
+
textElm.style.textDecoration = this.textDecoration;
|
|
175
|
+
textElm.style.textAlign = 'center';
|
|
176
|
+
textElm.style.width = "".concat(this.width, "px");
|
|
177
|
+
textElm.style.lineHeight = "".concat(this.height, "px");
|
|
178
|
+
textElm.innerText = "".concat((_a = this.sums) === null || _a === void 0 ? void 0 : _a.text);
|
|
179
|
+
this.div.innerHTML = '';
|
|
180
|
+
this.div.appendChild(img);
|
|
181
|
+
this.div.appendChild(textElm);
|
|
229
182
|
this.div.title = divTitle;
|
|
230
183
|
this.div.style.display = '';
|
|
231
184
|
}
|
|
@@ -233,12 +186,13 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
233
186
|
};
|
|
234
187
|
ClusterIcon.prototype.useStyle = function (sums) {
|
|
235
188
|
this.sums = sums;
|
|
236
|
-
var
|
|
189
|
+
var styles = this.cluster.getClusterer().getStyles();
|
|
190
|
+
var style = styles[Math.min(styles.length - 1, Math.max(0, sums.index - 1))];
|
|
237
191
|
this.url = style.url;
|
|
238
192
|
this.height = style.height;
|
|
239
193
|
this.width = style.width;
|
|
240
194
|
if (style.className)
|
|
241
|
-
this.className = this.
|
|
195
|
+
this.className = "".concat(this.clusterClassName, " ").concat(style.className);
|
|
242
196
|
this.anchorText = style.anchorText || [0, 0];
|
|
243
197
|
this.anchorIcon = style.anchorIcon || [this.height / 2, this.width / 2];
|
|
244
198
|
this.textColor = style.textColor || 'black';
|
|
@@ -252,15 +206,7 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
252
206
|
ClusterIcon.prototype.setCenter = function (center) {
|
|
253
207
|
this.center = center;
|
|
254
208
|
};
|
|
255
|
-
ClusterIcon.prototype.createCss = function (pos) {
|
|
256
|
-
var style = [];
|
|
257
|
-
style.push('cursor: pointer;');
|
|
258
|
-
style.push('position: absolute; top: ' + pos.y + 'px; left: ' + pos.x + 'px;');
|
|
259
|
-
style.push('width: ' + this.width + 'px; height: ' + this.height + 'px;');
|
|
260
|
-
return style.join('');
|
|
261
|
-
};
|
|
262
209
|
ClusterIcon.prototype.getPosFromLatLng = function (latlng) {
|
|
263
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
264
210
|
// @ts-ignore
|
|
265
211
|
var pos = this.getProjection().fromLatLngToDivPixel(latlng);
|
|
266
212
|
pos.x -= this.anchorIcon[1];
|
|
@@ -275,7 +221,6 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
275
221
|
var Cluster = /** @class */ (function () {
|
|
276
222
|
function Cluster(markerClusterer) {
|
|
277
223
|
this.markerClusterer = markerClusterer;
|
|
278
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
279
224
|
// @ts-ignore
|
|
280
225
|
this.map = this.markerClusterer.getMap();
|
|
281
226
|
this.gridSize = this.markerClusterer.getGridSize();
|
|
@@ -313,7 +258,6 @@ var Cluster = /** @class */ (function () {
|
|
|
313
258
|
return bounds;
|
|
314
259
|
};
|
|
315
260
|
Cluster.prototype.remove = function () {
|
|
316
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
317
261
|
// @ts-ignore
|
|
318
262
|
this.clusterIcon.setMap(null);
|
|
319
263
|
this.markers = [];
|
|
@@ -482,13 +426,11 @@ var Clusterer = /** @class */ (function () {
|
|
|
482
426
|
this.timerRefStatic = null;
|
|
483
427
|
this.setupStyles();
|
|
484
428
|
this.addMarkers(optMarkers, true);
|
|
485
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
486
429
|
// @ts-ignore
|
|
487
430
|
this.setMap(map); // Note: this causes onAdd to be called
|
|
488
431
|
}
|
|
489
432
|
Clusterer.prototype.onAdd = function () {
|
|
490
433
|
var _this = this;
|
|
491
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
492
434
|
// @ts-ignore
|
|
493
435
|
this.activeMap = this.getMap();
|
|
494
436
|
this.ready = true;
|
|
@@ -496,11 +438,8 @@ var Clusterer = /** @class */ (function () {
|
|
|
496
438
|
// Add the map event listeners
|
|
497
439
|
this.listeners = [
|
|
498
440
|
google.maps.event.addListener(
|
|
499
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
500
441
|
// @ts-ignore
|
|
501
|
-
this.getMap(), 'zoom_changed',
|
|
502
|
-
// eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
|
|
503
|
-
function () {
|
|
442
|
+
this.getMap(), 'zoom_changed', function () {
|
|
504
443
|
_this.resetViewport(false);
|
|
505
444
|
// Workaround for this Google bug: when map is at level 0 and "-" of
|
|
506
445
|
// zoom slider is clicked, a "zoom_changed" event is fired even though
|
|
@@ -508,26 +447,20 @@ var Clusterer = /** @class */ (function () {
|
|
|
508
447
|
// event is triggered so the cluster markers that have been removed
|
|
509
448
|
// do not get redrawn. Same goes for a zoom in at maxZoom.
|
|
510
449
|
if (
|
|
511
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
512
450
|
// @ts-ignore
|
|
513
451
|
_this.getMap().getZoom() === (_this.get('minZoom') || 0) ||
|
|
514
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
515
452
|
// @ts-ignore
|
|
516
453
|
_this.getMap().getZoom() === _this.get('maxZoom')) {
|
|
517
454
|
google.maps.event.trigger(_this, 'idle');
|
|
518
455
|
}
|
|
519
456
|
}),
|
|
520
457
|
google.maps.event.addListener(
|
|
521
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
522
458
|
// @ts-ignore
|
|
523
|
-
this.getMap(), 'idle',
|
|
524
|
-
// eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
|
|
525
|
-
function () {
|
|
459
|
+
this.getMap(), 'idle', function () {
|
|
526
460
|
_this.redraw();
|
|
527
461
|
}),
|
|
528
462
|
];
|
|
529
463
|
};
|
|
530
|
-
// eslint-disable-next-line @getify/proper-arrows/this
|
|
531
464
|
Clusterer.prototype.onRemove = function () {
|
|
532
465
|
// Put all the managed markers back on the map:
|
|
533
466
|
for (var i = 0; i < this.markers.length; i++) {
|
|
@@ -571,7 +504,6 @@ var Clusterer = /** @class */ (function () {
|
|
|
571
504
|
bounds.extend(position);
|
|
572
505
|
}
|
|
573
506
|
}
|
|
574
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
575
507
|
// @ts-ignore
|
|
576
508
|
this.getMap().fitBounds(bounds);
|
|
577
509
|
};
|
|
@@ -685,7 +617,7 @@ var Clusterer = /** @class */ (function () {
|
|
|
685
617
|
};
|
|
686
618
|
Clusterer.prototype.addMarkers = function (markers, optNoDraw) {
|
|
687
619
|
for (var key in markers) {
|
|
688
|
-
if (
|
|
620
|
+
if (Object.prototype.hasOwnProperty.call(markers, key)) {
|
|
689
621
|
this.pushMarkerTo(markers[key]);
|
|
690
622
|
}
|
|
691
623
|
}
|
|
@@ -697,7 +629,6 @@ var Clusterer = /** @class */ (function () {
|
|
|
697
629
|
var _this = this;
|
|
698
630
|
// If the marker is draggable add a listener so we can update the clusters on the dragend:
|
|
699
631
|
if (marker.getDraggable()) {
|
|
700
|
-
// eslint-disable-next-line @getify/proper-arrows/name, @getify/proper-arrows/this
|
|
701
632
|
google.maps.event.addListener(marker, 'dragend', function () {
|
|
702
633
|
if (_this.ready) {
|
|
703
634
|
marker.isAdded = false;
|
|
@@ -764,7 +695,6 @@ var Clusterer = /** @class */ (function () {
|
|
|
764
695
|
}, 0);
|
|
765
696
|
};
|
|
766
697
|
Clusterer.prototype.getExtendedBounds = function (bounds) {
|
|
767
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
768
698
|
// @ts-ignore
|
|
769
699
|
var projection = this.getProjection();
|
|
770
700
|
// Convert the points to pixels and the extend out by the grid size.
|
|
@@ -875,16 +805,13 @@ var Clusterer = /** @class */ (function () {
|
|
|
875
805
|
//
|
|
876
806
|
// See Comments 9 & 11 on Issue 3651 relating to this workaround for a Google Maps bug:
|
|
877
807
|
var mapBounds =
|
|
878
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
879
808
|
// @ts-ignore
|
|
880
809
|
this.getMap().getZoom() > 3
|
|
881
810
|
? new google.maps.LatLngBounds(
|
|
882
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
883
811
|
// @ts-ignore
|
|
884
812
|
this.getMap()
|
|
885
813
|
.getBounds()
|
|
886
814
|
.getSouthWest(),
|
|
887
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
888
815
|
// @ts-ignore
|
|
889
816
|
this.getMap()
|
|
890
817
|
.getBounds()
|
|
@@ -901,9 +828,7 @@ var Clusterer = /** @class */ (function () {
|
|
|
901
828
|
}
|
|
902
829
|
}
|
|
903
830
|
if (iLast < this.markers.length) {
|
|
904
|
-
this.timerRefStatic = window.setTimeout(
|
|
905
|
-
// eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
|
|
906
|
-
function () {
|
|
831
|
+
this.timerRefStatic = window.setTimeout(function () {
|
|
907
832
|
_this.createClusters(iLast);
|
|
908
833
|
}, 0);
|
|
909
834
|
}
|
|
@@ -926,11 +851,9 @@ var Clusterer = /** @class */ (function () {
|
|
|
926
851
|
return function applyExtend(object) {
|
|
927
852
|
// eslint-disable-next-line guard-for-in
|
|
928
853
|
for (var property in object.prototype) {
|
|
929
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
930
854
|
// @ts-ignore
|
|
931
855
|
this.prototype[property] = object.prototype[property];
|
|
932
856
|
}
|
|
933
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
934
857
|
// @ts-ignore
|
|
935
858
|
return this;
|
|
936
859
|
}.apply(obj1, [obj2]);
|