@react-google-maps/marker-clusterer 2.10.0 → 2.11.1
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 +262 -223
- 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 +262 -223
- 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 -6
- package/dist/umd.js +262 -223
- 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 +7 -7
- package/src/Cluster.tsx +4 -8
- package/src/ClusterIcon.tsx +183 -114
- package/src/Clusterer.tsx +92 -82
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
|
+
var map = markerClusterer_1.getMap();
|
|
90
|
+
if (map !== null && 'fitBounds' in map) {
|
|
91
|
+
map.fitBounds(bounds_1);
|
|
92
|
+
}
|
|
93
|
+
// There is a fix for Issue 170 here:
|
|
94
|
+
this.timeOut = window.setTimeout(function () {
|
|
95
|
+
var map = markerClusterer_1.getMap();
|
|
96
|
+
if (map !== null) {
|
|
97
|
+
if ('fitBounds' in map) {
|
|
98
|
+
map.fitBounds(bounds_1);
|
|
99
|
+
}
|
|
100
|
+
var zoom = map.getZoom() || 0;
|
|
101
|
+
// Don't zoom beyond the max zoom level
|
|
102
|
+
if (maxZoom_1 !== null &&
|
|
103
|
+
zoom > maxZoom_1) {
|
|
104
|
+
map.setZoom(maxZoom_1 + 1);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}, 100);
|
|
108
|
+
}
|
|
109
|
+
// Prevent event propagation to the map:
|
|
110
|
+
event.cancelBubble = true;
|
|
111
|
+
if (event.stopPropagation) {
|
|
112
|
+
event.stopPropagation();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
ClusterIcon.prototype.onMouseOver = function () {
|
|
117
|
+
/**
|
|
118
|
+
* This event is fired when the mouse moves over a cluster marker.
|
|
119
|
+
* @name MarkerClusterer#mouseover
|
|
120
|
+
* @param {Cluster} c The cluster that the mouse moved over.
|
|
121
|
+
* @event
|
|
122
|
+
*/
|
|
123
|
+
google.maps.event.trigger(this.cluster.getClusterer(), 'mouseover', this.cluster);
|
|
124
|
+
};
|
|
125
|
+
ClusterIcon.prototype.onMouseOut = function () {
|
|
126
|
+
/**
|
|
127
|
+
* This event is fired when the mouse moves out of a cluster marker.
|
|
128
|
+
* @name MarkerClusterer#mouseout
|
|
129
|
+
* @param {Cluster} c The cluster that the mouse moved out of.
|
|
130
|
+
* @event
|
|
131
|
+
*/
|
|
132
|
+
google.maps.event.trigger(this.cluster.getClusterer(), 'mouseout', this.cluster);
|
|
133
|
+
};
|
|
28
134
|
ClusterIcon.prototype.onAdd = function () {
|
|
29
|
-
var
|
|
30
|
-
var cMouseDownInCluster;
|
|
31
|
-
var cDraggingMapByCluster;
|
|
135
|
+
var _a;
|
|
32
136
|
this.div = document.createElement('div');
|
|
33
137
|
this.div.className = this.className;
|
|
34
138
|
if (this.visible) {
|
|
35
139
|
this.show();
|
|
36
140
|
}
|
|
37
|
-
|
|
38
|
-
this.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
cDraggingMapByCluster = false;
|
|
48
|
-
});
|
|
49
|
-
google.maps.event.addListener(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.addListener(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.addListener(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
|
-
});
|
|
141
|
+
(_a = this.getPanes()) === null || _a === void 0 ? void 0 : _a.overlayMouseTarget.appendChild(this.div);
|
|
142
|
+
var map = this.getMap();
|
|
143
|
+
if (map !== null) {
|
|
144
|
+
// Fix for Issue 157
|
|
145
|
+
this.boundsChangedListener = google.maps.event.addListener(map, 'bounds_changed', this.onBoundsChanged);
|
|
146
|
+
this.div.addEventListener('mousedown', this.onMouseDown);
|
|
147
|
+
this.div.addEventListener('click', this.onClick);
|
|
148
|
+
this.div.addEventListener('mouseover', this.onMouseOver);
|
|
149
|
+
this.div.addEventListener('mouseout', this.onMouseOut);
|
|
150
|
+
}
|
|
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,22 +257,19 @@ 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;
|
|
220
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
221
|
-
// @ts-ignore
|
|
222
273
|
this.map = this.markerClusterer.getMap();
|
|
223
274
|
this.gridSize = this.markerClusterer.getGridSize();
|
|
224
275
|
this.minClusterSize = this.markerClusterer.getMinimumClusterSize();
|
|
@@ -255,8 +306,6 @@ var Cluster = /** @class */ (function () {
|
|
|
255
306
|
return bounds;
|
|
256
307
|
};
|
|
257
308
|
Cluster.prototype.remove = function () {
|
|
258
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
259
|
-
// @ts-ignore
|
|
260
309
|
this.clusterIcon.setMap(null);
|
|
261
310
|
this.markers = [];
|
|
262
311
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -264,6 +313,7 @@ var Cluster = /** @class */ (function () {
|
|
|
264
313
|
delete this.markers;
|
|
265
314
|
};
|
|
266
315
|
Cluster.prototype.addMarker = function (marker) {
|
|
316
|
+
var _a;
|
|
267
317
|
if (this.isMarkerAlreadyAdded(marker)) {
|
|
268
318
|
return false;
|
|
269
319
|
}
|
|
@@ -288,7 +338,7 @@ var Cluster = /** @class */ (function () {
|
|
|
288
338
|
this.markers.push(marker);
|
|
289
339
|
var mCount = this.markers.length;
|
|
290
340
|
var maxZoom = this.markerClusterer.getMaxZoom();
|
|
291
|
-
var zoom = this.map.getZoom();
|
|
341
|
+
var zoom = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getZoom();
|
|
292
342
|
if (maxZoom !== null && typeof zoom !== 'undefined' && zoom > maxZoom) {
|
|
293
343
|
// Zoomed in past max zoom, so show the marker.
|
|
294
344
|
if (marker.getMap() !== this.map) {
|
|
@@ -325,9 +375,10 @@ var Cluster = /** @class */ (function () {
|
|
|
325
375
|
this.bounds = this.markerClusterer.getExtendedBounds(new google.maps.LatLngBounds(this.center, this.center));
|
|
326
376
|
};
|
|
327
377
|
Cluster.prototype.updateIcon = function () {
|
|
378
|
+
var _a;
|
|
328
379
|
var mCount = this.markers.length;
|
|
329
380
|
var maxZoom = this.markerClusterer.getMaxZoom();
|
|
330
|
-
var zoom = this.map.getZoom();
|
|
381
|
+
var zoom = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getZoom();
|
|
331
382
|
if (maxZoom !== null && typeof zoom !== 'undefined' && zoom > maxZoom) {
|
|
332
383
|
this.clusterIcon.hide();
|
|
333
384
|
return;
|
|
@@ -357,7 +408,6 @@ var Cluster = /** @class */ (function () {
|
|
|
357
408
|
return Cluster;
|
|
358
409
|
}());
|
|
359
410
|
|
|
360
|
-
/* global google */
|
|
361
411
|
/**
|
|
362
412
|
* Supports up to 9007199254740991 (Number.MAX_SAFE_INTEGER) markers
|
|
363
413
|
* which is not a problem as max array length is 4294967296 (2**32)
|
|
@@ -378,91 +428,84 @@ var IMAGE_PATH = 'https://developers.google.com/maps/documentation/javascript/ex
|
|
|
378
428
|
var IMAGE_EXTENSION = 'png';
|
|
379
429
|
var IMAGE_SIZES = [53, 56, 66, 78, 90];
|
|
380
430
|
var CLUSTERER_CLASS = 'cluster';
|
|
381
|
-
var Clusterer = /** @class */ (function () {
|
|
431
|
+
var Clusterer = /** @class */ (function (_super) {
|
|
432
|
+
__extends(Clusterer, _super);
|
|
382
433
|
function Clusterer(map, optMarkers, optOptions) {
|
|
383
434
|
if (optMarkers === void 0) { optMarkers = []; }
|
|
384
435
|
if (optOptions === void 0) { optOptions = {}; }
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
436
|
+
var _this = _super.call(this) || this;
|
|
437
|
+
_this.extend(Clusterer, google.maps.OverlayView);
|
|
438
|
+
_this.markers = [];
|
|
439
|
+
_this.clusters = [];
|
|
440
|
+
_this.listeners = [];
|
|
441
|
+
_this.activeMap = null;
|
|
442
|
+
_this.ready = false;
|
|
443
|
+
_this.gridSize = optOptions.gridSize || 60;
|
|
444
|
+
_this.minClusterSize = optOptions.minimumClusterSize || 2;
|
|
445
|
+
_this.maxZoom = optOptions.maxZoom || null;
|
|
446
|
+
_this.styles = optOptions.styles || [];
|
|
447
|
+
_this.title = optOptions.title || '';
|
|
448
|
+
_this.zoomOnClick = true;
|
|
397
449
|
if (optOptions.zoomOnClick !== undefined) {
|
|
398
|
-
|
|
450
|
+
_this.zoomOnClick = optOptions.zoomOnClick;
|
|
399
451
|
}
|
|
400
|
-
|
|
452
|
+
_this.averageCenter = false;
|
|
401
453
|
if (optOptions.averageCenter !== undefined) {
|
|
402
|
-
|
|
454
|
+
_this.averageCenter = optOptions.averageCenter;
|
|
403
455
|
}
|
|
404
|
-
|
|
456
|
+
_this.ignoreHidden = false;
|
|
405
457
|
if (optOptions.ignoreHidden !== undefined) {
|
|
406
|
-
|
|
458
|
+
_this.ignoreHidden = optOptions.ignoreHidden;
|
|
407
459
|
}
|
|
408
|
-
|
|
460
|
+
_this.enableRetinaIcons = false;
|
|
409
461
|
if (optOptions.enableRetinaIcons !== undefined) {
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
462
|
+
_this.enableRetinaIcons = optOptions.enableRetinaIcons;
|
|
463
|
+
}
|
|
464
|
+
_this.imagePath = optOptions.imagePath || IMAGE_PATH;
|
|
465
|
+
_this.imageExtension = optOptions.imageExtension || IMAGE_EXTENSION;
|
|
466
|
+
_this.imageSizes = optOptions.imageSizes || IMAGE_SIZES;
|
|
467
|
+
_this.calculator = optOptions.calculator || CALCULATOR;
|
|
468
|
+
_this.batchSize = optOptions.batchSize || BATCH_SIZE;
|
|
469
|
+
_this.batchSizeIE = optOptions.batchSizeIE || BATCH_SIZE_IE;
|
|
470
|
+
_this.clusterClass = optOptions.clusterClass || CLUSTERER_CLASS;
|
|
419
471
|
if (navigator.userAgent.toLowerCase().indexOf('msie') !== -1) {
|
|
420
472
|
// Try to avoid IE timeout when processing a huge number of markers:
|
|
421
|
-
|
|
473
|
+
_this.batchSize = _this.batchSizeIE;
|
|
422
474
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
//
|
|
427
|
-
|
|
428
|
-
this.setMap(map); // Note: this causes onAdd to be called
|
|
475
|
+
_this.timerRefStatic = null;
|
|
476
|
+
_this.setupStyles();
|
|
477
|
+
_this.addMarkers(optMarkers, true);
|
|
478
|
+
_this.setMap(map); // Note: this causes onAdd to be called
|
|
479
|
+
return _this;
|
|
429
480
|
}
|
|
481
|
+
Clusterer.prototype.onZoomChanged = function () {
|
|
482
|
+
var _a, _b;
|
|
483
|
+
this.resetViewport(false);
|
|
484
|
+
// Workaround for this Google bug: when map is at level 0 and "-" of
|
|
485
|
+
// zoom slider is clicked, a "zoom_changed" event is fired even though
|
|
486
|
+
// the map doesn't zoom out any further. In this situation, no "idle"
|
|
487
|
+
// event is triggered so the cluster markers that have been removed
|
|
488
|
+
// do not get redrawn. Same goes for a zoom in at maxZoom.
|
|
489
|
+
if (((_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.getZoom()) === (this.get('minZoom') || 0) ||
|
|
490
|
+
((_b = this.getMap()) === null || _b === void 0 ? void 0 : _b.getZoom()) === this.get('maxZoom')) {
|
|
491
|
+
google.maps.event.trigger(this, 'idle');
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
Clusterer.prototype.onIdle = function () {
|
|
495
|
+
this.redraw();
|
|
496
|
+
};
|
|
430
497
|
Clusterer.prototype.onAdd = function () {
|
|
431
|
-
var
|
|
432
|
-
|
|
433
|
-
// @ts-ignore
|
|
434
|
-
this.activeMap = this.getMap();
|
|
498
|
+
var map = this.getMap();
|
|
499
|
+
this.activeMap = map;
|
|
435
500
|
this.ready = true;
|
|
436
501
|
this.repaint();
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
// Workaround for this Google bug: when map is at level 0 and "-" of
|
|
445
|
-
// zoom slider is clicked, a "zoom_changed" event is fired even though
|
|
446
|
-
// the map doesn't zoom out any further. In this situation, no "idle"
|
|
447
|
-
// event is triggered so the cluster markers that have been removed
|
|
448
|
-
// do not get redrawn. Same goes for a zoom in at maxZoom.
|
|
449
|
-
if (
|
|
450
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
451
|
-
// @ts-ignore
|
|
452
|
-
_this.getMap().getZoom() === (_this.get('minZoom') || 0) ||
|
|
453
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
454
|
-
// @ts-ignore
|
|
455
|
-
_this.getMap().getZoom() === _this.get('maxZoom')) {
|
|
456
|
-
google.maps.event.trigger(_this, 'idle');
|
|
457
|
-
}
|
|
458
|
-
}),
|
|
459
|
-
google.maps.event.addListener(
|
|
460
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
461
|
-
// @ts-ignore
|
|
462
|
-
this.getMap(), 'idle', function () {
|
|
463
|
-
_this.redraw();
|
|
464
|
-
}),
|
|
465
|
-
];
|
|
502
|
+
if (map !== null) {
|
|
503
|
+
// Add the map event listeners
|
|
504
|
+
this.listeners = [
|
|
505
|
+
google.maps.event.addListener(map, 'zoom_changed', this.onZoomChanged),
|
|
506
|
+
google.maps.event.addListener(map, 'idle', this.onIdle),
|
|
507
|
+
];
|
|
508
|
+
}
|
|
466
509
|
};
|
|
467
510
|
Clusterer.prototype.onRemove = function () {
|
|
468
511
|
// Put all the managed markers back on the map:
|
|
@@ -507,9 +550,10 @@ var Clusterer = /** @class */ (function () {
|
|
|
507
550
|
bounds.extend(position);
|
|
508
551
|
}
|
|
509
552
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
553
|
+
var map = this.getMap();
|
|
554
|
+
if (map !== null && 'fitBounds' in map) {
|
|
555
|
+
map.fitBounds(bounds);
|
|
556
|
+
}
|
|
513
557
|
};
|
|
514
558
|
Clusterer.prototype.getGridSize = function () {
|
|
515
559
|
return this.gridSize;
|
|
@@ -699,27 +743,37 @@ var Clusterer = /** @class */ (function () {
|
|
|
699
743
|
}, 0);
|
|
700
744
|
};
|
|
701
745
|
Clusterer.prototype.getExtendedBounds = function (bounds) {
|
|
702
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
703
|
-
// @ts-ignore
|
|
704
746
|
var projection = this.getProjection();
|
|
705
747
|
// Convert the points to pixels and the extend out by the grid size.
|
|
706
748
|
var trPix = projection.fromLatLngToDivPixel(
|
|
707
749
|
// Turn the bounds into latlng.
|
|
708
750
|
new google.maps.LatLng(bounds.getNorthEast().lat(), bounds.getNorthEast().lng()));
|
|
709
|
-
trPix
|
|
710
|
-
|
|
751
|
+
if (trPix !== null) {
|
|
752
|
+
trPix.x += this.gridSize;
|
|
753
|
+
trPix.y -= this.gridSize;
|
|
754
|
+
}
|
|
711
755
|
var blPix = projection.fromLatLngToDivPixel(
|
|
712
756
|
// Turn the bounds into latlng.
|
|
713
757
|
new google.maps.LatLng(bounds.getSouthWest().lat(), bounds.getSouthWest().lng()));
|
|
714
|
-
blPix
|
|
715
|
-
|
|
758
|
+
if (blPix !== null) {
|
|
759
|
+
blPix.x -= this.gridSize;
|
|
760
|
+
blPix.y += this.gridSize;
|
|
761
|
+
}
|
|
716
762
|
// Extend the bounds to contain the new bounds.
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
763
|
+
if (trPix !== null) {
|
|
764
|
+
// Convert the pixel points back to LatLng nw
|
|
765
|
+
var point1 = projection.fromDivPixelToLatLng(trPix);
|
|
766
|
+
if (point1 !== null) {
|
|
767
|
+
bounds.extend(point1);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
if (blPix !== null) {
|
|
771
|
+
// Convert the pixel points back to LatLng sw
|
|
772
|
+
var point2 = projection.fromDivPixelToLatLng(blPix);
|
|
773
|
+
if (point2 !== null) {
|
|
774
|
+
bounds.extend(point2);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
723
777
|
return bounds;
|
|
724
778
|
};
|
|
725
779
|
Clusterer.prototype.redraw = function () {
|
|
@@ -806,31 +860,21 @@ var Clusterer = /** @class */ (function () {
|
|
|
806
860
|
delete this.timerRefStatic;
|
|
807
861
|
}
|
|
808
862
|
}
|
|
863
|
+
var map = this.getMap();
|
|
864
|
+
var bounds = map !== null && 'getBounds' in map ? map.getBounds() : null;
|
|
865
|
+
var zoom = (map === null || map === void 0 ? void 0 : map.getZoom()) || 0;
|
|
809
866
|
// Get our current map view bounds.
|
|
810
867
|
// Create a new bounds object so we don't affect the map.
|
|
811
868
|
//
|
|
812
869
|
// See Comments 9 & 11 on Issue 3651 relating to this workaround for a Google Maps bug:
|
|
813
|
-
var mapBounds =
|
|
814
|
-
|
|
815
|
-
// @ts-ignore
|
|
816
|
-
this.getMap().getZoom() > 3
|
|
817
|
-
? new google.maps.LatLngBounds(
|
|
818
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
819
|
-
// @ts-ignore
|
|
820
|
-
this.getMap()
|
|
821
|
-
.getBounds()
|
|
822
|
-
.getSouthWest(),
|
|
823
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
824
|
-
// @ts-ignore
|
|
825
|
-
this.getMap()
|
|
826
|
-
.getBounds()
|
|
827
|
-
.getNorthEast())
|
|
870
|
+
var mapBounds = zoom > 3
|
|
871
|
+
? new google.maps.LatLngBounds(bounds === null || bounds === void 0 ? void 0 : bounds.getSouthWest(), bounds === null || bounds === void 0 ? void 0 : bounds.getNorthEast())
|
|
828
872
|
: new google.maps.LatLngBounds(new google.maps.LatLng(85.02070771743472, -178.48388434375), new google.maps.LatLng(-85.08136444384544, 178.00048865625));
|
|
829
|
-
var
|
|
873
|
+
var extendedMapBounds = this.getExtendedBounds(mapBounds);
|
|
830
874
|
var iLast = Math.min(iFirst + this.batchSize, this.markers.length);
|
|
831
875
|
for (var i = iFirst; i < iLast; i++) {
|
|
832
876
|
var marker = this.markers[i];
|
|
833
|
-
if (!marker.isAdded && this.isMarkerInBounds(marker,
|
|
877
|
+
if (!marker.isAdded && this.isMarkerInBounds(marker, extendedMapBounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
|
|
834
878
|
this.addToClosestCluster(marker);
|
|
835
879
|
}
|
|
836
880
|
}
|
|
@@ -856,19 +900,14 @@ var Clusterer = /** @class */ (function () {
|
|
|
856
900
|
};
|
|
857
901
|
Clusterer.prototype.extend = function (obj1, obj2) {
|
|
858
902
|
return function applyExtend(object) {
|
|
859
|
-
// eslint-disable-next-line guard-for-in
|
|
860
903
|
for (var property in object.prototype) {
|
|
861
|
-
|
|
862
|
-
// @ts-ignore
|
|
863
|
-
this.prototype[property] = object.prototype[property];
|
|
904
|
+
this.prototype.set(property, object.prototype.get(property));
|
|
864
905
|
}
|
|
865
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
866
|
-
// @ts-ignore
|
|
867
906
|
return this;
|
|
868
907
|
}.apply(obj1, [obj2]);
|
|
869
908
|
};
|
|
870
909
|
return Clusterer;
|
|
871
|
-
}());
|
|
910
|
+
}(google.maps.OverlayView));
|
|
872
911
|
|
|
873
912
|
export { Cluster, ClusterIcon, Clusterer };
|
|
874
913
|
//# sourceMappingURL=esm.js.map
|