Skip to content

Commit 53e6f2c

Browse files
author
Konrad Gorski
committed
fix: example for using cuterer with markers map
1 parent cbd06d0 commit 53e6f2c

File tree

4 files changed

+79
-32
lines changed

4 files changed

+79
-32
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@ const Template: ComponentStory<typeof GoogleMarkerClusterer> = (args) => {
5050
return (
5151
<GoogleMap mapContainerStyle={mapContainerStyle} zoom={3} center={center}>
5252
<GoogleMarkerClusterer {...args}>
53-
{(clusterer) =>
54-
locations.map((location) => (
55-
<MarkerF
56-
key={createKey(location)}
57-
position={location}
58-
clusterer={clusterer}
59-
/>
60-
)) as any
61-
}
53+
{(clusterer) => (
54+
<>
55+
{locations.map((location) => (
56+
<MarkerF
57+
key={createKey(location)}
58+
position={location}
59+
clusterer={clusterer}
60+
/>
61+
))}
62+
</>
63+
)}
6264
</GoogleMarkerClusterer>
6365
</GoogleMap>
6466
)

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)