@react-google-maps/marker-clusterer 2.9.0 → 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 +260 -201
- 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 +260 -201
- 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 +14 -4
- package/dist/umd.js +260 -201
- 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 +10 -47
- package/src/Cluster.tsx +9 -5
- package/src/ClusterIcon.tsx +171 -110
- package/src/Clusterer.tsx +88 -66
- package/src/index.ts +5 -5
- package/src/setup-tests.js +0 -356
package/dist/esm.js
CHANGED
|
@@ -1,108 +1,153 @@
|
|
|
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
|
-
|
|
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;
|
|
27
63
|
}
|
|
64
|
+
ClusterIcon.prototype.onBoundsChanged = function () {
|
|
65
|
+
this.cDraggingMapByCluster = this.cMouseDownInCluster;
|
|
66
|
+
};
|
|
67
|
+
ClusterIcon.prototype.onMouseDown = function () {
|
|
68
|
+
this.cMouseDownInCluster = true;
|
|
69
|
+
this.cDraggingMapByCluster = false;
|
|
70
|
+
};
|
|
71
|
+
ClusterIcon.prototype.onClick = function (event) {
|
|
72
|
+
this.cMouseDownInCluster = false;
|
|
73
|
+
if (!this.cDraggingMapByCluster) {
|
|
74
|
+
var markerClusterer_1 = this.cluster.getClusterer();
|
|
75
|
+
/**
|
|
76
|
+
* This event is fired when a cluster marker is clicked.
|
|
77
|
+
* @name MarkerClusterer#click
|
|
78
|
+
* @param {Cluster} c The cluster that was clicked.
|
|
79
|
+
* @event
|
|
80
|
+
*/
|
|
81
|
+
google.maps.event.trigger(markerClusterer_1, 'click', this.cluster);
|
|
82
|
+
google.maps.event.trigger(markerClusterer_1, 'clusterclick', this.cluster); // deprecated name
|
|
83
|
+
// The default click handler follows. Disable it by setting
|
|
84
|
+
// the zoomOnClick property to false.
|
|
85
|
+
if (markerClusterer_1.getZoomOnClick()) {
|
|
86
|
+
// Zoom into the cluster.
|
|
87
|
+
var maxZoom_1 = markerClusterer_1.getMaxZoom();
|
|
88
|
+
var bounds_1 = this.cluster.getBounds();
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
markerClusterer_1.getMap().fitBounds(bounds_1);
|
|
92
|
+
// There is a fix for Issue 170 here:
|
|
93
|
+
this.timeOut = window.setTimeout(function () {
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
markerClusterer_1.getMap().fitBounds(bounds_1);
|
|
97
|
+
// Don't zoom beyond the max zoom level
|
|
98
|
+
if (maxZoom_1 !== null &&
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
100
|
+
// @ts-ignore
|
|
101
|
+
markerClusterer_1.getMap().getZoom() > maxZoom_1) {
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
103
|
+
// @ts-ignore
|
|
104
|
+
markerClusterer_1.getMap().setZoom(maxZoom_1 + 1);
|
|
105
|
+
}
|
|
106
|
+
}, 100);
|
|
107
|
+
}
|
|
108
|
+
// Prevent event propagation to the map:
|
|
109
|
+
event.cancelBubble = true;
|
|
110
|
+
if (event.stopPropagation) {
|
|
111
|
+
event.stopPropagation();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
ClusterIcon.prototype.onMouseOver = function () {
|
|
116
|
+
/**
|
|
117
|
+
* This event is fired when the mouse moves over a cluster marker.
|
|
118
|
+
* @name MarkerClusterer#mouseover
|
|
119
|
+
* @param {Cluster} c The cluster that the mouse moved over.
|
|
120
|
+
* @event
|
|
121
|
+
*/
|
|
122
|
+
google.maps.event.trigger(this.cluster.getClusterer(), 'mouseover', this.cluster);
|
|
123
|
+
};
|
|
124
|
+
ClusterIcon.prototype.onMouseOut = function () {
|
|
125
|
+
/**
|
|
126
|
+
* This event is fired when the mouse moves out of a cluster marker.
|
|
127
|
+
* @name MarkerClusterer#mouseout
|
|
128
|
+
* @param {Cluster} c The cluster that the mouse moved out of.
|
|
129
|
+
* @event
|
|
130
|
+
*/
|
|
131
|
+
google.maps.event.trigger(this.cluster.getClusterer(), 'mouseout', this.cluster);
|
|
132
|
+
};
|
|
28
133
|
ClusterIcon.prototype.onAdd = function () {
|
|
29
|
-
var _this = this;
|
|
30
|
-
var cMouseDownInCluster;
|
|
31
|
-
var cDraggingMapByCluster;
|
|
32
134
|
this.div = document.createElement('div');
|
|
33
135
|
this.div.className = this.className;
|
|
34
136
|
if (this.visible) {
|
|
35
137
|
this.show();
|
|
36
138
|
}
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
37
140
|
// @ts-ignore
|
|
38
141
|
this.getPanes().overlayMouseTarget.appendChild(this.div);
|
|
39
142
|
// Fix for Issue 157
|
|
40
143
|
this.boundsChangedListener = google.maps.event.addListener(
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
41
145
|
// @ts-ignore
|
|
42
|
-
this.getMap(), '
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
cDraggingMapByCluster = false;
|
|
48
|
-
});
|
|
49
|
-
google.maps.event.addDomListener(this.div, 'click', function (event) {
|
|
50
|
-
cMouseDownInCluster = false;
|
|
51
|
-
if (!cDraggingMapByCluster) {
|
|
52
|
-
var markerClusterer_1 = _this.cluster.getClusterer();
|
|
53
|
-
/**
|
|
54
|
-
* This event is fired when a cluster marker is clicked.
|
|
55
|
-
* @name MarkerClusterer#click
|
|
56
|
-
* @param {Cluster} c The cluster that was clicked.
|
|
57
|
-
* @event
|
|
58
|
-
*/
|
|
59
|
-
google.maps.event.trigger(markerClusterer_1, 'click', _this.cluster);
|
|
60
|
-
google.maps.event.trigger(markerClusterer_1, 'clusterclick', _this.cluster); // deprecated name
|
|
61
|
-
// The default click handler follows. Disable it by setting
|
|
62
|
-
// the zoomOnClick property to false.
|
|
63
|
-
if (markerClusterer_1.getZoomOnClick()) {
|
|
64
|
-
// Zoom into the cluster.
|
|
65
|
-
var maxZoom_1 = markerClusterer_1.getMaxZoom();
|
|
66
|
-
var bounds_1 = _this.cluster.getBounds();
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
markerClusterer_1.getMap().fitBounds(bounds_1);
|
|
69
|
-
// There is a fix for Issue 170 here:
|
|
70
|
-
setTimeout(function timeout() {
|
|
71
|
-
// @ts-ignore
|
|
72
|
-
markerClusterer_1.getMap().fitBounds(bounds_1);
|
|
73
|
-
// Don't zoom beyond the max zoom level
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
if (maxZoom_1 !== null && markerClusterer_1.getMap().getZoom() > maxZoom_1) {
|
|
76
|
-
// @ts-ignore
|
|
77
|
-
markerClusterer_1.getMap().setZoom(maxZoom_1 + 1);
|
|
78
|
-
}
|
|
79
|
-
}, 100);
|
|
80
|
-
}
|
|
81
|
-
// Prevent event propagation to the map:
|
|
82
|
-
event.cancelBubble = true;
|
|
83
|
-
if (event.stopPropagation) {
|
|
84
|
-
event.stopPropagation();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
google.maps.event.addDomListener(this.div, 'mouseover', function () {
|
|
89
|
-
/**
|
|
90
|
-
* This event is fired when the mouse moves over a cluster marker.
|
|
91
|
-
* @name MarkerClusterer#mouseover
|
|
92
|
-
* @param {Cluster} c The cluster that the mouse moved over.
|
|
93
|
-
* @event
|
|
94
|
-
*/
|
|
95
|
-
google.maps.event.trigger(_this.cluster.getClusterer(), 'mouseover', _this.cluster);
|
|
96
|
-
});
|
|
97
|
-
google.maps.event.addDomListener(this.div, 'mouseout', function () {
|
|
98
|
-
/**
|
|
99
|
-
* This event is fired when the mouse moves out of a cluster marker.
|
|
100
|
-
* @name MarkerClusterer#mouseout
|
|
101
|
-
* @param {Cluster} c The cluster that the mouse moved out of.
|
|
102
|
-
* @event
|
|
103
|
-
*/
|
|
104
|
-
google.maps.event.trigger(_this.cluster.getClusterer(), 'mouseout', _this.cluster);
|
|
105
|
-
});
|
|
146
|
+
this.getMap(), 'bounds_changed', this.onBoundsChanged);
|
|
147
|
+
this.div.addEventListener('mousedown', this.onMouseDown);
|
|
148
|
+
this.div.addEventListener('click', this.onClick);
|
|
149
|
+
this.div.addEventListener('mouseover', this.onMouseOver);
|
|
150
|
+
this.div.addEventListener('mouseout', this.onMouseOut);
|
|
106
151
|
};
|
|
107
152
|
ClusterIcon.prototype.onRemove = function () {
|
|
108
153
|
if (this.div && this.div.parentNode) {
|
|
@@ -110,16 +155,23 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
110
155
|
if (this.boundsChangedListener !== null) {
|
|
111
156
|
google.maps.event.removeListener(this.boundsChangedListener);
|
|
112
157
|
}
|
|
113
|
-
|
|
158
|
+
this.div.removeEventListener('mousedown', this.onMouseDown);
|
|
159
|
+
this.div.removeEventListener('click', this.onClick);
|
|
160
|
+
this.div.removeEventListener('mouseover', this.onMouseOver);
|
|
161
|
+
this.div.removeEventListener('mouseout', this.onMouseOut);
|
|
114
162
|
this.div.parentNode.removeChild(this.div);
|
|
163
|
+
if (this.timeOut !== null) {
|
|
164
|
+
window.clearTimeout(this.timeOut);
|
|
165
|
+
this.timeOut = null;
|
|
166
|
+
}
|
|
115
167
|
this.div = null;
|
|
116
168
|
}
|
|
117
169
|
};
|
|
118
170
|
ClusterIcon.prototype.draw = function () {
|
|
119
171
|
if (this.visible && this.div !== null && this.center) {
|
|
120
|
-
var
|
|
121
|
-
this.div.style.top = y
|
|
122
|
-
this.div.style.left = x
|
|
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';
|
|
123
175
|
}
|
|
124
176
|
};
|
|
125
177
|
ClusterIcon.prototype.hide = function () {
|
|
@@ -137,7 +189,9 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
137
189
|
var spriteH = parseInt(bp[0].replace(/^\s+|\s+$/g, ''), 10);
|
|
138
190
|
var spriteV = parseInt(bp[1].replace(/^\s+|\s+$/g, ''), 10);
|
|
139
191
|
var pos = this.getPosFromLatLng(this.center);
|
|
140
|
-
if (this.sums === null ||
|
|
192
|
+
if (this.sums === null ||
|
|
193
|
+
typeof this.sums.title === 'undefined' ||
|
|
194
|
+
this.sums.title === '') {
|
|
141
195
|
divTitle = this.cluster.getClusterer().getTitle();
|
|
142
196
|
}
|
|
143
197
|
else {
|
|
@@ -145,8 +199,8 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
145
199
|
}
|
|
146
200
|
this.div.style.cursor = 'pointer';
|
|
147
201
|
this.div.style.position = 'absolute';
|
|
148
|
-
this.div.style.top = "".concat(pos.y, "px");
|
|
149
|
-
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';
|
|
150
204
|
this.div.style.width = "".concat(this.width, "px");
|
|
151
205
|
this.div.style.height = "".concat(this.height, "px");
|
|
152
206
|
var img = document.createElement('img');
|
|
@@ -203,20 +257,20 @@ var ClusterIcon = /** @class */ (function () {
|
|
|
203
257
|
this.center = center;
|
|
204
258
|
};
|
|
205
259
|
ClusterIcon.prototype.getPosFromLatLng = function (latlng) {
|
|
206
|
-
// @ts-ignore
|
|
207
260
|
var pos = this.getProjection().fromLatLngToDivPixel(latlng);
|
|
208
|
-
pos
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
261
|
+
if (pos !== null) {
|
|
262
|
+
pos.x -= this.anchorIcon[1];
|
|
263
|
+
pos.y -= this.anchorIcon[0];
|
|
264
|
+
}
|
|
212
265
|
return pos;
|
|
213
266
|
};
|
|
214
267
|
return ClusterIcon;
|
|
215
|
-
}());
|
|
268
|
+
}(google.maps.OverlayView));
|
|
216
269
|
|
|
217
270
|
var Cluster = /** @class */ (function () {
|
|
218
271
|
function Cluster(markerClusterer) {
|
|
219
272
|
this.markerClusterer = markerClusterer;
|
|
273
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
220
274
|
// @ts-ignore
|
|
221
275
|
this.map = this.markerClusterer.getMap();
|
|
222
276
|
this.gridSize = this.markerClusterer.getGridSize();
|
|
@@ -254,9 +308,11 @@ var Cluster = /** @class */ (function () {
|
|
|
254
308
|
return bounds;
|
|
255
309
|
};
|
|
256
310
|
Cluster.prototype.remove = function () {
|
|
311
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
257
312
|
// @ts-ignore
|
|
258
313
|
this.clusterIcon.setMap(null);
|
|
259
314
|
this.markers = [];
|
|
315
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
260
316
|
// @ts-ignore
|
|
261
317
|
delete this.markers;
|
|
262
318
|
};
|
|
@@ -344,11 +400,9 @@ var Cluster = /** @class */ (function () {
|
|
|
344
400
|
if (this.markers.includes) {
|
|
345
401
|
return this.markers.includes(marker);
|
|
346
402
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
return true;
|
|
351
|
-
}
|
|
403
|
+
for (var i = 0; i < this.markers.length; i++) {
|
|
404
|
+
if (marker === this.markers[i]) {
|
|
405
|
+
return true;
|
|
352
406
|
}
|
|
353
407
|
}
|
|
354
408
|
return false;
|
|
@@ -356,7 +410,6 @@ var Cluster = /** @class */ (function () {
|
|
|
356
410
|
return Cluster;
|
|
357
411
|
}());
|
|
358
412
|
|
|
359
|
-
/* global google */
|
|
360
413
|
/**
|
|
361
414
|
* Supports up to 9007199254740991 (Number.MAX_SAFE_INTEGER) markers
|
|
362
415
|
* which is not a problem as max array length is 4294967296 (2**32)
|
|
@@ -377,85 +430,86 @@ var IMAGE_PATH = 'https://developers.google.com/maps/documentation/javascript/ex
|
|
|
377
430
|
var IMAGE_EXTENSION = 'png';
|
|
378
431
|
var IMAGE_SIZES = [53, 56, 66, 78, 90];
|
|
379
432
|
var CLUSTERER_CLASS = 'cluster';
|
|
380
|
-
var Clusterer = /** @class */ (function () {
|
|
433
|
+
var Clusterer = /** @class */ (function (_super) {
|
|
434
|
+
__extends(Clusterer, _super);
|
|
381
435
|
function Clusterer(map, optMarkers, optOptions) {
|
|
382
436
|
if (optMarkers === void 0) { optMarkers = []; }
|
|
383
437
|
if (optOptions === void 0) { optOptions = {}; }
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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;
|
|
396
451
|
if (optOptions.zoomOnClick !== undefined) {
|
|
397
|
-
|
|
452
|
+
_this.zoomOnClick = optOptions.zoomOnClick;
|
|
398
453
|
}
|
|
399
|
-
|
|
454
|
+
_this.averageCenter = false;
|
|
400
455
|
if (optOptions.averageCenter !== undefined) {
|
|
401
|
-
|
|
456
|
+
_this.averageCenter = optOptions.averageCenter;
|
|
402
457
|
}
|
|
403
|
-
|
|
458
|
+
_this.ignoreHidden = false;
|
|
404
459
|
if (optOptions.ignoreHidden !== undefined) {
|
|
405
|
-
|
|
460
|
+
_this.ignoreHidden = optOptions.ignoreHidden;
|
|
406
461
|
}
|
|
407
|
-
|
|
462
|
+
_this.enableRetinaIcons = false;
|
|
408
463
|
if (optOptions.enableRetinaIcons !== undefined) {
|
|
409
|
-
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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;
|
|
418
473
|
if (navigator.userAgent.toLowerCase().indexOf('msie') !== -1) {
|
|
419
474
|
// Try to avoid IE timeout when processing a huge number of markers:
|
|
420
|
-
|
|
475
|
+
_this.batchSize = _this.batchSizeIE;
|
|
421
476
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
477
|
+
_this.timerRefStatic = null;
|
|
478
|
+
_this.setupStyles();
|
|
479
|
+
_this.addMarkers(optMarkers, true);
|
|
480
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
425
481
|
// @ts-ignore
|
|
426
|
-
|
|
482
|
+
_this.setMap(map); // Note: this causes onAdd to be called
|
|
483
|
+
return _this;
|
|
427
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
|
+
};
|
|
428
501
|
Clusterer.prototype.onAdd = function () {
|
|
429
|
-
var
|
|
430
|
-
|
|
431
|
-
this.activeMap = this.getMap();
|
|
502
|
+
var map = this.getMap();
|
|
503
|
+
this.activeMap = map;
|
|
432
504
|
this.ready = true;
|
|
433
505
|
this.repaint();
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
// zoom slider is clicked, a "zoom_changed" event is fired even though
|
|
442
|
-
// the map doesn't zoom out any further. In this situation, no "idle"
|
|
443
|
-
// event is triggered so the cluster markers that have been removed
|
|
444
|
-
// do not get redrawn. Same goes for a zoom in at maxZoom.
|
|
445
|
-
if (
|
|
446
|
-
// @ts-ignore
|
|
447
|
-
_this.getMap().getZoom() === (_this.get('minZoom') || 0) ||
|
|
448
|
-
// @ts-ignore
|
|
449
|
-
_this.getMap().getZoom() === _this.get('maxZoom')) {
|
|
450
|
-
google.maps.event.trigger(_this, 'idle');
|
|
451
|
-
}
|
|
452
|
-
}),
|
|
453
|
-
google.maps.event.addListener(
|
|
454
|
-
// @ts-ignore
|
|
455
|
-
this.getMap(), 'idle', function () {
|
|
456
|
-
_this.redraw();
|
|
457
|
-
}),
|
|
458
|
-
];
|
|
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
|
+
}
|
|
459
513
|
};
|
|
460
514
|
Clusterer.prototype.onRemove = function () {
|
|
461
515
|
// Put all the managed markers back on the map:
|
|
@@ -500,6 +554,7 @@ var Clusterer = /** @class */ (function () {
|
|
|
500
554
|
bounds.extend(position);
|
|
501
555
|
}
|
|
502
556
|
}
|
|
557
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
503
558
|
// @ts-ignore
|
|
504
559
|
this.getMap().fitBounds(bounds);
|
|
505
560
|
};
|
|
@@ -691,26 +746,39 @@ var Clusterer = /** @class */ (function () {
|
|
|
691
746
|
}, 0);
|
|
692
747
|
};
|
|
693
748
|
Clusterer.prototype.getExtendedBounds = function (bounds) {
|
|
749
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
694
750
|
// @ts-ignore
|
|
695
751
|
var projection = this.getProjection();
|
|
696
752
|
// Convert the points to pixels and the extend out by the grid size.
|
|
697
753
|
var trPix = projection.fromLatLngToDivPixel(
|
|
698
754
|
// Turn the bounds into latlng.
|
|
699
755
|
new google.maps.LatLng(bounds.getNorthEast().lat(), bounds.getNorthEast().lng()));
|
|
700
|
-
trPix
|
|
701
|
-
|
|
756
|
+
if (trPix !== null) {
|
|
757
|
+
trPix.x += this.gridSize;
|
|
758
|
+
trPix.y -= this.gridSize;
|
|
759
|
+
}
|
|
702
760
|
var blPix = projection.fromLatLngToDivPixel(
|
|
703
761
|
// Turn the bounds into latlng.
|
|
704
762
|
new google.maps.LatLng(bounds.getSouthWest().lat(), bounds.getSouthWest().lng()));
|
|
705
|
-
blPix
|
|
706
|
-
|
|
763
|
+
if (blPix !== null) {
|
|
764
|
+
blPix.x -= this.gridSize;
|
|
765
|
+
blPix.y += this.gridSize;
|
|
766
|
+
}
|
|
707
767
|
// Extend the bounds to contain the new bounds.
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
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
|
+
}
|
|
714
782
|
return bounds;
|
|
715
783
|
};
|
|
716
784
|
Clusterer.prototype.redraw = function () {
|
|
@@ -792,35 +860,29 @@ var Clusterer = /** @class */ (function () {
|
|
|
792
860
|
google.maps.event.trigger(this, 'clusteringbegin', this);
|
|
793
861
|
if (this.timerRefStatic !== null) {
|
|
794
862
|
window.clearTimeout(this.timerRefStatic);
|
|
863
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
795
864
|
// @ts-ignore
|
|
796
865
|
delete this.timerRefStatic;
|
|
797
866
|
}
|
|
798
867
|
}
|
|
868
|
+
var map = this.getMap();
|
|
869
|
+
var bounds = map !== null && 'getBounds' in map ? map.getBounds() : null;
|
|
799
870
|
// Get our current map view bounds.
|
|
800
871
|
// Create a new bounds object so we don't affect the map.
|
|
801
872
|
//
|
|
802
873
|
// See Comments 9 & 11 on Issue 3651 relating to this workaround for a Google Maps bug:
|
|
803
874
|
var mapBounds =
|
|
875
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
804
876
|
// @ts-ignore
|
|
805
|
-
|
|
806
|
-
? new google.maps.LatLngBounds(
|
|
807
|
-
// @ts-ignore
|
|
808
|
-
this.getMap()
|
|
809
|
-
.getBounds()
|
|
810
|
-
.getSouthWest(),
|
|
811
|
-
// @ts-ignore
|
|
812
|
-
this.getMap()
|
|
813
|
-
.getBounds()
|
|
814
|
-
.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())
|
|
815
879
|
: new google.maps.LatLngBounds(new google.maps.LatLng(85.02070771743472, -178.48388434375), new google.maps.LatLng(-85.08136444384544, 178.00048865625));
|
|
816
|
-
var
|
|
880
|
+
var extendedMapBounds = this.getExtendedBounds(mapBounds);
|
|
817
881
|
var iLast = Math.min(iFirst + this.batchSize, this.markers.length);
|
|
818
882
|
for (var i = iFirst; i < iLast; i++) {
|
|
819
883
|
var marker = this.markers[i];
|
|
820
|
-
if (!marker.isAdded && this.isMarkerInBounds(marker,
|
|
821
|
-
|
|
822
|
-
this.addToClosestCluster(marker);
|
|
823
|
-
}
|
|
884
|
+
if (!marker.isAdded && this.isMarkerInBounds(marker, extendedMapBounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
|
|
885
|
+
this.addToClosestCluster(marker);
|
|
824
886
|
}
|
|
825
887
|
}
|
|
826
888
|
if (iLast < this.markers.length) {
|
|
@@ -845,17 +907,14 @@ var Clusterer = /** @class */ (function () {
|
|
|
845
907
|
};
|
|
846
908
|
Clusterer.prototype.extend = function (obj1, obj2) {
|
|
847
909
|
return function applyExtend(object) {
|
|
848
|
-
// eslint-disable-next-line guard-for-in
|
|
849
910
|
for (var property in object.prototype) {
|
|
850
|
-
|
|
851
|
-
this.prototype[property] = object.prototype[property];
|
|
911
|
+
this.prototype.set(property, object.prototype.get(property));
|
|
852
912
|
}
|
|
853
|
-
// @ts-ignore
|
|
854
913
|
return this;
|
|
855
914
|
}.apply(obj1, [obj2]);
|
|
856
915
|
};
|
|
857
916
|
return Clusterer;
|
|
858
|
-
}());
|
|
917
|
+
}(google.maps.OverlayView));
|
|
859
918
|
|
|
860
919
|
export { Cluster, ClusterIcon, Clusterer };
|
|
861
920
|
//# sourceMappingURL=esm.js.map
|