@react-google-maps/marker-clusterer 2.3.0 → 2.6.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/umd.js CHANGED
@@ -1,948 +1,952 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.markerClusterer = {}));
5
- }(this, (function (exports) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.markerClusterer = {}));
5
+ })(this, (function (exports) { 'use strict';
6
6
 
7
- var ClusterIcon = /** @class */ (function () {
8
- function ClusterIcon(cluster, styles) {
9
- cluster.getClusterer().extend(ClusterIcon, google.maps.OverlayView);
10
- this.cluster = cluster;
11
- this.className = this.cluster.getClusterer().getClusterClass();
12
- this.styles = styles;
13
- this.center = undefined;
14
- this.div = null;
15
- this.sums = null;
16
- this.visible = false;
17
- this.boundsChangedListener = null;
18
- this.url = '';
19
- this.height = 0;
20
- this.width = 0;
21
- this.anchorText = [0, 0];
22
- this.anchorIcon = [0, 0];
23
- this.textColor = 'black';
24
- this.textSize = 11;
25
- this.textDecoration = 'none';
26
- this.fontWeight = 'bold';
27
- this.fontStyle = 'normal';
28
- this.fontFamily = 'Arial,sans-serif';
29
- this.backgroundPosition = '0 0';
30
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
31
- // @ts-ignore
32
- this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
33
- }
34
- ClusterIcon.prototype.onAdd = function () {
35
- var _this = this;
36
- var cMouseDownInCluster;
37
- var cDraggingMapByCluster;
38
- this.div = document.createElement('div');
39
- this.div.className = this.className;
40
- if (this.visible) {
41
- this.show();
42
- }
43
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
44
- // @ts-ignore
45
- this.getPanes().overlayMouseTarget.appendChild(this.div);
46
- // Fix for Issue 157
47
- this.boundsChangedListener = google.maps.event.addListener(
48
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
49
- // @ts-ignore
50
- this.getMap(), 'boundschanged', function boundsChanged() {
51
- cDraggingMapByCluster = cMouseDownInCluster;
52
- });
53
- google.maps.event.addDomListener(this.div, 'mousedown', function onMouseDown() {
54
- cMouseDownInCluster = true;
55
- cDraggingMapByCluster = false;
56
- });
57
- // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
58
- google.maps.event.addDomListener(this.div, 'click',
59
- // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
60
- function (event) {
61
- cMouseDownInCluster = false;
62
- if (!cDraggingMapByCluster) {
63
- var markerClusterer_1 = _this.cluster.getClusterer();
64
- /**
65
- * This event is fired when a cluster marker is clicked.
66
- * @name MarkerClusterer#click
67
- * @param {Cluster} c The cluster that was clicked.
68
- * @event
69
- */
70
- google.maps.event.trigger(markerClusterer_1, 'click', _this.cluster);
71
- google.maps.event.trigger(markerClusterer_1, 'clusterclick', _this.cluster); // deprecated name
72
- // The default click handler follows. Disable it by setting
73
- // the zoomOnClick property to false.
74
- if (markerClusterer_1.getZoomOnClick()) {
75
- // Zoom into the cluster.
76
- var maxZoom_1 = markerClusterer_1.getMaxZoom();
77
- var bounds_1 = _this.cluster.getBounds();
78
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
79
- // @ts-ignore
80
- markerClusterer_1.getMap().fitBounds(bounds_1);
81
- // There is a fix for Issue 170 here:
82
- setTimeout(function timeout() {
83
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
84
- // @ts-ignore
85
- markerClusterer_1.getMap().fitBounds(bounds_1);
86
- // Don't zoom beyond the max zoom level
87
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
88
- // @ts-ignore
89
- if (maxZoom_1 !== null && markerClusterer_1.getMap().getZoom() > maxZoom_1) {
90
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
91
- // @ts-ignore
92
- markerClusterer_1.getMap().setZoom(maxZoom_1 + 1);
93
- }
94
- }, 100);
95
- }
96
- // Prevent event propagation to the map:
97
- event.cancelBubble = true;
98
- if (event.stopPropagation) {
99
- event.stopPropagation();
100
- }
101
- }
102
- });
103
- google.maps.event.addDomListener(this.div, 'mouseover',
104
- // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
105
- function () {
106
- /**
107
- * This event is fired when the mouse moves over a cluster marker.
108
- * @name MarkerClusterer#mouseover
109
- * @param {Cluster} c The cluster that the mouse moved over.
110
- * @event
111
- */
112
- google.maps.event.trigger(_this.cluster.getClusterer(), 'mouseover', _this.cluster);
113
- });
114
- // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
115
- google.maps.event.addDomListener(this.div, 'mouseout',
116
- // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
117
- function () {
118
- /**
119
- * This event is fired when the mouse moves out of a cluster marker.
120
- * @name MarkerClusterer#mouseout
121
- * @param {Cluster} c The cluster that the mouse moved out of.
122
- * @event
123
- */
124
- google.maps.event.trigger(_this.cluster.getClusterer(), 'mouseout', _this.cluster);
125
- });
126
- };
127
- ClusterIcon.prototype.onRemove = function () {
128
- if (this.div && this.div.parentNode) {
129
- this.hide();
130
- if (this.boundsChangedListener !== null) {
131
- google.maps.event.removeListener(this.boundsChangedListener);
132
- }
133
- google.maps.event.clearInstanceListeners(this.div);
134
- this.div.parentNode.removeChild(this.div);
135
- this.div = null;
136
- }
137
- };
138
- ClusterIcon.prototype.draw = function () {
139
- if (this.visible && this.div !== null && this.center) {
140
- var _a = this.getPosFromLatLng(this.center), x = _a.x, y = _a.y;
141
- this.div.style.top = y + 'px';
142
- this.div.style.left = x + 'px';
143
- }
144
- };
145
- ClusterIcon.prototype.hide = function () {
146
- if (this.div) {
147
- this.div.style.display = 'none';
148
- }
149
- this.visible = false;
150
- };
151
- ClusterIcon.prototype.show = function () {
152
- if (this.div && this.center) {
153
- var img = '', divTitle = '';
154
- // NOTE: values must be specified in px units
155
- var bp = this.backgroundPosition.split(' ');
156
- var spriteH = parseInt(bp[0].replace(/^\s+|\s+$/g, ''), 10);
157
- var spriteV = parseInt(bp[1].replace(/^\s+|\s+$/g, ''), 10);
158
- var pos = this.getPosFromLatLng(this.center);
159
- if (this.sums === null || typeof this.sums.title === 'undefined' || this.sums.title === '') {
160
- divTitle = this.cluster.getClusterer().getTitle();
161
- }
162
- else {
163
- divTitle = this.sums.title;
164
- }
165
- this.div.style.cssText = this.createCss(pos);
166
- img =
167
- "<img alt='" +
168
- divTitle +
169
- "' src='" +
170
- this.url +
171
- "' style='position: absolute; top: " +
172
- spriteV +
173
- 'px; left: ' +
174
- spriteH +
175
- 'px; ';
176
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
177
- //@ts-ignore
178
- if (!this.cluster.getClusterer().enableRetinaIcons) {
179
- img +=
180
- 'clip: rect(' +
181
- -1 * spriteV +
182
- 'px, ' +
183
- (-1 * spriteH + this.width) +
184
- 'px, ' +
185
- (-1 * spriteV + this.height) +
186
- 'px, ' +
187
- -1 * spriteH +
188
- 'px);';
189
- }
190
- img += "'>";
191
- this.div.innerHTML =
192
- img +
193
- "<div style='" +
194
- 'position: absolute;' +
195
- 'top: ' +
196
- this.anchorText[0] +
197
- 'px;' +
198
- 'left: ' +
199
- this.anchorText[1] +
200
- 'px;' +
201
- 'color: ' +
202
- this.textColor +
203
- ';' +
204
- 'font-size: ' +
205
- this.textSize +
206
- 'px;' +
207
- 'font-family: ' +
208
- this.fontFamily +
209
- ';' +
210
- 'font-weight: ' +
211
- this.fontWeight +
212
- ';' +
213
- 'font-style: ' +
214
- this.fontStyle +
215
- ';' +
216
- 'text-decoration: ' +
217
- this.textDecoration +
218
- ';' +
219
- 'text-align: center;' +
220
- 'width: ' +
221
- this.width +
222
- 'px;' +
223
- 'line-height:' +
224
- this.height +
225
- 'px;' +
226
- "'>" +
227
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
228
- // @ts-ignore
229
- this.sums.text +
230
- '</div>';
231
- this.div.title = divTitle;
232
- this.div.style.display = '';
233
- }
234
- this.visible = true;
235
- };
236
- ClusterIcon.prototype.useStyle = function (sums) {
237
- this.sums = sums;
238
- var style = this.styles[Math.min(this.styles.length - 1, Math.max(0, sums.index - 1))];
239
- this.url = style.url;
240
- this.height = style.height;
241
- this.width = style.width;
242
- if (style.className)
243
- this.className = this.className + " " + style.className;
244
- this.anchorText = style.anchorText || [0, 0];
245
- this.anchorIcon = style.anchorIcon || [this.height / 2, this.width / 2];
246
- this.textColor = style.textColor || 'black';
247
- this.textSize = style.textSize || 11;
248
- this.textDecoration = style.textDecoration || 'none';
249
- this.fontWeight = style.fontWeight || 'bold';
250
- this.fontStyle = style.fontStyle || 'normal';
251
- this.fontFamily = style.fontFamily || 'Arial,sans-serif';
252
- this.backgroundPosition = style.backgroundPosition || '0 0';
253
- };
254
- ClusterIcon.prototype.setCenter = function (center) {
255
- this.center = center;
256
- };
257
- ClusterIcon.prototype.createCss = function (pos) {
258
- var style = [];
259
- style.push('cursor: pointer;');
260
- style.push('position: absolute; top: ' + pos.y + 'px; left: ' + pos.x + 'px;');
261
- style.push('width: ' + this.width + 'px; height: ' + this.height + 'px;');
262
- return style.join('');
263
- };
264
- ClusterIcon.prototype.getPosFromLatLng = function (latlng) {
265
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
266
- // @ts-ignore
267
- var pos = this.getProjection().fromLatLngToDivPixel(latlng);
268
- pos.x -= this.anchorIcon[1];
269
- pos.y -= this.anchorIcon[0];
270
- // pos.x = pos.x
271
- // pos.y = pos.y
272
- return pos;
273
- };
274
- return ClusterIcon;
275
- }());
7
+ var ClusterIcon = /** @class */ (function () {
8
+ function ClusterIcon(cluster, styles) {
9
+ cluster.getClusterer().extend(ClusterIcon, google.maps.OverlayView);
10
+ this.cluster = cluster;
11
+ this.clusterClassName = this.cluster.getClusterer().getClusterClass();
12
+ this.className = this.clusterClassName;
13
+ this.styles = styles;
14
+ this.center = undefined;
15
+ this.div = null;
16
+ this.sums = null;
17
+ this.visible = false;
18
+ this.boundsChangedListener = null;
19
+ this.url = '';
20
+ this.height = 0;
21
+ this.width = 0;
22
+ this.anchorText = [0, 0];
23
+ this.anchorIcon = [0, 0];
24
+ this.textColor = 'black';
25
+ this.textSize = 11;
26
+ this.textDecoration = 'none';
27
+ this.fontWeight = 'bold';
28
+ this.fontStyle = 'normal';
29
+ this.fontFamily = 'Arial,sans-serif';
30
+ this.backgroundPosition = '0 0';
31
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
32
+ // @ts-ignore
33
+ this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
34
+ }
35
+ ClusterIcon.prototype.onAdd = function () {
36
+ var _this = this;
37
+ var cMouseDownInCluster;
38
+ var cDraggingMapByCluster;
39
+ this.div = document.createElement('div');
40
+ this.div.className = this.className;
41
+ if (this.visible) {
42
+ this.show();
43
+ }
44
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
45
+ // @ts-ignore
46
+ this.getPanes().overlayMouseTarget.appendChild(this.div);
47
+ // Fix for Issue 157
48
+ this.boundsChangedListener = google.maps.event.addListener(
49
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
50
+ // @ts-ignore
51
+ this.getMap(), 'boundschanged', function boundsChanged() {
52
+ cDraggingMapByCluster = cMouseDownInCluster;
53
+ });
54
+ google.maps.event.addDomListener(this.div, 'mousedown', function onMouseDown() {
55
+ cMouseDownInCluster = true;
56
+ cDraggingMapByCluster = false;
57
+ });
58
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
59
+ google.maps.event.addDomListener(this.div, 'click',
60
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
61
+ function (event) {
62
+ cMouseDownInCluster = false;
63
+ if (!cDraggingMapByCluster) {
64
+ var markerClusterer_1 = _this.cluster.getClusterer();
65
+ /**
66
+ * This event is fired when a cluster marker is clicked.
67
+ * @name MarkerClusterer#click
68
+ * @param {Cluster} c The cluster that was clicked.
69
+ * @event
70
+ */
71
+ google.maps.event.trigger(markerClusterer_1, 'click', _this.cluster);
72
+ google.maps.event.trigger(markerClusterer_1, 'clusterclick', _this.cluster); // deprecated name
73
+ // The default click handler follows. Disable it by setting
74
+ // the zoomOnClick property to false.
75
+ if (markerClusterer_1.getZoomOnClick()) {
76
+ // Zoom into the cluster.
77
+ var maxZoom_1 = markerClusterer_1.getMaxZoom();
78
+ var bounds_1 = _this.cluster.getBounds();
79
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
80
+ // @ts-ignore
81
+ markerClusterer_1.getMap().fitBounds(bounds_1);
82
+ // There is a fix for Issue 170 here:
83
+ setTimeout(function timeout() {
84
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
85
+ // @ts-ignore
86
+ markerClusterer_1.getMap().fitBounds(bounds_1);
87
+ // Don't zoom beyond the max zoom level
88
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
89
+ // @ts-ignore
90
+ if (maxZoom_1 !== null && markerClusterer_1.getMap().getZoom() > maxZoom_1) {
91
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
92
+ // @ts-ignore
93
+ markerClusterer_1.getMap().setZoom(maxZoom_1 + 1);
94
+ }
95
+ }, 100);
96
+ }
97
+ // Prevent event propagation to the map:
98
+ event.cancelBubble = true;
99
+ if (event.stopPropagation) {
100
+ event.stopPropagation();
101
+ }
102
+ }
103
+ });
104
+ google.maps.event.addDomListener(this.div, 'mouseover',
105
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
106
+ function () {
107
+ /**
108
+ * This event is fired when the mouse moves over a cluster marker.
109
+ * @name MarkerClusterer#mouseover
110
+ * @param {Cluster} c The cluster that the mouse moved over.
111
+ * @event
112
+ */
113
+ google.maps.event.trigger(_this.cluster.getClusterer(), 'mouseover', _this.cluster);
114
+ });
115
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
116
+ google.maps.event.addDomListener(this.div, 'mouseout',
117
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
118
+ function () {
119
+ /**
120
+ * This event is fired when the mouse moves out of a cluster marker.
121
+ * @name MarkerClusterer#mouseout
122
+ * @param {Cluster} c The cluster that the mouse moved out of.
123
+ * @event
124
+ */
125
+ google.maps.event.trigger(_this.cluster.getClusterer(), 'mouseout', _this.cluster);
126
+ });
127
+ };
128
+ ClusterIcon.prototype.onRemove = function () {
129
+ if (this.div && this.div.parentNode) {
130
+ this.hide();
131
+ if (this.boundsChangedListener !== null) {
132
+ google.maps.event.removeListener(this.boundsChangedListener);
133
+ }
134
+ google.maps.event.clearInstanceListeners(this.div);
135
+ this.div.parentNode.removeChild(this.div);
136
+ this.div = null;
137
+ }
138
+ };
139
+ ClusterIcon.prototype.draw = function () {
140
+ if (this.visible && this.div !== null && this.center) {
141
+ var _a = this.getPosFromLatLng(this.center), x = _a.x, y = _a.y;
142
+ this.div.style.top = y + 'px';
143
+ this.div.style.left = x + 'px';
144
+ }
145
+ };
146
+ ClusterIcon.prototype.hide = function () {
147
+ if (this.div) {
148
+ this.div.style.display = 'none';
149
+ }
150
+ this.visible = false;
151
+ };
152
+ ClusterIcon.prototype.show = function () {
153
+ if (this.div && this.center) {
154
+ var img = '', divTitle = '';
155
+ // NOTE: values must be specified in px units
156
+ var bp = this.backgroundPosition.split(' ');
157
+ var spriteH = parseInt(bp[0].replace(/^\s+|\s+$/g, ''), 10);
158
+ var spriteV = parseInt(bp[1].replace(/^\s+|\s+$/g, ''), 10);
159
+ var pos = this.getPosFromLatLng(this.center);
160
+ if (this.sums === null || typeof this.sums.title === 'undefined' || this.sums.title === '') {
161
+ divTitle = this.cluster.getClusterer().getTitle();
162
+ }
163
+ else {
164
+ divTitle = this.sums.title;
165
+ }
166
+ this.div.style.cssText = this.createCss(pos);
167
+ img =
168
+ "<img alt='" +
169
+ divTitle +
170
+ "' src='" +
171
+ this.url +
172
+ "' style='position: absolute; top: " +
173
+ spriteV +
174
+ 'px; left: ' +
175
+ spriteH +
176
+ 'px; ';
177
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
178
+ //@ts-ignore
179
+ if (!this.cluster.getClusterer().enableRetinaIcons) {
180
+ img +=
181
+ 'clip: rect(' +
182
+ -1 * spriteV +
183
+ 'px, ' +
184
+ (-1 * spriteH + this.width) +
185
+ 'px, ' +
186
+ (-1 * spriteV + this.height) +
187
+ 'px, ' +
188
+ -1 * spriteH +
189
+ 'px);';
190
+ }
191
+ img += "'>";
192
+ this.div.innerHTML =
193
+ img +
194
+ "<div style='" +
195
+ 'position: absolute;' +
196
+ 'top: ' +
197
+ this.anchorText[0] +
198
+ 'px;' +
199
+ 'left: ' +
200
+ this.anchorText[1] +
201
+ 'px;' +
202
+ 'color: ' +
203
+ this.textColor +
204
+ ';' +
205
+ 'font-size: ' +
206
+ this.textSize +
207
+ 'px;' +
208
+ 'font-family: ' +
209
+ this.fontFamily +
210
+ ';' +
211
+ 'font-weight: ' +
212
+ this.fontWeight +
213
+ ';' +
214
+ 'font-style: ' +
215
+ this.fontStyle +
216
+ ';' +
217
+ 'text-decoration: ' +
218
+ this.textDecoration +
219
+ ';' +
220
+ 'text-align: center;' +
221
+ 'width: ' +
222
+ this.width +
223
+ 'px;' +
224
+ 'line-height:' +
225
+ this.height +
226
+ 'px;' +
227
+ "'>" +
228
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
229
+ // @ts-ignore
230
+ this.sums.text +
231
+ '</div>';
232
+ this.div.title = divTitle;
233
+ this.div.style.display = '';
234
+ }
235
+ this.visible = true;
236
+ };
237
+ ClusterIcon.prototype.useStyle = function (sums) {
238
+ this.sums = sums;
239
+ var styles = this.cluster.getClusterer().getStyles();
240
+ var style = styles[Math.min(styles.length - 1, Math.max(0, sums.index - 1))];
241
+ this.url = style.url;
242
+ this.height = style.height;
243
+ this.width = style.width;
244
+ if (style.className)
245
+ this.className = this.clusterClassName + " " + style.className;
246
+ this.anchorText = style.anchorText || [0, 0];
247
+ this.anchorIcon = style.anchorIcon || [this.height / 2, this.width / 2];
248
+ this.textColor = style.textColor || 'black';
249
+ this.textSize = style.textSize || 11;
250
+ this.textDecoration = style.textDecoration || 'none';
251
+ this.fontWeight = style.fontWeight || 'bold';
252
+ this.fontStyle = style.fontStyle || 'normal';
253
+ this.fontFamily = style.fontFamily || 'Arial,sans-serif';
254
+ this.backgroundPosition = style.backgroundPosition || '0 0';
255
+ };
256
+ ClusterIcon.prototype.setCenter = function (center) {
257
+ this.center = center;
258
+ };
259
+ ClusterIcon.prototype.createCss = function (pos) {
260
+ var style = [];
261
+ style.push('cursor: pointer;');
262
+ style.push('position: absolute; top: ' + pos.y + 'px; left: ' + pos.x + 'px;');
263
+ style.push('width: ' + this.width + 'px; height: ' + this.height + 'px;');
264
+ return style.join('');
265
+ };
266
+ ClusterIcon.prototype.getPosFromLatLng = function (latlng) {
267
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
268
+ // @ts-ignore
269
+ var pos = this.getProjection().fromLatLngToDivPixel(latlng);
270
+ pos.x -= this.anchorIcon[1];
271
+ pos.y -= this.anchorIcon[0];
272
+ // pos.x = pos.x
273
+ // pos.y = pos.y
274
+ return pos;
275
+ };
276
+ return ClusterIcon;
277
+ }());
276
278
 
277
- var Cluster = /** @class */ (function () {
278
- function Cluster(markerClusterer) {
279
- this.markerClusterer = markerClusterer;
280
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
281
- // @ts-ignore
282
- this.map = this.markerClusterer.getMap();
283
- this.gridSize = this.markerClusterer.getGridSize();
284
- this.minClusterSize = this.markerClusterer.getMinimumClusterSize();
285
- this.averageCenter = this.markerClusterer.getAverageCenter();
286
- this.markers = [];
287
- this.center = undefined;
288
- this.bounds = null;
289
- this.clusterIcon = new ClusterIcon(this, this.markerClusterer.getStyles());
290
- }
291
- Cluster.prototype.getSize = function () {
292
- return this.markers.length;
293
- };
294
- Cluster.prototype.getMarkers = function () {
295
- return this.markers;
296
- };
297
- Cluster.prototype.getCenter = function () {
298
- return this.center;
299
- };
300
- Cluster.prototype.getMap = function () {
301
- return this.map;
302
- };
303
- Cluster.prototype.getClusterer = function () {
304
- return this.markerClusterer;
305
- };
306
- Cluster.prototype.getBounds = function () {
307
- var bounds = new google.maps.LatLngBounds(this.center, this.center);
308
- var markers = this.getMarkers();
309
- for (var i = 0; i < markers.length; i++) {
310
- var position = markers[i].getPosition();
311
- if (position) {
312
- bounds.extend(position);
313
- }
314
- }
315
- return bounds;
316
- };
317
- Cluster.prototype.remove = function () {
318
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
319
- // @ts-ignore
320
- this.clusterIcon.setMap(null);
321
- this.markers = [];
322
- // @ts-ignore
323
- delete this.markers;
324
- };
325
- Cluster.prototype.addMarker = function (marker) {
326
- if (this.isMarkerAlreadyAdded(marker)) {
327
- return false;
328
- }
329
- if (!this.center) {
330
- var position = marker.getPosition();
331
- if (position) {
332
- this.center = position;
333
- this.calculateBounds();
334
- }
335
- }
336
- else {
337
- if (this.averageCenter) {
338
- var position = marker.getPosition();
339
- if (position) {
340
- var length_1 = this.markers.length + 1;
341
- this.center = new google.maps.LatLng((this.center.lat() * (length_1 - 1) + position.lat()) / length_1, (this.center.lng() * (length_1 - 1) + position.lng()) / length_1);
342
- this.calculateBounds();
343
- }
344
- }
345
- }
346
- marker.isAdded = true;
347
- this.markers.push(marker);
348
- var mCount = this.markers.length;
349
- var maxZoom = this.markerClusterer.getMaxZoom();
350
- if (maxZoom !== null && this.map.getZoom() > maxZoom) {
351
- // Zoomed in past max zoom, so show the marker.
352
- if (marker.getMap() !== this.map) {
353
- marker.setMap(this.map);
354
- }
355
- }
356
- else if (mCount < this.minClusterSize) {
357
- // Min cluster size not reached so show the marker.
358
- if (marker.getMap() !== this.map) {
359
- marker.setMap(this.map);
360
- }
361
- }
362
- else if (mCount === this.minClusterSize) {
363
- // Hide the markers that were showing.
364
- for (var i = 0; i < mCount; i++) {
365
- this.markers[i].setMap(null);
366
- }
367
- }
368
- else {
369
- marker.setMap(null);
370
- }
371
- return true;
372
- };
373
- Cluster.prototype.isMarkerInClusterBounds = function (marker) {
374
- if (this.bounds !== null) {
375
- var position = marker.getPosition();
376
- if (position) {
377
- return this.bounds.contains(position);
378
- }
379
- }
380
- return false;
381
- };
382
- Cluster.prototype.calculateBounds = function () {
383
- this.bounds = this.markerClusterer.getExtendedBounds(new google.maps.LatLngBounds(this.center, this.center));
384
- };
385
- Cluster.prototype.updateIcon = function () {
386
- var mCount = this.markers.length;
387
- var maxZoom = this.markerClusterer.getMaxZoom();
388
- if (maxZoom !== null && this.map.getZoom() > maxZoom) {
389
- this.clusterIcon.hide();
390
- return;
391
- }
392
- if (mCount < this.minClusterSize) {
393
- // Min cluster size not yet reached.
394
- this.clusterIcon.hide();
395
- return;
396
- }
397
- if (this.center) {
398
- this.clusterIcon.setCenter(this.center);
399
- }
400
- this.clusterIcon.useStyle(this.markerClusterer.getCalculator()(this.markers, this.markerClusterer.getStyles().length));
401
- this.clusterIcon.show();
402
- };
403
- Cluster.prototype.isMarkerAlreadyAdded = function (marker) {
404
- if (this.markers.includes) {
405
- return this.markers.includes(marker);
406
- }
407
- else {
408
- for (var i = 0; i < this.markers.length; i++) {
409
- if (marker === this.markers[i]) {
410
- return true;
411
- }
412
- }
413
- }
414
- return false;
415
- };
416
- return Cluster;
417
- }());
279
+ var Cluster = /** @class */ (function () {
280
+ function Cluster(markerClusterer) {
281
+ this.markerClusterer = markerClusterer;
282
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
283
+ // @ts-ignore
284
+ this.map = this.markerClusterer.getMap();
285
+ this.gridSize = this.markerClusterer.getGridSize();
286
+ this.minClusterSize = this.markerClusterer.getMinimumClusterSize();
287
+ this.averageCenter = this.markerClusterer.getAverageCenter();
288
+ this.markers = [];
289
+ this.center = undefined;
290
+ this.bounds = null;
291
+ this.clusterIcon = new ClusterIcon(this, this.markerClusterer.getStyles());
292
+ }
293
+ Cluster.prototype.getSize = function () {
294
+ return this.markers.length;
295
+ };
296
+ Cluster.prototype.getMarkers = function () {
297
+ return this.markers;
298
+ };
299
+ Cluster.prototype.getCenter = function () {
300
+ return this.center;
301
+ };
302
+ Cluster.prototype.getMap = function () {
303
+ return this.map;
304
+ };
305
+ Cluster.prototype.getClusterer = function () {
306
+ return this.markerClusterer;
307
+ };
308
+ Cluster.prototype.getBounds = function () {
309
+ var bounds = new google.maps.LatLngBounds(this.center, this.center);
310
+ var markers = this.getMarkers();
311
+ for (var i = 0; i < markers.length; i++) {
312
+ var position = markers[i].getPosition();
313
+ if (position) {
314
+ bounds.extend(position);
315
+ }
316
+ }
317
+ return bounds;
318
+ };
319
+ Cluster.prototype.remove = function () {
320
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
321
+ // @ts-ignore
322
+ this.clusterIcon.setMap(null);
323
+ this.markers = [];
324
+ // @ts-ignore
325
+ delete this.markers;
326
+ };
327
+ Cluster.prototype.addMarker = function (marker) {
328
+ if (this.isMarkerAlreadyAdded(marker)) {
329
+ return false;
330
+ }
331
+ if (!this.center) {
332
+ var position = marker.getPosition();
333
+ if (position) {
334
+ this.center = position;
335
+ this.calculateBounds();
336
+ }
337
+ }
338
+ else {
339
+ if (this.averageCenter) {
340
+ var position = marker.getPosition();
341
+ if (position) {
342
+ var length_1 = this.markers.length + 1;
343
+ this.center = new google.maps.LatLng((this.center.lat() * (length_1 - 1) + position.lat()) / length_1, (this.center.lng() * (length_1 - 1) + position.lng()) / length_1);
344
+ this.calculateBounds();
345
+ }
346
+ }
347
+ }
348
+ marker.isAdded = true;
349
+ this.markers.push(marker);
350
+ var mCount = this.markers.length;
351
+ var maxZoom = this.markerClusterer.getMaxZoom();
352
+ var zoom = this.map.getZoom();
353
+ if (maxZoom !== null && typeof zoom !== 'undefined' && zoom > maxZoom) {
354
+ // Zoomed in past max zoom, so show the marker.
355
+ if (marker.getMap() !== this.map) {
356
+ marker.setMap(this.map);
357
+ }
358
+ }
359
+ else if (mCount < this.minClusterSize) {
360
+ // Min cluster size not reached so show the marker.
361
+ if (marker.getMap() !== this.map) {
362
+ marker.setMap(this.map);
363
+ }
364
+ }
365
+ else if (mCount === this.minClusterSize) {
366
+ // Hide the markers that were showing.
367
+ for (var i = 0; i < mCount; i++) {
368
+ this.markers[i].setMap(null);
369
+ }
370
+ }
371
+ else {
372
+ marker.setMap(null);
373
+ }
374
+ return true;
375
+ };
376
+ Cluster.prototype.isMarkerInClusterBounds = function (marker) {
377
+ if (this.bounds !== null) {
378
+ var position = marker.getPosition();
379
+ if (position) {
380
+ return this.bounds.contains(position);
381
+ }
382
+ }
383
+ return false;
384
+ };
385
+ Cluster.prototype.calculateBounds = function () {
386
+ this.bounds = this.markerClusterer.getExtendedBounds(new google.maps.LatLngBounds(this.center, this.center));
387
+ };
388
+ Cluster.prototype.updateIcon = function () {
389
+ var mCount = this.markers.length;
390
+ var maxZoom = this.markerClusterer.getMaxZoom();
391
+ var zoom = this.map.getZoom();
392
+ if (maxZoom !== null && typeof zoom !== 'undefined' && zoom > maxZoom) {
393
+ this.clusterIcon.hide();
394
+ return;
395
+ }
396
+ if (mCount < this.minClusterSize) {
397
+ // Min cluster size not yet reached.
398
+ this.clusterIcon.hide();
399
+ return;
400
+ }
401
+ if (this.center) {
402
+ this.clusterIcon.setCenter(this.center);
403
+ }
404
+ this.clusterIcon.useStyle(this.markerClusterer.getCalculator()(this.markers, this.markerClusterer.getStyles().length));
405
+ this.clusterIcon.show();
406
+ };
407
+ Cluster.prototype.isMarkerAlreadyAdded = function (marker) {
408
+ if (this.markers.includes) {
409
+ return this.markers.includes(marker);
410
+ }
411
+ else {
412
+ for (var i = 0; i < this.markers.length; i++) {
413
+ if (marker === this.markers[i]) {
414
+ return true;
415
+ }
416
+ }
417
+ }
418
+ return false;
419
+ };
420
+ return Cluster;
421
+ }());
418
422
 
419
- /* global google */
420
- /**
421
- * Supports up to 9007199254740991 (Number.MAX_SAFE_INTEGER) markers
422
- * which is not a problem as max array length is 4294967296 (2**32)
423
- */
424
- var CALCULATOR = function CALCULATOR(markers, numStyles) {
425
- var count = markers.length;
426
- var numberOfDigits = count.toString().length;
427
- var index = Math.min(numberOfDigits, numStyles);
428
- return {
429
- text: count.toString(),
430
- index: index,
431
- title: '',
432
- };
433
- };
434
- var BATCH_SIZE = 2000;
435
- var BATCH_SIZE_IE = 500;
436
- var IMAGE_PATH = 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m';
437
- var IMAGE_EXTENSION = 'png';
438
- var IMAGE_SIZES = [53, 56, 66, 78, 90];
439
- var CLUSTERER_CLASS = 'cluster';
440
- var Clusterer = /** @class */ (function () {
441
- function Clusterer(map, optMarkers, optOptions) {
442
- if (optMarkers === void 0) { optMarkers = []; }
443
- if (optOptions === void 0) { optOptions = {}; }
444
- this.extend(Clusterer, google.maps.OverlayView);
445
- this.markers = [];
446
- this.clusters = [];
447
- this.listeners = [];
448
- this.activeMap = null;
449
- this.ready = false;
450
- this.gridSize = optOptions.gridSize || 60;
451
- this.minClusterSize = optOptions.minimumClusterSize || 2;
452
- this.maxZoom = optOptions.maxZoom || null;
453
- this.styles = optOptions.styles || [];
454
- this.title = optOptions.title || '';
455
- this.zoomOnClick = true;
456
- if (optOptions.zoomOnClick !== undefined) {
457
- this.zoomOnClick = optOptions.zoomOnClick;
458
- }
459
- this.averageCenter = false;
460
- if (optOptions.averageCenter !== undefined) {
461
- this.averageCenter = optOptions.averageCenter;
462
- }
463
- this.ignoreHidden = false;
464
- if (optOptions.ignoreHidden !== undefined) {
465
- this.ignoreHidden = optOptions.ignoreHidden;
466
- }
467
- this.enableRetinaIcons = false;
468
- if (optOptions.enableRetinaIcons !== undefined) {
469
- this.enableRetinaIcons = optOptions.enableRetinaIcons;
470
- }
471
- this.imagePath = optOptions.imagePath || IMAGE_PATH;
472
- this.imageExtension = optOptions.imageExtension || IMAGE_EXTENSION;
473
- this.imageSizes = optOptions.imageSizes || IMAGE_SIZES;
474
- this.calculator = optOptions.calculator || CALCULATOR;
475
- this.batchSize = optOptions.batchSize || BATCH_SIZE;
476
- this.batchSizeIE = optOptions.batchSizeIE || BATCH_SIZE_IE;
477
- this.clusterClass = optOptions.clusterClass || CLUSTERER_CLASS;
478
- if (navigator.userAgent.toLowerCase().indexOf('msie') !== -1) {
479
- // Try to avoid IE timeout when processing a huge number of markers:
480
- this.batchSize = this.batchSizeIE;
481
- }
482
- this.timerRefStatic = null;
483
- this.setupStyles();
484
- this.addMarkers(optMarkers, true);
485
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
486
- // @ts-ignore
487
- this.setMap(map); // Note: this causes onAdd to be called
488
- }
489
- Clusterer.prototype.onAdd = function () {
490
- var _this = this;
491
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
492
- // @ts-ignore
493
- this.activeMap = this.getMap();
494
- this.ready = true;
495
- this.repaint();
496
- // Add the map event listeners
497
- this.listeners = [
498
- google.maps.event.addListener(
499
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
500
- // @ts-ignore
501
- this.getMap(), 'zoom_changed',
502
- // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
503
- function () {
504
- _this.resetViewport(false);
505
- // Workaround for this Google bug: when map is at level 0 and "-" of
506
- // zoom slider is clicked, a "zoom_changed" event is fired even though
507
- // the map doesn't zoom out any further. In this situation, no "idle"
508
- // event is triggered so the cluster markers that have been removed
509
- // do not get redrawn. Same goes for a zoom in at maxZoom.
510
- if (
511
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
512
- // @ts-ignore
513
- _this.getMap().getZoom() === (_this.get('minZoom') || 0) ||
514
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
515
- // @ts-ignore
516
- _this.getMap().getZoom() === _this.get('maxZoom')) {
517
- google.maps.event.trigger(_this, 'idle');
518
- }
519
- }),
520
- google.maps.event.addListener(
521
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
522
- // @ts-ignore
523
- this.getMap(), 'idle',
524
- // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
525
- function () {
526
- _this.redraw();
527
- }),
528
- ];
529
- };
530
- // eslint-disable-next-line @getify/proper-arrows/this
531
- Clusterer.prototype.onRemove = function () {
532
- // Put all the managed markers back on the map:
533
- for (var i = 0; i < this.markers.length; i++) {
534
- if (this.markers[i].getMap() !== this.activeMap) {
535
- this.markers[i].setMap(this.activeMap);
536
- }
537
- }
538
- // Remove all clusters:
539
- for (var i = 0; i < this.clusters.length; i++) {
540
- this.clusters[i].remove();
541
- }
542
- this.clusters = [];
543
- // Remove map event listeners:
544
- for (var i = 0; i < this.listeners.length; i++) {
545
- google.maps.event.removeListener(this.listeners[i]);
546
- }
547
- this.listeners = [];
548
- this.activeMap = null;
549
- this.ready = false;
550
- };
551
- // eslint-disable-next-line @typescript-eslint/no-empty-function
552
- Clusterer.prototype.draw = function () { };
553
- Clusterer.prototype.setupStyles = function () {
554
- if (this.styles.length > 0) {
555
- return;
556
- }
557
- for (var i = 0; i < this.imageSizes.length; i++) {
558
- this.styles.push({
559
- url: this.imagePath + (i + 1) + '.' + this.imageExtension,
560
- height: this.imageSizes[i],
561
- width: this.imageSizes[i],
562
- });
563
- }
564
- };
565
- Clusterer.prototype.fitMapToMarkers = function () {
566
- var markers = this.getMarkers();
567
- var bounds = new google.maps.LatLngBounds();
568
- for (var i = 0; i < markers.length; i++) {
569
- var position = markers[i].getPosition();
570
- if (position) {
571
- bounds.extend(position);
572
- }
573
- }
574
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
575
- // @ts-ignore
576
- this.getMap().fitBounds(bounds);
577
- };
578
- Clusterer.prototype.getGridSize = function () {
579
- return this.gridSize;
580
- };
581
- Clusterer.prototype.setGridSize = function (gridSize) {
582
- this.gridSize = gridSize;
583
- };
584
- Clusterer.prototype.getMinimumClusterSize = function () {
585
- return this.minClusterSize;
586
- };
587
- Clusterer.prototype.setMinimumClusterSize = function (minimumClusterSize) {
588
- this.minClusterSize = minimumClusterSize;
589
- };
590
- Clusterer.prototype.getMaxZoom = function () {
591
- return this.maxZoom;
592
- };
593
- Clusterer.prototype.setMaxZoom = function (maxZoom) {
594
- this.maxZoom = maxZoom;
595
- };
596
- Clusterer.prototype.getStyles = function () {
597
- return this.styles;
598
- };
599
- Clusterer.prototype.setStyles = function (styles) {
600
- this.styles = styles;
601
- };
602
- Clusterer.prototype.getTitle = function () {
603
- return this.title;
604
- };
605
- Clusterer.prototype.setTitle = function (title) {
606
- this.title = title;
607
- };
608
- Clusterer.prototype.getZoomOnClick = function () {
609
- return this.zoomOnClick;
610
- };
611
- Clusterer.prototype.setZoomOnClick = function (zoomOnClick) {
612
- this.zoomOnClick = zoomOnClick;
613
- };
614
- Clusterer.prototype.getAverageCenter = function () {
615
- return this.averageCenter;
616
- };
617
- Clusterer.prototype.setAverageCenter = function (averageCenter) {
618
- this.averageCenter = averageCenter;
619
- };
620
- Clusterer.prototype.getIgnoreHidden = function () {
621
- return this.ignoreHidden;
622
- };
623
- Clusterer.prototype.setIgnoreHidden = function (ignoreHidden) {
624
- this.ignoreHidden = ignoreHidden;
625
- };
626
- Clusterer.prototype.getEnableRetinaIcons = function () {
627
- return this.enableRetinaIcons;
628
- };
629
- Clusterer.prototype.setEnableRetinaIcons = function (enableRetinaIcons) {
630
- this.enableRetinaIcons = enableRetinaIcons;
631
- };
632
- Clusterer.prototype.getImageExtension = function () {
633
- return this.imageExtension;
634
- };
635
- Clusterer.prototype.setImageExtension = function (imageExtension) {
636
- this.imageExtension = imageExtension;
637
- };
638
- Clusterer.prototype.getImagePath = function () {
639
- return this.imagePath;
640
- };
641
- Clusterer.prototype.setImagePath = function (imagePath) {
642
- this.imagePath = imagePath;
643
- };
644
- Clusterer.prototype.getImageSizes = function () {
645
- return this.imageSizes;
646
- };
647
- Clusterer.prototype.setImageSizes = function (imageSizes) {
648
- this.imageSizes = imageSizes;
649
- };
650
- Clusterer.prototype.getCalculator = function () {
651
- return this.calculator;
652
- };
653
- Clusterer.prototype.setCalculator = function (calculator) {
654
- this.calculator = calculator;
655
- };
656
- Clusterer.prototype.getBatchSizeIE = function () {
657
- return this.batchSizeIE;
658
- };
659
- Clusterer.prototype.setBatchSizeIE = function (batchSizeIE) {
660
- this.batchSizeIE = batchSizeIE;
661
- };
662
- Clusterer.prototype.getClusterClass = function () {
663
- return this.clusterClass;
664
- };
665
- Clusterer.prototype.setClusterClass = function (clusterClass) {
666
- this.clusterClass = clusterClass;
667
- };
668
- Clusterer.prototype.getMarkers = function () {
669
- return this.markers;
670
- };
671
- Clusterer.prototype.getTotalMarkers = function () {
672
- return this.markers.length;
673
- };
674
- Clusterer.prototype.getClusters = function () {
675
- return this.clusters;
676
- };
677
- Clusterer.prototype.getTotalClusters = function () {
678
- return this.clusters.length;
679
- };
680
- Clusterer.prototype.addMarker = function (marker, optNoDraw) {
681
- this.pushMarkerTo(marker);
682
- if (!optNoDraw) {
683
- this.redraw();
684
- }
685
- };
686
- Clusterer.prototype.addMarkers = function (markers, optNoDraw) {
687
- for (var key in markers) {
688
- if (markers.hasOwnProperty(key)) {
689
- this.pushMarkerTo(markers[key]);
690
- }
691
- }
692
- if (!optNoDraw) {
693
- this.redraw();
694
- }
695
- };
696
- Clusterer.prototype.pushMarkerTo = function (marker) {
697
- var _this = this;
698
- // If the marker is draggable add a listener so we can update the clusters on the dragend:
699
- if (marker.getDraggable()) {
700
- // eslint-disable-next-line @getify/proper-arrows/name, @getify/proper-arrows/this
701
- google.maps.event.addListener(marker, 'dragend', function () {
702
- if (_this.ready) {
703
- marker.isAdded = false;
704
- _this.repaint();
705
- }
706
- });
707
- }
708
- marker.isAdded = false;
709
- this.markers.push(marker);
710
- };
711
- Clusterer.prototype.removeMarker_ = function (marker) {
712
- var index = -1;
713
- if (this.markers.indexOf) {
714
- index = this.markers.indexOf(marker);
715
- }
716
- else {
717
- for (var i = 0; i < this.markers.length; i++) {
718
- if (marker === this.markers[i]) {
719
- index = i;
720
- break;
721
- }
722
- }
723
- }
724
- if (index === -1) {
725
- // Marker is not in our list of markers, so do nothing:
726
- return false;
727
- }
728
- marker.setMap(null);
729
- this.markers.splice(index, 1); // Remove the marker from the list of managed markers
730
- return true;
731
- };
732
- Clusterer.prototype.removeMarker = function (marker, optNoDraw) {
733
- var removed = this.removeMarker_(marker);
734
- if (!optNoDraw && removed) {
735
- this.repaint();
736
- }
737
- return removed;
738
- };
739
- Clusterer.prototype.removeMarkers = function (markers, optNoDraw) {
740
- var removed = false;
741
- for (var i = 0; i < markers.length; i++) {
742
- removed = removed || this.removeMarker_(markers[i]);
743
- }
744
- if (!optNoDraw && removed) {
745
- this.repaint();
746
- }
747
- return removed;
748
- };
749
- Clusterer.prototype.clearMarkers = function () {
750
- this.resetViewport(true);
751
- this.markers = [];
752
- };
753
- Clusterer.prototype.repaint = function () {
754
- var oldClusters = this.clusters.slice();
755
- this.clusters = [];
756
- this.resetViewport(false);
757
- this.redraw();
758
- // Remove the old clusters.
759
- // Do it in a timeout to prevent blinking effect.
760
- setTimeout(function timeout() {
761
- for (var i = 0; i < oldClusters.length; i++) {
762
- oldClusters[i].remove();
763
- }
764
- }, 0);
765
- };
766
- Clusterer.prototype.getExtendedBounds = function (bounds) {
767
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
768
- // @ts-ignore
769
- var projection = this.getProjection();
770
- // Convert the points to pixels and the extend out by the grid size.
771
- var trPix = projection.fromLatLngToDivPixel(
772
- // Turn the bounds into latlng.
773
- new google.maps.LatLng(bounds.getNorthEast().lat(), bounds.getNorthEast().lng()));
774
- trPix.x += this.gridSize;
775
- trPix.y -= this.gridSize;
776
- var blPix = projection.fromLatLngToDivPixel(
777
- // Turn the bounds into latlng.
778
- new google.maps.LatLng(bounds.getSouthWest().lat(), bounds.getSouthWest().lng()));
779
- blPix.x -= this.gridSize;
780
- blPix.y += this.gridSize;
781
- // Extend the bounds to contain the new bounds.
782
- bounds.extend(
783
- // Convert the pixel points back to LatLng nw
784
- projection.fromDivPixelToLatLng(trPix));
785
- bounds.extend(
786
- // Convert the pixel points back to LatLng sw
787
- projection.fromDivPixelToLatLng(blPix));
788
- return bounds;
789
- };
790
- Clusterer.prototype.redraw = function () {
791
- // Redraws all the clusters.
792
- this.createClusters(0);
793
- };
794
- Clusterer.prototype.resetViewport = function (optHide) {
795
- // Remove all the clusters
796
- for (var i = 0; i < this.clusters.length; i++) {
797
- this.clusters[i].remove();
798
- }
799
- this.clusters = [];
800
- // Reset the markers to not be added and to be removed from the map.
801
- for (var i = 0; i < this.markers.length; i++) {
802
- var marker = this.markers[i];
803
- marker.isAdded = false;
804
- if (optHide) {
805
- marker.setMap(null);
806
- }
807
- }
808
- };
809
- Clusterer.prototype.distanceBetweenPoints = function (p1, p2) {
810
- var R = 6371; // Radius of the Earth in km
811
- var dLat = ((p2.lat() - p1.lat()) * Math.PI) / 180;
812
- var dLon = ((p2.lng() - p1.lng()) * Math.PI) / 180;
813
- var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
814
- Math.cos((p1.lat() * Math.PI) / 180) *
815
- Math.cos((p2.lat() * Math.PI) / 180) *
816
- Math.sin(dLon / 2) *
817
- Math.sin(dLon / 2);
818
- return R * (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
819
- };
820
- Clusterer.prototype.isMarkerInBounds = function (marker, bounds) {
821
- var position = marker.getPosition();
822
- if (position) {
823
- return bounds.contains(position);
824
- }
825
- return false;
826
- };
827
- Clusterer.prototype.addToClosestCluster = function (marker) {
828
- var cluster;
829
- var distance = 40000; // Some large number
830
- var clusterToAddTo = null;
831
- for (var i = 0; i < this.clusters.length; i++) {
832
- cluster = this.clusters[i];
833
- var center = cluster.getCenter();
834
- var position = marker.getPosition();
835
- if (center && position) {
836
- var d = this.distanceBetweenPoints(center, position);
837
- if (d < distance) {
838
- distance = d;
839
- clusterToAddTo = cluster;
840
- }
841
- }
842
- }
843
- if (clusterToAddTo && clusterToAddTo.isMarkerInClusterBounds(marker)) {
844
- clusterToAddTo.addMarker(marker);
845
- }
846
- else {
847
- cluster = new Cluster(this);
848
- cluster.addMarker(marker);
849
- this.clusters.push(cluster);
850
- }
851
- };
852
- Clusterer.prototype.createClusters = function (iFirst) {
853
- var _this = this;
854
- if (!this.ready) {
855
- return;
856
- }
857
- // Cancel previous batch processing if we're working on the first batch:
858
- if (iFirst === 0) {
859
- /**
860
- * This event is fired when the <code>Clusterer</code> begins
861
- * clustering markers.
862
- * @name Clusterer#clusteringbegin
863
- * @param {Clusterer} mc The Clusterer whose markers are being clustered.
864
- * @event
865
- */
866
- google.maps.event.trigger(this, 'clusteringbegin', this);
867
- if (this.timerRefStatic !== null) {
868
- window.clearTimeout(this.timerRefStatic);
869
- // @ts-ignore
870
- delete this.timerRefStatic;
871
- }
872
- }
873
- // Get our current map view bounds.
874
- // Create a new bounds object so we don't affect the map.
875
- //
876
- // See Comments 9 & 11 on Issue 3651 relating to this workaround for a Google Maps bug:
877
- var mapBounds =
878
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
879
- // @ts-ignore
880
- this.getMap().getZoom() > 3
881
- ? new google.maps.LatLngBounds(
882
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
883
- // @ts-ignore
884
- this.getMap()
885
- .getBounds()
886
- .getSouthWest(),
887
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
888
- // @ts-ignore
889
- this.getMap()
890
- .getBounds()
891
- .getNorthEast())
892
- : new google.maps.LatLngBounds(new google.maps.LatLng(85.02070771743472, -178.48388434375), new google.maps.LatLng(-85.08136444384544, 178.00048865625));
893
- var bounds = this.getExtendedBounds(mapBounds);
894
- var iLast = Math.min(iFirst + this.batchSize, this.markers.length);
895
- for (var i = iFirst; i < iLast; i++) {
896
- var marker = this.markers[i];
897
- if (!marker.isAdded && this.isMarkerInBounds(marker, bounds)) {
898
- if (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible())) {
899
- this.addToClosestCluster(marker);
900
- }
901
- }
902
- }
903
- 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 () {
907
- _this.createClusters(iLast);
908
- }, 0);
909
- }
910
- else {
911
- this.timerRefStatic = null;
912
- /**
913
- * This event is fired when the <code>Clusterer</code> stops
914
- * clustering markers.
915
- * @name Clusterer#clusteringend
916
- * @param {Clusterer} mc The Clusterer whose markers are being clustered.
917
- * @event
918
- */
919
- google.maps.event.trigger(this, 'clusteringend', this);
920
- for (var i = 0; i < this.clusters.length; i++) {
921
- this.clusters[i].updateIcon();
922
- }
923
- }
924
- };
925
- Clusterer.prototype.extend = function (obj1, obj2) {
926
- return function applyExtend(object) {
927
- // eslint-disable-next-line guard-for-in
928
- for (var property in object.prototype) {
929
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
930
- // @ts-ignore
931
- this.prototype[property] = object.prototype[property];
932
- }
933
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
934
- // @ts-ignore
935
- return this;
936
- }.apply(obj1, [obj2]);
937
- };
938
- return Clusterer;
939
- }());
423
+ /* global google */
424
+ /**
425
+ * Supports up to 9007199254740991 (Number.MAX_SAFE_INTEGER) markers
426
+ * which is not a problem as max array length is 4294967296 (2**32)
427
+ */
428
+ var CALCULATOR = function CALCULATOR(markers, numStyles) {
429
+ var count = markers.length;
430
+ var numberOfDigits = count.toString().length;
431
+ var index = Math.min(numberOfDigits, numStyles);
432
+ return {
433
+ text: count.toString(),
434
+ index: index,
435
+ title: '',
436
+ };
437
+ };
438
+ var BATCH_SIZE = 2000;
439
+ var BATCH_SIZE_IE = 500;
440
+ var IMAGE_PATH = 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m';
441
+ var IMAGE_EXTENSION = 'png';
442
+ var IMAGE_SIZES = [53, 56, 66, 78, 90];
443
+ var CLUSTERER_CLASS = 'cluster';
444
+ var Clusterer = /** @class */ (function () {
445
+ function Clusterer(map, optMarkers, optOptions) {
446
+ if (optMarkers === void 0) { optMarkers = []; }
447
+ if (optOptions === void 0) { optOptions = {}; }
448
+ this.extend(Clusterer, google.maps.OverlayView);
449
+ this.markers = [];
450
+ this.clusters = [];
451
+ this.listeners = [];
452
+ this.activeMap = null;
453
+ this.ready = false;
454
+ this.gridSize = optOptions.gridSize || 60;
455
+ this.minClusterSize = optOptions.minimumClusterSize || 2;
456
+ this.maxZoom = optOptions.maxZoom || null;
457
+ this.styles = optOptions.styles || [];
458
+ this.title = optOptions.title || '';
459
+ this.zoomOnClick = true;
460
+ if (optOptions.zoomOnClick !== undefined) {
461
+ this.zoomOnClick = optOptions.zoomOnClick;
462
+ }
463
+ this.averageCenter = false;
464
+ if (optOptions.averageCenter !== undefined) {
465
+ this.averageCenter = optOptions.averageCenter;
466
+ }
467
+ this.ignoreHidden = false;
468
+ if (optOptions.ignoreHidden !== undefined) {
469
+ this.ignoreHidden = optOptions.ignoreHidden;
470
+ }
471
+ this.enableRetinaIcons = false;
472
+ if (optOptions.enableRetinaIcons !== undefined) {
473
+ this.enableRetinaIcons = optOptions.enableRetinaIcons;
474
+ }
475
+ this.imagePath = optOptions.imagePath || IMAGE_PATH;
476
+ this.imageExtension = optOptions.imageExtension || IMAGE_EXTENSION;
477
+ this.imageSizes = optOptions.imageSizes || IMAGE_SIZES;
478
+ this.calculator = optOptions.calculator || CALCULATOR;
479
+ this.batchSize = optOptions.batchSize || BATCH_SIZE;
480
+ this.batchSizeIE = optOptions.batchSizeIE || BATCH_SIZE_IE;
481
+ this.clusterClass = optOptions.clusterClass || CLUSTERER_CLASS;
482
+ if (navigator.userAgent.toLowerCase().indexOf('msie') !== -1) {
483
+ // Try to avoid IE timeout when processing a huge number of markers:
484
+ this.batchSize = this.batchSizeIE;
485
+ }
486
+ this.timerRefStatic = null;
487
+ this.setupStyles();
488
+ this.addMarkers(optMarkers, true);
489
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
490
+ // @ts-ignore
491
+ this.setMap(map); // Note: this causes onAdd to be called
492
+ }
493
+ Clusterer.prototype.onAdd = function () {
494
+ var _this = this;
495
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
496
+ // @ts-ignore
497
+ this.activeMap = this.getMap();
498
+ this.ready = true;
499
+ this.repaint();
500
+ // Add the map event listeners
501
+ this.listeners = [
502
+ google.maps.event.addListener(
503
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
504
+ // @ts-ignore
505
+ this.getMap(), 'zoom_changed',
506
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
507
+ function () {
508
+ _this.resetViewport(false);
509
+ // Workaround for this Google bug: when map is at level 0 and "-" of
510
+ // zoom slider is clicked, a "zoom_changed" event is fired even though
511
+ // the map doesn't zoom out any further. In this situation, no "idle"
512
+ // event is triggered so the cluster markers that have been removed
513
+ // do not get redrawn. Same goes for a zoom in at maxZoom.
514
+ if (
515
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
516
+ // @ts-ignore
517
+ _this.getMap().getZoom() === (_this.get('minZoom') || 0) ||
518
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
519
+ // @ts-ignore
520
+ _this.getMap().getZoom() === _this.get('maxZoom')) {
521
+ google.maps.event.trigger(_this, 'idle');
522
+ }
523
+ }),
524
+ google.maps.event.addListener(
525
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
526
+ // @ts-ignore
527
+ this.getMap(), 'idle',
528
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
529
+ function () {
530
+ _this.redraw();
531
+ }),
532
+ ];
533
+ };
534
+ // eslint-disable-next-line @getify/proper-arrows/this
535
+ Clusterer.prototype.onRemove = function () {
536
+ // Put all the managed markers back on the map:
537
+ for (var i = 0; i < this.markers.length; i++) {
538
+ if (this.markers[i].getMap() !== this.activeMap) {
539
+ this.markers[i].setMap(this.activeMap);
540
+ }
541
+ }
542
+ // Remove all clusters:
543
+ for (var i = 0; i < this.clusters.length; i++) {
544
+ this.clusters[i].remove();
545
+ }
546
+ this.clusters = [];
547
+ // Remove map event listeners:
548
+ for (var i = 0; i < this.listeners.length; i++) {
549
+ google.maps.event.removeListener(this.listeners[i]);
550
+ }
551
+ this.listeners = [];
552
+ this.activeMap = null;
553
+ this.ready = false;
554
+ };
555
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
556
+ Clusterer.prototype.draw = function () { };
557
+ Clusterer.prototype.setupStyles = function () {
558
+ if (this.styles.length > 0) {
559
+ return;
560
+ }
561
+ for (var i = 0; i < this.imageSizes.length; i++) {
562
+ this.styles.push({
563
+ url: this.imagePath + (i + 1) + '.' + this.imageExtension,
564
+ height: this.imageSizes[i],
565
+ width: this.imageSizes[i],
566
+ });
567
+ }
568
+ };
569
+ Clusterer.prototype.fitMapToMarkers = function () {
570
+ var markers = this.getMarkers();
571
+ var bounds = new google.maps.LatLngBounds();
572
+ for (var i = 0; i < markers.length; i++) {
573
+ var position = markers[i].getPosition();
574
+ if (position) {
575
+ bounds.extend(position);
576
+ }
577
+ }
578
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
579
+ // @ts-ignore
580
+ this.getMap().fitBounds(bounds);
581
+ };
582
+ Clusterer.prototype.getGridSize = function () {
583
+ return this.gridSize;
584
+ };
585
+ Clusterer.prototype.setGridSize = function (gridSize) {
586
+ this.gridSize = gridSize;
587
+ };
588
+ Clusterer.prototype.getMinimumClusterSize = function () {
589
+ return this.minClusterSize;
590
+ };
591
+ Clusterer.prototype.setMinimumClusterSize = function (minimumClusterSize) {
592
+ this.minClusterSize = minimumClusterSize;
593
+ };
594
+ Clusterer.prototype.getMaxZoom = function () {
595
+ return this.maxZoom;
596
+ };
597
+ Clusterer.prototype.setMaxZoom = function (maxZoom) {
598
+ this.maxZoom = maxZoom;
599
+ };
600
+ Clusterer.prototype.getStyles = function () {
601
+ return this.styles;
602
+ };
603
+ Clusterer.prototype.setStyles = function (styles) {
604
+ this.styles = styles;
605
+ };
606
+ Clusterer.prototype.getTitle = function () {
607
+ return this.title;
608
+ };
609
+ Clusterer.prototype.setTitle = function (title) {
610
+ this.title = title;
611
+ };
612
+ Clusterer.prototype.getZoomOnClick = function () {
613
+ return this.zoomOnClick;
614
+ };
615
+ Clusterer.prototype.setZoomOnClick = function (zoomOnClick) {
616
+ this.zoomOnClick = zoomOnClick;
617
+ };
618
+ Clusterer.prototype.getAverageCenter = function () {
619
+ return this.averageCenter;
620
+ };
621
+ Clusterer.prototype.setAverageCenter = function (averageCenter) {
622
+ this.averageCenter = averageCenter;
623
+ };
624
+ Clusterer.prototype.getIgnoreHidden = function () {
625
+ return this.ignoreHidden;
626
+ };
627
+ Clusterer.prototype.setIgnoreHidden = function (ignoreHidden) {
628
+ this.ignoreHidden = ignoreHidden;
629
+ };
630
+ Clusterer.prototype.getEnableRetinaIcons = function () {
631
+ return this.enableRetinaIcons;
632
+ };
633
+ Clusterer.prototype.setEnableRetinaIcons = function (enableRetinaIcons) {
634
+ this.enableRetinaIcons = enableRetinaIcons;
635
+ };
636
+ Clusterer.prototype.getImageExtension = function () {
637
+ return this.imageExtension;
638
+ };
639
+ Clusterer.prototype.setImageExtension = function (imageExtension) {
640
+ this.imageExtension = imageExtension;
641
+ };
642
+ Clusterer.prototype.getImagePath = function () {
643
+ return this.imagePath;
644
+ };
645
+ Clusterer.prototype.setImagePath = function (imagePath) {
646
+ this.imagePath = imagePath;
647
+ };
648
+ Clusterer.prototype.getImageSizes = function () {
649
+ return this.imageSizes;
650
+ };
651
+ Clusterer.prototype.setImageSizes = function (imageSizes) {
652
+ this.imageSizes = imageSizes;
653
+ };
654
+ Clusterer.prototype.getCalculator = function () {
655
+ return this.calculator;
656
+ };
657
+ Clusterer.prototype.setCalculator = function (calculator) {
658
+ this.calculator = calculator;
659
+ };
660
+ Clusterer.prototype.getBatchSizeIE = function () {
661
+ return this.batchSizeIE;
662
+ };
663
+ Clusterer.prototype.setBatchSizeIE = function (batchSizeIE) {
664
+ this.batchSizeIE = batchSizeIE;
665
+ };
666
+ Clusterer.prototype.getClusterClass = function () {
667
+ return this.clusterClass;
668
+ };
669
+ Clusterer.prototype.setClusterClass = function (clusterClass) {
670
+ this.clusterClass = clusterClass;
671
+ };
672
+ Clusterer.prototype.getMarkers = function () {
673
+ return this.markers;
674
+ };
675
+ Clusterer.prototype.getTotalMarkers = function () {
676
+ return this.markers.length;
677
+ };
678
+ Clusterer.prototype.getClusters = function () {
679
+ return this.clusters;
680
+ };
681
+ Clusterer.prototype.getTotalClusters = function () {
682
+ return this.clusters.length;
683
+ };
684
+ Clusterer.prototype.addMarker = function (marker, optNoDraw) {
685
+ this.pushMarkerTo(marker);
686
+ if (!optNoDraw) {
687
+ this.redraw();
688
+ }
689
+ };
690
+ Clusterer.prototype.addMarkers = function (markers, optNoDraw) {
691
+ for (var key in markers) {
692
+ if (markers.hasOwnProperty(key)) {
693
+ this.pushMarkerTo(markers[key]);
694
+ }
695
+ }
696
+ if (!optNoDraw) {
697
+ this.redraw();
698
+ }
699
+ };
700
+ Clusterer.prototype.pushMarkerTo = function (marker) {
701
+ var _this = this;
702
+ // If the marker is draggable add a listener so we can update the clusters on the dragend:
703
+ if (marker.getDraggable()) {
704
+ // eslint-disable-next-line @getify/proper-arrows/name, @getify/proper-arrows/this
705
+ google.maps.event.addListener(marker, 'dragend', function () {
706
+ if (_this.ready) {
707
+ marker.isAdded = false;
708
+ _this.repaint();
709
+ }
710
+ });
711
+ }
712
+ marker.isAdded = false;
713
+ this.markers.push(marker);
714
+ };
715
+ Clusterer.prototype.removeMarker_ = function (marker) {
716
+ var index = -1;
717
+ if (this.markers.indexOf) {
718
+ index = this.markers.indexOf(marker);
719
+ }
720
+ else {
721
+ for (var i = 0; i < this.markers.length; i++) {
722
+ if (marker === this.markers[i]) {
723
+ index = i;
724
+ break;
725
+ }
726
+ }
727
+ }
728
+ if (index === -1) {
729
+ // Marker is not in our list of markers, so do nothing:
730
+ return false;
731
+ }
732
+ marker.setMap(null);
733
+ this.markers.splice(index, 1); // Remove the marker from the list of managed markers
734
+ return true;
735
+ };
736
+ Clusterer.prototype.removeMarker = function (marker, optNoDraw) {
737
+ var removed = this.removeMarker_(marker);
738
+ if (!optNoDraw && removed) {
739
+ this.repaint();
740
+ }
741
+ return removed;
742
+ };
743
+ Clusterer.prototype.removeMarkers = function (markers, optNoDraw) {
744
+ var removed = false;
745
+ for (var i = 0; i < markers.length; i++) {
746
+ removed = removed || this.removeMarker_(markers[i]);
747
+ }
748
+ if (!optNoDraw && removed) {
749
+ this.repaint();
750
+ }
751
+ return removed;
752
+ };
753
+ Clusterer.prototype.clearMarkers = function () {
754
+ this.resetViewport(true);
755
+ this.markers = [];
756
+ };
757
+ Clusterer.prototype.repaint = function () {
758
+ var oldClusters = this.clusters.slice();
759
+ this.clusters = [];
760
+ this.resetViewport(false);
761
+ this.redraw();
762
+ // Remove the old clusters.
763
+ // Do it in a timeout to prevent blinking effect.
764
+ setTimeout(function timeout() {
765
+ for (var i = 0; i < oldClusters.length; i++) {
766
+ oldClusters[i].remove();
767
+ }
768
+ }, 0);
769
+ };
770
+ Clusterer.prototype.getExtendedBounds = function (bounds) {
771
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
772
+ // @ts-ignore
773
+ var projection = this.getProjection();
774
+ // Convert the points to pixels and the extend out by the grid size.
775
+ var trPix = projection.fromLatLngToDivPixel(
776
+ // Turn the bounds into latlng.
777
+ new google.maps.LatLng(bounds.getNorthEast().lat(), bounds.getNorthEast().lng()));
778
+ trPix.x += this.gridSize;
779
+ trPix.y -= this.gridSize;
780
+ var blPix = projection.fromLatLngToDivPixel(
781
+ // Turn the bounds into latlng.
782
+ new google.maps.LatLng(bounds.getSouthWest().lat(), bounds.getSouthWest().lng()));
783
+ blPix.x -= this.gridSize;
784
+ blPix.y += this.gridSize;
785
+ // Extend the bounds to contain the new bounds.
786
+ bounds.extend(
787
+ // Convert the pixel points back to LatLng nw
788
+ projection.fromDivPixelToLatLng(trPix));
789
+ bounds.extend(
790
+ // Convert the pixel points back to LatLng sw
791
+ projection.fromDivPixelToLatLng(blPix));
792
+ return bounds;
793
+ };
794
+ Clusterer.prototype.redraw = function () {
795
+ // Redraws all the clusters.
796
+ this.createClusters(0);
797
+ };
798
+ Clusterer.prototype.resetViewport = function (optHide) {
799
+ // Remove all the clusters
800
+ for (var i = 0; i < this.clusters.length; i++) {
801
+ this.clusters[i].remove();
802
+ }
803
+ this.clusters = [];
804
+ // Reset the markers to not be added and to be removed from the map.
805
+ for (var i = 0; i < this.markers.length; i++) {
806
+ var marker = this.markers[i];
807
+ marker.isAdded = false;
808
+ if (optHide) {
809
+ marker.setMap(null);
810
+ }
811
+ }
812
+ };
813
+ Clusterer.prototype.distanceBetweenPoints = function (p1, p2) {
814
+ var R = 6371; // Radius of the Earth in km
815
+ var dLat = ((p2.lat() - p1.lat()) * Math.PI) / 180;
816
+ var dLon = ((p2.lng() - p1.lng()) * Math.PI) / 180;
817
+ var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
818
+ Math.cos((p1.lat() * Math.PI) / 180) *
819
+ Math.cos((p2.lat() * Math.PI) / 180) *
820
+ Math.sin(dLon / 2) *
821
+ Math.sin(dLon / 2);
822
+ return R * (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
823
+ };
824
+ Clusterer.prototype.isMarkerInBounds = function (marker, bounds) {
825
+ var position = marker.getPosition();
826
+ if (position) {
827
+ return bounds.contains(position);
828
+ }
829
+ return false;
830
+ };
831
+ Clusterer.prototype.addToClosestCluster = function (marker) {
832
+ var cluster;
833
+ var distance = 40000; // Some large number
834
+ var clusterToAddTo = null;
835
+ for (var i = 0; i < this.clusters.length; i++) {
836
+ cluster = this.clusters[i];
837
+ var center = cluster.getCenter();
838
+ var position = marker.getPosition();
839
+ if (center && position) {
840
+ var d = this.distanceBetweenPoints(center, position);
841
+ if (d < distance) {
842
+ distance = d;
843
+ clusterToAddTo = cluster;
844
+ }
845
+ }
846
+ }
847
+ if (clusterToAddTo && clusterToAddTo.isMarkerInClusterBounds(marker)) {
848
+ clusterToAddTo.addMarker(marker);
849
+ }
850
+ else {
851
+ cluster = new Cluster(this);
852
+ cluster.addMarker(marker);
853
+ this.clusters.push(cluster);
854
+ }
855
+ };
856
+ Clusterer.prototype.createClusters = function (iFirst) {
857
+ var _this = this;
858
+ if (!this.ready) {
859
+ return;
860
+ }
861
+ // Cancel previous batch processing if we're working on the first batch:
862
+ if (iFirst === 0) {
863
+ /**
864
+ * This event is fired when the <code>Clusterer</code> begins
865
+ * clustering markers.
866
+ * @name Clusterer#clusteringbegin
867
+ * @param {Clusterer} mc The Clusterer whose markers are being clustered.
868
+ * @event
869
+ */
870
+ google.maps.event.trigger(this, 'clusteringbegin', this);
871
+ if (this.timerRefStatic !== null) {
872
+ window.clearTimeout(this.timerRefStatic);
873
+ // @ts-ignore
874
+ delete this.timerRefStatic;
875
+ }
876
+ }
877
+ // Get our current map view bounds.
878
+ // Create a new bounds object so we don't affect the map.
879
+ //
880
+ // See Comments 9 & 11 on Issue 3651 relating to this workaround for a Google Maps bug:
881
+ var mapBounds =
882
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
883
+ // @ts-ignore
884
+ this.getMap().getZoom() > 3
885
+ ? new google.maps.LatLngBounds(
886
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
887
+ // @ts-ignore
888
+ this.getMap()
889
+ .getBounds()
890
+ .getSouthWest(),
891
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
892
+ // @ts-ignore
893
+ this.getMap()
894
+ .getBounds()
895
+ .getNorthEast())
896
+ : new google.maps.LatLngBounds(new google.maps.LatLng(85.02070771743472, -178.48388434375), new google.maps.LatLng(-85.08136444384544, 178.00048865625));
897
+ var bounds = this.getExtendedBounds(mapBounds);
898
+ var iLast = Math.min(iFirst + this.batchSize, this.markers.length);
899
+ for (var i = iFirst; i < iLast; i++) {
900
+ var marker = this.markers[i];
901
+ if (!marker.isAdded && this.isMarkerInBounds(marker, bounds)) {
902
+ if (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible())) {
903
+ this.addToClosestCluster(marker);
904
+ }
905
+ }
906
+ }
907
+ if (iLast < this.markers.length) {
908
+ this.timerRefStatic = window.setTimeout(
909
+ // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
910
+ function () {
911
+ _this.createClusters(iLast);
912
+ }, 0);
913
+ }
914
+ else {
915
+ this.timerRefStatic = null;
916
+ /**
917
+ * This event is fired when the <code>Clusterer</code> stops
918
+ * clustering markers.
919
+ * @name Clusterer#clusteringend
920
+ * @param {Clusterer} mc The Clusterer whose markers are being clustered.
921
+ * @event
922
+ */
923
+ google.maps.event.trigger(this, 'clusteringend', this);
924
+ for (var i = 0; i < this.clusters.length; i++) {
925
+ this.clusters[i].updateIcon();
926
+ }
927
+ }
928
+ };
929
+ Clusterer.prototype.extend = function (obj1, obj2) {
930
+ return function applyExtend(object) {
931
+ // eslint-disable-next-line guard-for-in
932
+ for (var property in object.prototype) {
933
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
934
+ // @ts-ignore
935
+ this.prototype[property] = object.prototype[property];
936
+ }
937
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
938
+ // @ts-ignore
939
+ return this;
940
+ }.apply(obj1, [obj2]);
941
+ };
942
+ return Clusterer;
943
+ }());
940
944
 
941
- exports.Cluster = Cluster;
942
- exports.ClusterIcon = ClusterIcon;
943
- exports.Clusterer = Clusterer;
945
+ exports.Cluster = Cluster;
946
+ exports.ClusterIcon = ClusterIcon;
947
+ exports.Clusterer = Clusterer;
944
948
 
945
- Object.defineProperty(exports, '__esModule', { value: true });
949
+ Object.defineProperty(exports, '__esModule', { value: true });
946
950
 
947
- })));
951
+ }));
948
952
  //# sourceMappingURL=umd.js.map