@react-google-maps/marker-clusterer 2.6.0 → 2.10.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/src/Clusterer.tsx CHANGED
@@ -26,7 +26,7 @@ const CALCULATOR = function CALCULATOR(
26
26
 
27
27
  return {
28
28
  text: count.toString(),
29
- index: index,
29
+ index,
30
30
  title: '',
31
31
  }
32
32
  }
@@ -134,13 +134,13 @@ export class Clusterer {
134
134
  this.setupStyles()
135
135
 
136
136
  this.addMarkers(optMarkers, true)
137
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
137
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
138
138
  // @ts-ignore
139
139
  this.setMap(map) // Note: this causes onAdd to be called
140
140
  }
141
141
 
142
142
  onAdd() {
143
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
143
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
144
144
  // @ts-ignore
145
145
  this.activeMap = this.getMap()
146
146
 
@@ -151,11 +151,10 @@ export class Clusterer {
151
151
  // Add the map event listeners
152
152
  this.listeners = [
153
153
  google.maps.event.addListener(
154
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
154
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
155
155
  // @ts-ignore
156
156
  this.getMap(),
157
157
  'zoom_changed',
158
- // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
159
158
  () => {
160
159
  this.resetViewport(false)
161
160
  // Workaround for this Google bug: when map is at level 0 and "-" of
@@ -164,10 +163,10 @@ export class Clusterer {
164
163
  // event is triggered so the cluster markers that have been removed
165
164
  // do not get redrawn. Same goes for a zoom in at maxZoom.
166
165
  if (
167
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
166
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
168
167
  // @ts-ignore
169
168
  this.getMap().getZoom() === (this.get('minZoom') || 0) ||
170
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
169
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
171
170
  // @ts-ignore
172
171
  this.getMap().getZoom() === this.get('maxZoom')
173
172
  ) {
@@ -176,11 +175,10 @@ export class Clusterer {
176
175
  }
177
176
  ),
178
177
  google.maps.event.addListener(
179
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
178
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
180
179
  // @ts-ignore
181
180
  this.getMap(),
182
181
  'idle',
183
- // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
184
182
  () => {
185
183
  this.redraw()
186
184
  }
@@ -188,7 +186,6 @@ export class Clusterer {
188
186
  ]
189
187
  }
190
188
 
191
- // eslint-disable-next-line @getify/proper-arrows/this
192
189
  onRemove() {
193
190
  // Put all the managed markers back on the map:
194
191
  for (let i = 0; i < this.markers.length; i++) {
@@ -245,7 +242,7 @@ export class Clusterer {
245
242
  }
246
243
  }
247
244
 
248
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
245
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
249
246
  // @ts-ignore
250
247
  this.getMap().fitBounds(bounds)
251
248
  }
@@ -396,7 +393,7 @@ export class Clusterer {
396
393
 
397
394
  addMarkers(markers: MarkerExtended[], optNoDraw: boolean) {
398
395
  for (const key in markers) {
399
- if (markers.hasOwnProperty(key)) {
396
+ if (Object.prototype.hasOwnProperty.call(markers, key)) {
400
397
  this.pushMarkerTo(markers[key])
401
398
  }
402
399
  }
@@ -409,7 +406,6 @@ export class Clusterer {
409
406
  pushMarkerTo(marker: MarkerExtended) {
410
407
  // If the marker is draggable add a listener so we can update the clusters on the dragend:
411
408
  if (marker.getDraggable()) {
412
- // eslint-disable-next-line @getify/proper-arrows/name, @getify/proper-arrows/this
413
409
  google.maps.event.addListener(marker, 'dragend', () => {
414
410
  if (this.ready) {
415
411
  marker.isAdded = false
@@ -500,7 +496,7 @@ export class Clusterer {
500
496
  }
501
497
 
502
498
  getExtendedBounds(bounds: google.maps.LatLngBounds): google.maps.LatLngBounds {
503
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
499
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
504
500
  // @ts-ignore
505
501
  const projection = this.getProjection()
506
502
  // Convert the points to pixels and the extend out by the grid size.
@@ -640,6 +636,7 @@ export class Clusterer {
640
636
  if (this.timerRefStatic !== null) {
641
637
  window.clearTimeout(this.timerRefStatic)
642
638
 
639
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
643
640
  // @ts-ignore
644
641
  delete this.timerRefStatic
645
642
  }
@@ -650,16 +647,16 @@ export class Clusterer {
650
647
  //
651
648
  // See Comments 9 & 11 on Issue 3651 relating to this workaround for a Google Maps bug:
652
649
  const mapBounds =
653
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
650
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
654
651
  // @ts-ignore
655
652
  this.getMap().getZoom() > 3
656
653
  ? new google.maps.LatLngBounds(
657
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
654
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
658
655
  // @ts-ignore
659
656
  this.getMap()
660
657
  .getBounds()
661
658
  .getSouthWest(),
662
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
659
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
663
660
  // @ts-ignore
664
661
  this.getMap()
665
662
  .getBounds()
@@ -677,16 +674,13 @@ export class Clusterer {
677
674
  for (let i = iFirst; i < iLast; i++) {
678
675
  const marker = this.markers[i]
679
676
 
680
- if (!marker.isAdded && this.isMarkerInBounds(marker, bounds)) {
681
- if (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible())) {
682
- this.addToClosestCluster(marker)
683
- }
677
+ if (!marker.isAdded && this.isMarkerInBounds(marker, bounds) && (!this.ignoreHidden || (this.ignoreHidden && marker.getVisible()))) {
678
+ this.addToClosestCluster(marker)
684
679
  }
685
680
  }
686
681
 
687
682
  if (iLast < this.markers.length) {
688
683
  this.timerRefStatic = window.setTimeout(
689
- // eslint-disable-next-line @getify/proper-arrows/this, @getify/proper-arrows/name
690
684
  () => {
691
685
  this.createClusters(iLast)
692
686
  },
@@ -714,12 +708,12 @@ export class Clusterer {
714
708
  return function applyExtend(object: any) {
715
709
  // eslint-disable-next-line guard-for-in
716
710
  for (const property in object.prototype) {
717
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
711
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
718
712
  // @ts-ignore
719
713
  this.prototype[property] = object.prototype[property]
720
714
  }
721
715
 
722
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
716
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
723
717
  // @ts-ignore
724
718
  return this
725
719
  }.apply(obj1, [obj2])
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
1
5
  import { Clusterer } from '../Clusterer'
2
6
 
3
7
  describe('Clusterer', () => {
package/src/index.ts CHANGED
@@ -43,9 +43,9 @@ export { Cluster } from './Cluster'
43
43
  export { ClusterIcon } from './ClusterIcon'
44
44
 
45
45
  export {
46
- ClusterIconInfo,
47
- ClusterIconStyle,
48
- MarkerExtended,
49
- TCalculator,
50
- ClustererOptions,
46
+ type ClusterIconInfo,
47
+ type ClusterIconStyle,
48
+ type MarkerExtended,
49
+ type TCalculator,
50
+ type ClustererOptions,
51
51
  } from './types'
package/src/types.tsx CHANGED
@@ -11,6 +11,22 @@ export type MarkerExtended = google.maps.Marker & {
11
11
 
12
12
  export type TCalculator = (markers: MarkerExtended[], num: number) => ClusterIconInfo
13
13
 
14
+ export interface ClusterIconStyle {
15
+ url: string
16
+ className?: string
17
+ height: number
18
+ width: number
19
+ anchorText?: number[]
20
+ anchorIcon?: number[]
21
+ textColor?: string
22
+ textSize?: number
23
+ textDecoration?: string
24
+ fontWeight?: string
25
+ fontStyle?: string
26
+ fontFamily?: string
27
+ backgroundPosition?: string
28
+ }
29
+
14
30
  export interface ClustererOptions {
15
31
  gridSize?: number
16
32
  maxZoom?: number
@@ -29,19 +45,3 @@ export interface ClustererOptions {
29
45
  imageExtension?: string
30
46
  imageSizes?: number[]
31
47
  }
32
-
33
- export interface ClusterIconStyle {
34
- url: string
35
- className?: string
36
- height: number
37
- width: number
38
- anchorText?: number[]
39
- anchorIcon?: number[]
40
- textColor?: string
41
- textSize?: number
42
- textDecoration?: string
43
- fontWeight?: string
44
- fontStyle?: string
45
- fontFamily?: string
46
- backgroundPosition?: string
47
- }
@@ -1,356 +0,0 @@
1
- const createMockFuncsFromArray = (instance, names = []) => {
2
- names.forEach(name => {
3
- instance[name] = jest.fn().mockName(name)
4
- })
5
- }
6
-
7
- const createGoogleMapsMock = (libraries = []) => {
8
- const createMVCObject = instance => {
9
- const listeners = {}
10
- instance.listeners = listeners
11
-
12
- instance.addListener = jest
13
- .fn((event, fn) => {
14
- listeners[event] = listeners[event] || []
15
- listeners[event].push(fn)
16
- return {
17
- remove: () => {
18
- const index = listeners[event].indexOf(fn)
19
-
20
- if (index !== -1) {
21
- listeners[event].splice(index, 1)
22
- }
23
- },
24
- }
25
- })
26
- .mockName('addListener')
27
-
28
- createMockFuncsFromArray(instance, [
29
- 'bindTo',
30
- 'get',
31
- 'notify',
32
- 'set',
33
- 'setValues',
34
- 'unbind',
35
- 'unbindAll',
36
- ])
37
- }
38
-
39
- const OverlayViewMock = function() {}
40
- OverlayViewMock.prototype.setMap = jest.fn()
41
-
42
- const maps = {
43
- Animation: {
44
- BOUNCE: 1,
45
- DROP: 2,
46
- Lo: 3,
47
- Go: 4,
48
- },
49
- BicyclingLayer: jest.fn().mockImplementation(function() {
50
- createMVCObject(this)
51
- createMockFuncsFromArray(this, ['setMap'])
52
- }),
53
- TransitLayer: jest.fn().mockImplementation(function() {
54
- createMVCObject(this)
55
- createMockFuncsFromArray(this, ['setMap'])
56
- }),
57
- Circle: jest.fn().mockImplementation(function(opts) {
58
- this.opts = opts
59
- createMVCObject(this)
60
- createMockFuncsFromArray(this, [
61
- 'setCenter',
62
- 'setDraggable',
63
- 'setEditable',
64
- 'setMap',
65
- 'setOptions',
66
- 'setRadius',
67
- 'setVisible',
68
- ])
69
- }),
70
- ControlPosition: {
71
- TOP_LEFT: 1,
72
- TOP_CENTER: 2,
73
- TOP: 2,
74
- TOP_RIGHT: 3,
75
- LEFT_CENTER: 4,
76
- LEFT: 5,
77
- LEFT_TOP: 5,
78
- LEFT_BOTTOM: 6,
79
- RIGHT: 7,
80
- RIGHT_CENTER: 8,
81
- RIGHT_BOTTOM: 9,
82
- BOTTOM_LEFT: 10,
83
- BOTTOM: 11,
84
- BOTTOM_CENTER: 11,
85
- BOTTOM_RIGHT: 12,
86
- CENTER: 13,
87
- },
88
- Data: jest.fn().mockImplementation(function(options) {
89
- this.options = options
90
- createMVCObject(this)
91
- createMockFuncsFromArray(this, [
92
- 'setControlPosition',
93
- 'setControls',
94
- 'setDrawingMode',
95
- 'setMap',
96
- 'setStyle',
97
- ])
98
- }),
99
- DirectionsRenderer: jest.fn().mockImplementation(function(opts) {
100
- this.opts = opts
101
- createMVCObject(this)
102
- createMockFuncsFromArray(this, [
103
- 'setDirections',
104
- 'setMap',
105
- 'setOptions',
106
- 'setPanel',
107
- 'setRouteIndex',
108
- ])
109
- }),
110
- DirectionsService: function() {},
111
- DirectionsStatus: {
112
- INVALID_REQUEST: 'INVALID_REQUEST',
113
- MAX_WAYPOINTS_EXCEEDED: 'MAX_WAYPOINTS_EXCEEDED',
114
- NOT_FOUND: 'NOT_FOUND',
115
- OK: 'OK',
116
- OVER_QUERY_LIMIT: 'OVER_QUERY_LIMIT',
117
- REQUEST_DENIED: 'REQUEST_DENIED',
118
- UNKNOWN_ERROR: 'UNKNOWN_ERROR',
119
- ZERO_RESULTS: 'ZERO_RESULTS',
120
- },
121
- DirectionsTravelMode: {
122
- BICYCLING: 'BICYCLING',
123
- DRIVING: 'DRIVING',
124
- TRANSIT: 'TRANSIT',
125
- WALKING: 'WALKING',
126
- },
127
- DirectionsUnitSystem: {
128
- IMPERIAL: 1,
129
- METRIC: 0,
130
- },
131
- DistanceMatrixElementStatus: {
132
- NOT_FOUND: 'NOT_FOUND',
133
- OK: 'OK',
134
- ZERO_RESULTS: 'ZERO_RESULTS',
135
- },
136
- DistanceMatrixService: function() {},
137
- DistanceMatrixStatus: {
138
- INVALID_REQUEST: 'INVALID_REQUEST',
139
- MAX_DIMENSIONS_EXCEEDED: 'MAX_DIMENSIONS_EXCEEDED',
140
- MAX_ELEMENTS_EXCEEDED: 'MAX_ELEMENTS_EXCEEDED',
141
- OK: 'OK',
142
- OVER_QUERY_LIMIT: 'OVER_QUERY_LIMIT',
143
- REQUEST_DENIED: 'REQUEST_DENIED',
144
- UNKNOWN_ERROR: 'UNKNOWN_ERROR',
145
- },
146
- ElevationService: function() {},
147
- ElevationStatus: {
148
- Co: 'DATA_NOT_AVAILABLE',
149
- INVALID_REQUEST: 'INVALID_REQUEST',
150
- OK: 'OK',
151
- OVER_QUERY_LIMIT: 'OVER_QUERY_LIMIT',
152
- REQUEST_DENIED: 'REQUEST_DENIED',
153
- UNKNOWN_ERROR: 'UNKNOWN_ERROR',
154
- },
155
- FusionTablesLayer: jest.fn().mockImplementation(function(options) {
156
- this.options = options
157
- createMVCObject(this)
158
- createMockFuncsFromArray(this, ['setMap', 'setOptions'])
159
- }),
160
- Geocoder: function() {},
161
- GeocoderLocationType: {
162
- APPROXIMATE: 'APPROXIMATE',
163
- GEOMETRIC_CENTER: 'GEOMETRIC_CENTER',
164
- RANGE_INTERPOLATED: 'RANGE_INTERPOLATED',
165
- ROOFTOP: 'ROOFTOP',
166
- },
167
- GeocoderStatus: {
168
- ERROR: 'ERROR',
169
- INVALID_REQUEST: 'INVALID_REQUEST',
170
- OK: 'OK',
171
- OVER_QUERY_LIMIT: 'OVER_QUERY_LIMIT',
172
- REQUEST_DENIED: 'REQUEST_DENIED',
173
- UNKNOWN_ERROR: 'UNKNOWN_ERROR',
174
- ZERO_RESULTS: 'ZERO_RESULTS',
175
- },
176
- GroundOverlay: function() {},
177
- ImageMapType: function() {},
178
- InfoWindow: function() {},
179
- KmlLayer: function() {},
180
- KmlLayerStatus: {
181
- DOCUMENT_NOT_FOUND: 'DOCUMENT_NOT_FOUND',
182
- DOCUMENT_TOO_LARGE: 'DOCUMENT_TOO_LARGE',
183
- FETCH_ERROR: 'FETCH_ERROR',
184
- INVALID_DOCUMENT: 'INVALID_DOCUMENT',
185
- INVALID_REQUEST: 'INVALID_REQUEST',
186
- LIMITS_EXCEEDED: 'LIMITS_EXCEEDED',
187
- OK: 'OK',
188
- TIMED_OUT: 'TIMED_OUT',
189
- UNKNOWN: 'UNKNOWN',
190
- },
191
- LatLng: function() {},
192
- LatLngBounds: function() {},
193
- MVCArray: function() {},
194
- MVCObject: jest.fn().mockImplementation(function() {
195
- createMVCObject(this)
196
- }),
197
- Map: jest.fn().mockImplementation(function(mapDiv, opts) {
198
- this.mapDiv = mapDiv
199
- this.opts = opts
200
- createMVCObject(this)
201
- createMockFuncsFromArray(this, [
202
- 'setCenter',
203
- 'setClickableIcons',
204
- 'setHeading',
205
- 'setMapTypeId',
206
- 'setOptions',
207
- 'setStreetView',
208
- 'setTilt',
209
- 'setZoom',
210
- 'fitBounds',
211
- 'getBounds',
212
- 'panToBounds',
213
- ])
214
- }),
215
- MapTypeControlStyle: {
216
- DEFAULT: 0,
217
- DROPDOWN_MENU: 2,
218
- HORIZONTAL_BAR: 1,
219
- INSET: 3,
220
- INSET_LARGE: 4,
221
- },
222
- MapTypeId: {
223
- HYBRID: 'hybrid',
224
- ROADMAP: 'roadmap',
225
- SATELLITE: 'satellite',
226
- TERRAIN: 'terrain',
227
- },
228
- MapTypeRegistry: function() {},
229
- Marker: jest.fn().mockImplementation(function(opts) {
230
- this.opts = opts
231
- createMVCObject(this)
232
- createMockFuncsFromArray(this, [
233
- 'setMap',
234
- 'setOpacity',
235
- 'setOptions',
236
- 'setPosition',
237
- 'setShape',
238
- 'setTitle',
239
- 'setVisible',
240
- 'setZIndex',
241
- ])
242
- }),
243
- MarkerImage: function() {},
244
- MaxZoomService: function() {
245
- return {
246
- getMaxZoomAtLatLng: function() {},
247
- }
248
- },
249
- MaxZoomStatus: {
250
- ERROR: 'ERROR',
251
- OK: 'OK',
252
- },
253
- NavigationControlStyle: {
254
- ANDROID: 2,
255
- DEFAULT: 0,
256
- Mo: 4,
257
- SMALL: 1,
258
- ZOOM_PAN: 3,
259
- ik: 5,
260
- },
261
- OverlayView: OverlayViewMock,
262
- Point: function() {},
263
- Polygon: function() {},
264
- Polyline: function() {},
265
- Rectangle: function() {},
266
- SaveWidget: function() {},
267
- ScaleControlStyle: {
268
- DEFAULT: 0,
269
- },
270
- Size: function() {},
271
- StreetViewCoverageLayer: function() {},
272
- StreetViewPanorama: function() {},
273
- StreetViewPreference: {
274
- BEST: 'best',
275
- NEAREST: 'nearest',
276
- },
277
- StreetViewService: function() {},
278
- StreetViewSource: {
279
- DEFAULT: 'default',
280
- OUTDOOR: 'outdoor',
281
- },
282
- StreetViewStatus: {
283
- OK: 'OK',
284
- UNKNOWN_ERROR: 'UNKNOWN_ERROR',
285
- ZERO_RESULTS: 'ZERO_RESULTS',
286
- },
287
- StrokePosition: {
288
- CENTER: 0,
289
- INSIDE: 1,
290
- OUTSIDE: 2,
291
- },
292
- StyledMapType: function() {},
293
- SymbolPath: {
294
- BACKWARD_CLOSED_ARROW: 3,
295
- BACKWARD_OPEN_ARROW: 4,
296
- CIRCLE: 0,
297
- FORWARD_CLOSED_ARROW: 1,
298
- FORWARD_OPEN_ARROW: 2,
299
- },
300
- TrafficLayer: jest.fn().mockImplementation(function(opts) {
301
- this.opts = opts
302
- createMVCObject(this)
303
- createMockFuncsFromArray(this, ['setMap', 'setOptions'])
304
- }),
305
- TrafficModel: {
306
- BEST_GUESS: 'bestguess',
307
- OPTIMISTIC: 'optimistic',
308
- PESSIMISTIC: 'pessimistic',
309
- },
310
- TransitMode: {
311
- BUS: 'BUS',
312
- RAIL: 'RAIL',
313
- SUBWAY: 'SUBWAY',
314
- TRAIN: 'TRAIN',
315
- TRAM: 'TRAM',
316
- },
317
- TransitRoutePreference: {
318
- FEWER_TRANSFERS: 'FEWER_TRANSFERS',
319
- LESS_WALKING: 'LESS_WALKING',
320
- },
321
- TravelMode: {
322
- BICYCLING: 'BICYCLING',
323
- DRIVING: 'DRIVING',
324
- TRANSIT: 'TRANSIT',
325
- WALKING: 'WALKING',
326
- },
327
- UnitSystem: {
328
- IMPERIAL: 1,
329
- METRIC: 0,
330
- },
331
- ZoomControlStyle: {
332
- DEFAULT: 0,
333
- LARGE: 2,
334
- SMALL: 1,
335
- ik: 3,
336
- },
337
- __gjsload__: function() {},
338
- event: {
339
- clearInstanceListeners: jest.fn().mockName('clearInstanceListeners'),
340
- },
341
- }
342
-
343
- if (libraries.includes('places')) {
344
- maps.places = {
345
- AutocompleteService: jest.fn(() => ({
346
- getPlacePredictions: jest.fn(),
347
- })),
348
- }
349
- }
350
-
351
- return maps
352
- }
353
-
354
- window.google = {
355
- maps: createGoogleMapsMock(),
356
- }