@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 +161 -135
- 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 +161 -135
- 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 +6 -4
- package/dist/umd.js +161 -135
- 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 +1 -1
- package/src/ClusterIcon.tsx +31 -12
- package/src/Clusterer.tsx +82 -72
package/dist/esm.js
CHANGED
|
@@ -1,33 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise */
|
|
16
|
+
|
|
17
|
+
var extendStatics = function(d, b) {
|
|
18
|
+
extendStatics = Object.setPrototypeOf ||
|
|
19
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
20
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
21
|
+
return extendStatics(d, b);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function __extends(d, b) {
|
|
25
|
+
if (typeof b !== "function" && b !== null)
|
|
26
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
27
|
+
extendStatics(d, b);
|
|
28
|
+
function __() { this.constructor = d; }
|
|
29
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var ClusterIcon = /** @class */ (function (_super) {
|
|
33
|
+
__extends(ClusterIcon, _super);
|
|
2
34
|
function ClusterIcon(cluster, styles) {
|
|
35
|
+
var _this = _super.call(this) || this;
|
|
3
36
|
cluster.getClusterer().extend(ClusterIcon, google.maps.OverlayView);
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
|
|
37
|
+
_this.cluster = cluster;
|
|
38
|
+
_this.clusterClassName = _this.cluster.getClusterer().getClusterClass();
|
|
39
|
+
_this.className = _this.clusterClassName;
|
|
40
|
+
_this.styles = styles;
|
|
41
|
+
_this.center = undefined;
|
|
42
|
+
_this.div = null;
|
|
43
|
+
_this.sums = null;
|
|
44
|
+
_this.visible = false;
|
|
45
|
+
_this.boundsChangedListener = null;
|
|
46
|
+
_this.url = '';
|
|
47
|
+
_this.height = 0;
|
|
48
|
+
_this.width = 0;
|
|
49
|
+
_this.anchorText = [0, 0];
|
|
50
|
+
_this.anchorIcon = [0, 0];
|
|
51
|
+
_this.textColor = 'black';
|
|
52
|
+
_this.textSize = 11;
|
|
53
|
+
_this.textDecoration = 'none';
|
|
54
|
+
_this.fontWeight = 'bold';
|
|
55
|
+
_this.fontStyle = 'normal';
|
|
56
|
+
_this.fontFamily = 'Arial,sans-serif';
|
|
57
|
+
_this.backgroundPosition = '0 0';
|
|
58
|
+
_this.cMouseDownInCluster = null;
|
|
59
|
+
_this.cDraggingMapByCluster = null;
|
|
60
|
+
_this.timeOut = null;
|
|
61
|
+
_this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
|
|
62
|
+
return _this;
|
|
31
63
|
}
|
|
32
64
|
ClusterIcon.prototype.onBoundsChanged = function () {
|
|
33
65
|
this.cDraggingMapByCluster = this.cMouseDownInCluster;
|
|
@@ -137,9 +169,9 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
137
169
|
};
|
|
138
170
|
ClusterIcon.prototype.draw = function () {
|
|
139
171
|
if (this.visible && this.div !== null && this.center) {
|
|
140
|
-
var
|
|
141
|
-
this.div.style.top = "".concat(y, "px");
|
|
142
|
-
this.div.style.left = "".concat(x, "px");
|
|
172
|
+
var pos = this.getPosFromLatLng(this.center);
|
|
173
|
+
this.div.style.top = pos !== null ? "".concat(pos.y, "px") : '0';
|
|
174
|
+
this.div.style.left = pos !== null ? "".concat(pos.x, "px") : '0';
|
|
143
175
|
}
|
|
144
176
|
};
|
|
145
177
|
ClusterIcon.prototype.hide = function () {
|
|
@@ -167,8 +199,8 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
167
199
|
}
|
|
168
200
|
this.div.style.cursor = 'pointer';
|
|
169
201
|
this.div.style.position = 'absolute';
|
|
170
|
-
this.div.style.top = "".concat(pos.y, "px");
|
|
171
|
-
this.div.style.left = "".concat(pos.x, "px");
|
|
202
|
+
this.div.style.top = pos !== null ? "".concat(pos.y, "px") : '0';
|
|
203
|
+
this.div.style.left = pos !== null ? "".concat(pos.x, "px") : '0';
|
|
172
204
|
this.div.style.width = "".concat(this.width, "px");
|
|
173
205
|
this.div.style.height = "".concat(this.height, "px");
|
|
174
206
|
var img = document.createElement('img');
|
|
@@ -225,14 +257,15 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
225
257
|
this.center = center;
|
|
226
258
|
};
|
|
227
259
|
ClusterIcon.prototype.getPosFromLatLng = function (latlng) {
|
|
228
|
-
// @ts-ignore
|
|
229
260
|
var pos = this.getProjection().fromLatLngToDivPixel(latlng);
|
|
230
|
-
pos
|
|
231
|
-
|
|
261
|
+
if (pos !== null) {
|
|
262
|
+
pos.x -= this.anchorIcon[1];
|
|
263
|
+
pos.y -= this.anchorIcon[0];
|
|
264
|
+
}
|
|
232
265
|
return pos;
|
|
233
266
|
};
|
|
234
267
|
return ClusterIcon;
|
|
235
|
-
}());
|
|
268
|
+
}(google.maps.OverlayView));
|
|
236
269
|
|
|
237
270
|
var Cluster = /** @class */ (function () {
|
|
238
271
|
function Cluster(markerClusterer) {
|
|
@@ -377,7 +410,6 @@ var Cluster = /** @class */ (function () {
|
|
|
377
410
|
return Cluster;
|
|
378
411
|
}());
|
|
379
412
|
|
|
380
|
-
/* global google */
|
|
381
413
|
/**
|
|
382
414
|
* Supports up to 9007199254740991 (Number.MAX_SAFE_INTEGER) markers
|
|
383
415
|
* which is not a problem as max array length is 4294967296 (2**32)
|
|
@@ -398,91 +430,86 @@ var IMAGE_PATH = 'https://developers.google.com/maps/documentation/javascript/ex
|
|
|
398
430
|
var IMAGE_EXTENSION = 'png';
|
|
399
431
|
var IMAGE_SIZES = [53, 56, 66, 78, 90];
|
|
400
432
|
var CLUSTERER_CLASS = 'cluster';
|
|
401
|
-
var Clusterer = /** @class */ (function () {
|
|
433
|
+
var Clusterer = /** @class */ (function (_super) {
|
|
434
|
+
__extends(Clusterer, _super);
|
|
402
435
|
function Clusterer(map, optMarkers, optOptions) {
|
|
403
436
|
if (optMarkers === void 0) { optMarkers = []; }
|
|
404
437
|
if (optOptions === void 0) { optOptions = {}; }
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
438
|
+
var _this = _super.call(this) || this;
|
|
439
|
+
_this.extend(Clusterer, google.maps.OverlayView);
|
|
440
|
+
_this.markers = [];
|
|
441
|
+
_this.clusters = [];
|
|
442
|
+
_this.listeners = [];
|
|
443
|
+
_this.activeMap = null;
|
|
444
|
+
_this.ready = false;
|
|
445
|
+
_this.gridSize = optOptions.gridSize || 60;
|
|
446
|
+
_this.minClusterSize = optOptions.minimumClusterSize || 2;
|
|
447
|
+
_this.maxZoom = optOptions.maxZoom || null;
|
|
448
|
+
_this.styles = optOptions.styles || [];
|
|
449
|
+
_this.title = optOptions.title || '';
|
|
450
|
+
_this.zoomOnClick = true;
|
|
417
451
|
if (optOptions.zoomOnClick !== undefined) {
|
|
418
|
-
|
|
452
|
+
_this.zoomOnClick = optOptions.zoomOnClick;
|
|
419
453
|
}
|
|
420
|
-
|
|
454
|
+
_this.averageCenter = false;
|
|
421
455
|
if (optOptions.averageCenter !== undefined) {
|
|
422
|
-
|
|
456
|
+
_this.averageCenter = optOptions.averageCenter;
|
|
423
457
|
}
|
|
424
|
-
|
|
458
|
+
_this.ignoreHidden = false;
|
|
425
459
|
if (optOptions.ignoreHidden !== undefined) {
|
|
426
|
-
|
|
460
|
+
_this.ignoreHidden = optOptions.ignoreHidden;
|
|
427
461
|
}
|
|
428
|
-
|
|
462
|
+
_this.enableRetinaIcons = false;
|
|
429
463
|
if (optOptions.enableRetinaIcons !== undefined) {
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
464
|
+
_this.enableRetinaIcons = optOptions.enableRetinaIcons;
|
|
465
|
+
}
|
|
466
|
+
_this.imagePath = optOptions.imagePath || IMAGE_PATH;
|
|
467
|
+
_this.imageExtension = optOptions.imageExtension || IMAGE_EXTENSION;
|
|
468
|
+
_this.imageSizes = optOptions.imageSizes || IMAGE_SIZES;
|
|
469
|
+
_this.calculator = optOptions.calculator || CALCULATOR;
|
|
470
|
+
_this.batchSize = optOptions.batchSize || BATCH_SIZE;
|
|
471
|
+
_this.batchSizeIE = optOptions.batchSizeIE || BATCH_SIZE_IE;
|
|
472
|
+
_this.clusterClass = optOptions.clusterClass || CLUSTERER_CLASS;
|
|
439
473
|
if (navigator.userAgent.toLowerCase().indexOf('msie') !== -1) {
|
|
440
474
|
// Try to avoid IE timeout when processing a huge number of markers:
|
|
441
|
-
|
|
475
|
+
_this.batchSize = _this.batchSizeIE;
|
|
442
476
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
477
|
+
_this.timerRefStatic = null;
|
|
478
|
+
_this.setupStyles();
|
|
479
|
+
_this.addMarkers(optMarkers, true);
|
|
446
480
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
447
481
|
// @ts-ignore
|
|
448
|
-
|
|
482
|
+
_this.setMap(map); // Note: this causes onAdd to be called
|
|
483
|
+
return _this;
|
|
449
484
|
}
|
|
485
|
+
Clusterer.prototype.onZoomChanged = function () {
|
|
486
|
+
var _a, _b;
|
|
487
|
+
this.resetViewport(false);
|
|
488
|
+
// Workaround for this Google bug: when map is at level 0 and "-" of
|
|
489
|
+
// zoom slider is clicked, a "zoom_changed" event is fired even though
|
|
490
|
+
// the map doesn't zoom out any further. In this situation, no "idle"
|
|
491
|
+
// event is triggered so the cluster markers that have been removed
|
|
492
|
+
// do not get redrawn. Same goes for a zoom in at maxZoom.
|
|
493
|
+
if (((_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.getZoom()) === (this.get('minZoom') || 0) ||
|
|
494
|
+
((_b = this.getMap()) === null || _b === void 0 ? void 0 : _b.getZoom()) === this.get('maxZoom')) {
|
|
495
|
+
google.maps.event.trigger(this, 'idle');
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
Clusterer.prototype.onIdle = function () {
|
|
499
|
+
this.redraw();
|
|
500
|
+
};
|
|
450
501
|
Clusterer.prototype.onAdd = function () {
|
|
451
|
-
var
|
|
452
|
-
|
|
453
|
-
// @ts-ignore
|
|
454
|
-
this.activeMap = this.getMap();
|
|
502
|
+
var map = this.getMap();
|
|
503
|
+
this.activeMap = map;
|
|
455
504
|
this.ready = true;
|
|
456
505
|
this.repaint();
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
// Workaround for this Google bug: when map is at level 0 and "-" of
|
|
465
|
-
// zoom slider is clicked, a "zoom_changed" event is fired even though
|
|
466
|
-
// the map doesn't zoom out any further. In this situation, no "idle"
|
|
467
|
-
// event is triggered so the cluster markers that have been removed
|
|
468
|
-
// do not get redrawn. Same goes for a zoom in at maxZoom.
|
|
469
|
-
if (
|
|
470
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
471
|
-
// @ts-ignore
|
|
472
|
-
_this.getMap().getZoom() === (_this.get('minZoom') || 0) ||
|
|
473
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
474
|
-
// @ts-ignore
|
|
475
|
-
_this.getMap().getZoom() === _this.get('maxZoom')) {
|
|
476
|
-
google.maps.event.trigger(_this, 'idle');
|
|
477
|
-
}
|
|
478
|
-
}),
|
|
479
|
-
google.maps.event.addListener(
|
|
480
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
481
|
-
// @ts-ignore
|
|
482
|
-
this.getMap(), 'idle', function () {
|
|
483
|
-
_this.redraw();
|
|
484
|
-
}),
|
|
485
|
-
];
|
|
506
|
+
if (map !== null) {
|
|
507
|
+
// Add the map event listeners
|
|
508
|
+
this.listeners = [
|
|
509
|
+
google.maps.event.addListener(map, 'zoom_changed', this.onZoomChanged),
|
|
510
|
+
google.maps.event.addListener(map, 'idle', this.onIdle),
|
|
511
|
+
];
|
|
512
|
+
}
|
|
486
513
|
};
|
|
487
514
|
Clusterer.prototype.onRemove = function () {
|
|
488
515
|
// Put all the managed markers back on the map:
|
|
@@ -726,20 +753,32 @@ var Clusterer = /** @class */ (function () {
|
|
|
726
753
|
var trPix = projection.fromLatLngToDivPixel(
|
|
727
754
|
// Turn the bounds into latlng.
|
|
728
755
|
new google.maps.LatLng(bounds.getNorthEast().lat(), bounds.getNorthEast().lng()));
|
|
729
|
-
trPix
|
|
730
|
-
|
|
756
|
+
if (trPix !== null) {
|
|
757
|
+
trPix.x += this.gridSize;
|
|
758
|
+
trPix.y -= this.gridSize;
|
|
759
|
+
}
|
|
731
760
|
var blPix = projection.fromLatLngToDivPixel(
|
|
732
761
|
// Turn the bounds into latlng.
|
|
733
762
|
new google.maps.LatLng(bounds.getSouthWest().lat(), bounds.getSouthWest().lng()));
|
|
734
|
-
blPix
|
|
735
|
-
|
|
763
|
+
if (blPix !== null) {
|
|
764
|
+
blPix.x -= this.gridSize;
|
|
765
|
+
blPix.y += this.gridSize;
|
|
766
|
+
}
|
|
736
767
|
// Extend the bounds to contain the new bounds.
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
768
|
+
if (trPix !== null) {
|
|
769
|
+
// Convert the pixel points back to LatLng nw
|
|
770
|
+
var point1 = projection.fromDivPixelToLatLng(trPix);
|
|
771
|
+
if (point1 !== null) {
|
|
772
|
+
bounds.extend(point1);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
if (blPix !== null) {
|
|
776
|
+
// Convert the pixel points back to LatLng sw
|
|
777
|
+
var point2 = projection.fromDivPixelToLatLng(blPix);
|
|
778
|
+
if (point2 !== null) {
|
|
779
|
+
bounds.extend(point2);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
743
782
|
return bounds;
|
|
744
783
|
};
|
|
745
784
|
Clusterer.prototype.redraw = function () {
|
|
@@ -826,6 +865,8 @@ var Clusterer = /** @class */ (function () {
|
|
|
826
865
|
delete this.timerRefStatic;
|
|
827
866
|
}
|
|
828
867
|
}
|
|
868
|
+
var map = this.getMap();
|
|
869
|
+
var bounds = map !== null && 'getBounds' in map ? map.getBounds() : null;
|
|
829
870
|
// Get our current map view bounds.
|
|
830
871
|
// Create a new bounds object so we don't affect the map.
|
|
831
872
|
//
|
|
@@ -833,24 +874,14 @@ var Clusterer = /** @class */ (function () {
|
|
|
833
874
|
var mapBounds =
|
|
834
875
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
835
876
|
// @ts-ignore
|
|
836
|
-
|
|
837
|
-
? new google.maps.LatLngBounds(
|
|
838
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
839
|
-
// @ts-ignore
|
|
840
|
-
this.getMap()
|
|
841
|
-
.getBounds()
|
|
842
|
-
.getSouthWest(),
|
|
843
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
844
|
-
// @ts-ignore
|
|
845
|
-
this.getMap()
|
|
846
|
-
.getBounds()
|
|
847
|
-
.getNorthEast())
|
|
877
|
+
map.getZoom() > 3
|
|
878
|
+
? new google.maps.LatLngBounds(bounds === null || bounds === void 0 ? void 0 : bounds.getSouthWest(), bounds === null || bounds === void 0 ? void 0 : bounds.getNorthEast())
|
|
848
879
|
: new google.maps.LatLngBounds(new google.maps.LatLng(85.02070771743472, -178.48388434375), new google.maps.LatLng(-85.08136444384544, 178.00048865625));
|
|
849
|
-
var
|
|
880
|
+
var extendedMapBounds = this.getExtendedBounds(mapBounds);
|
|
850
881
|
var iLast = Math.min(iFirst + this.batchSize, this.markers.length);
|
|
851
882
|
for (var i = iFirst; i < iLast; i++) {
|
|
852
883
|
var marker = this.markers[i];
|
|
853
|
-
if (!marker.isAdded && this.isMarkerInBounds(marker,
|
|
884
|
+
if (!marker.isAdded && this.isMarkerInBounds(marker, extendedMapBounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
|
|
854
885
|
this.addToClosestCluster(marker);
|
|
855
886
|
}
|
|
856
887
|
}
|
|
@@ -876,19 +907,14 @@ var Clusterer = /** @class */ (function () {
|
|
|
876
907
|
};
|
|
877
908
|
Clusterer.prototype.extend = function (obj1, obj2) {
|
|
878
909
|
return function applyExtend(object) {
|
|
879
|
-
// eslint-disable-next-line guard-for-in
|
|
880
910
|
for (var property in object.prototype) {
|
|
881
|
-
|
|
882
|
-
// @ts-ignore
|
|
883
|
-
this.prototype[property] = object.prototype[property];
|
|
911
|
+
this.prototype.set(property, object.prototype.get(property));
|
|
884
912
|
}
|
|
885
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
886
|
-
// @ts-ignore
|
|
887
913
|
return this;
|
|
888
914
|
}.apply(obj1, [obj2]);
|
|
889
915
|
};
|
|
890
916
|
return Clusterer;
|
|
891
|
-
}());
|
|
917
|
+
}(google.maps.OverlayView));
|
|
892
918
|
|
|
893
919
|
export { Cluster, ClusterIcon, Clusterer };
|
|
894
920
|
//# sourceMappingURL=esm.js.map
|