Skip to content

Commit 03c6a2c

Browse files
authored
Merge pull request #3151 from Kontenty/fix/clusterer-example
2 parents e4d57d6 + 53e6f2c commit 03c6a2c

File tree

4 files changed

+81
-42
lines changed

4 files changed

+81
-42
lines changed

packages/react-google-maps-api/src/components/addons/GoogleMarkerClusterer.stories.tsx

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
21
import { ComponentStory, ComponentMeta } from '@storybook/react'
3-
import { GoogleMap, MarkerF , GoogleMapsMarkerClusterer as gm } from '../..'
2+
import { GoogleMap, MarkerF, GoogleMapsMarkerClusterer as gm } from '../..'
43
import GoogleMarkerClusterer from './GoogleMarkerClusterer'
54

6-
7-
const { DBScanAlgorithm, GridAlgorithm, KmeansAlgorithm, NoopAlgorithm } = gm
5+
const { GridAlgorithm, NoopAlgorithm } = gm
86

97
const mapContainerStyle = {
108
height: '400px',
@@ -52,33 +50,29 @@ const Template: ComponentStory<typeof GoogleMarkerClusterer> = (args) => {
5250
return (
5351
<GoogleMap mapContainerStyle={mapContainerStyle} zoom={3} center={center}>
5452
<GoogleMarkerClusterer {...args}>
55-
{(clusterer) =>
56-
locations.map((location) => (
57-
<MarkerF key={createKey(location)} position={location} clusterer={clusterer} />
58-
)) as any
59-
}
53+
{(clusterer) => (
54+
<>
55+
{locations.map((location) => (
56+
<MarkerF
57+
key={createKey(location)}
58+
position={location}
59+
clusterer={clusterer}
60+
/>
61+
))}
62+
</>
63+
)}
6064
</GoogleMarkerClusterer>
6165
</GoogleMap>
6266
)
6367
}
6468

6569
export const Default = Template.bind({})
6670

67-
export const DBScan = Template.bind({})
68-
DBScan.args = {
69-
options: { algorithm: new DBScanAlgorithm({}) },
70-
}
71-
7271
export const Grid = Template.bind({})
7372
Grid.args = {
7473
options: { algorithm: new GridAlgorithm({ maxDistance: 40000 }) },
7574
}
7675

77-
export const Kmeans = Template.bind({})
78-
Kmeans.args = {
79-
options: { algorithm: new KmeansAlgorithm({ numberOfClusters: 10 }) },
80-
}
81-
8276
export const Noop = Template.bind({})
8377
Noop.args = {
8478
options: { algorithm: new NoopAlgorithm({}) },

packages/react-google-maps-api/src/components/addons/MarkerClusterer.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,24 @@ function createKey(location) {
4949
const MapWithMarkerClusterer = () => {
5050
return (
5151
<ScriptLoaded>
52-
<GoogleMap id='marker-example' mapContainerStyle={mapContainerStyle} zoom={3} center={center}>
52+
<GoogleMap
53+
id='marker-example'
54+
mapContainerStyle={mapContainerStyle}
55+
zoom={3}
56+
center={center}
57+
>
5358
<MarkerClusterer options={options}>
54-
{(clusterer) =>
55-
locations.map((location) => (
56-
<MarkerF key={createKey(location)} position={location} clusterer={clusterer} />
57-
))
58-
}
59+
{(clusterer) => (
60+
<>
61+
{locations.map((location) => (
62+
<MarkerF
63+
key={createKey(location)}
64+
position={location}
65+
clusterer={clusterer}
66+
/>
67+
))}
68+
</>
69+
)}
5970
</MarkerClusterer>
6071
</GoogleMap>
6172
</ScriptLoaded>

packages/react-google-maps-api/src/components/addons/MarkerClusterer.stories.tsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { ComponentStory, ComponentMeta } from '@storybook/react'
22
import { GoogleMap, Marker } from '../..'
33
import MarkerClusterer from './MarkerClusterer'
44

5-
import { ClustererOptions, ClusterIconInfo, ClusterIconStyle, MarkerExtended } from '@react-google-maps/marker-clusterer'
5+
import {
6+
ClustererOptions,
7+
ClusterIconInfo,
8+
ClusterIconStyle,
9+
MarkerExtended,
10+
} from '@react-google-maps/marker-clusterer'
611

712
const mapContainerStyle = {
813
height: '400px',
@@ -72,7 +77,11 @@ const largeClusterIconStyle: ClusterIconStyle = {
7277
textSize: 22,
7378
}
7479

75-
const clusterIconStyles = [smallClusterIconStyle, mediumClusterIconStyle, largeClusterIconStyle]
80+
const clusterIconStyles = [
81+
smallClusterIconStyle,
82+
mediumClusterIconStyle,
83+
largeClusterIconStyle,
84+
]
7685

7786
const markerLengthToIndex = (length: number): number => {
7887
if (length >= 50) {
@@ -83,7 +92,9 @@ const markerLengthToIndex = (length: number): number => {
8392
return 1
8493
}
8594

86-
const markerClustererCalculator = (markers: MarkerExtended[]): ClusterIconInfo => ({
95+
const markerClustererCalculator = (
96+
markers: MarkerExtended[]
97+
): ClusterIconInfo => ({
8798
text: `${markers.length}`,
8899
index: markerLengthToIndex(markers.length),
89100
title: '',
@@ -105,11 +116,17 @@ const Template: ComponentStory<typeof MarkerClusterer> = (args) => {
105116
return (
106117
<GoogleMap mapContainerStyle={mapContainerStyle} zoom={3} center={center}>
107118
<MarkerClusterer {...args} options={markerClustererOptions}>
108-
{(clusterer) =>
109-
locations.map((location) => (
110-
<Marker key={createKey(location)} position={location} clusterer={clusterer} />
111-
)) as any
112-
}
119+
{(clusterer) => (
120+
<>
121+
{locations.map((location) => (
122+
<Marker
123+
key={createKey(location)}
124+
position={location}
125+
clusterer={clusterer}
126+
/>
127+
))}
128+
</>
129+
)}
113130
</MarkerClusterer>
114131
</GoogleMap>
115132
)

packages/react-google-maps-api/src/components/addons/MarkerClustererF.stories.tsx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { ComponentStory, ComponentMeta } from '@storybook/react'
22
import { GoogleMap, Marker } from '../..'
3-
import { MarkerClustererF} from './MarkerClusterer'
3+
import { MarkerClustererF } from './MarkerClusterer'
44

5-
import { ClustererOptions, ClusterIconInfo, ClusterIconStyle, MarkerExtended } from '@react-google-maps/marker-clusterer'
5+
import {
6+
ClustererOptions,
7+
ClusterIconInfo,
8+
ClusterIconStyle,
9+
MarkerExtended,
10+
} from '@react-google-maps/marker-clusterer'
611

712
const mapContainerStyle = {
813
height: '400px',
@@ -72,7 +77,11 @@ const largeClusterIconStyle: ClusterIconStyle = {
7277
textSize: 22,
7378
}
7479

75-
const clusterIconStyles = [smallClusterIconStyle, mediumClusterIconStyle, largeClusterIconStyle]
80+
const clusterIconStyles = [
81+
smallClusterIconStyle,
82+
mediumClusterIconStyle,
83+
largeClusterIconStyle,
84+
]
7685

7786
const markerLengthToIndex = (length: number): number => {
7887
if (length >= 50) {
@@ -83,7 +92,9 @@ const markerLengthToIndex = (length: number): number => {
8392
return 1
8493
}
8594

86-
const markerClustererCalculator = (markers: MarkerExtended[]): ClusterIconInfo => ({
95+
const markerClustererCalculator = (
96+
markers: MarkerExtended[]
97+
): ClusterIconInfo => ({
8798
text: `${markers.length}`,
8899
index: markerLengthToIndex(markers.length),
89100
title: '',
@@ -105,11 +116,17 @@ const Template: ComponentStory<typeof MarkerClustererF> = (args) => {
105116
return (
106117
<GoogleMap mapContainerStyle={mapContainerStyle} zoom={3} center={center}>
107118
<MarkerClustererF {...args} options={markerClustererOptions}>
108-
{(clusterer) =>
109-
locations.map((location) => (
110-
<Marker key={createKey(location)} position={location} clusterer={clusterer} />
111-
)) as any
112-
}
119+
{(clusterer) => (
120+
<>
121+
{locations.map((location) => (
122+
<Marker
123+
key={createKey(location)}
124+
position={location}
125+
clusterer={clusterer}
126+
/>
127+
))}
128+
</>
129+
)}
113130
</MarkerClustererF>
114131
</GoogleMap>
115132
)

0 commit comments

Comments
 (0)