You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/scripts/google-maps/2.api/4.marker-clusterer.md
+40-2Lines changed: 40 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,9 +71,9 @@ function addLocation(position: google.maps.LatLngLiteral) {
71
71
</template>
72
72
```
73
73
74
-
### Custom Algorithm & Renderer
74
+
### Custom Algorithm
75
75
76
-
Pass `algorithm`and `renderer`through `options` to customize clustering behavior. See the [`@googlemaps/markerclusterer` documentation](https://googlemaps.github.io/js-markerclusterer/) for available algorithms.
76
+
Pass `algorithm` through `options` to customize clustering behavior. See the [`@googlemaps/markerclusterer` documentation](https://googlemaps.github.io/js-markerclusterer/) for available algorithms.
77
77
78
78
```vue
79
79
<script setup lang="ts">
@@ -97,6 +97,44 @@ const clustererOptions = {
97
97
</template>
98
98
```
99
99
100
+
### Custom Cluster Renderer
101
+
102
+
Use the `#renderer` slot to customize how clusters look using Vue templates. The slot receives `cluster` (with `count`, `position`, `markers`), `stats`, and `map` (the Google Maps instance).
103
+
104
+
```vue
105
+
<template>
106
+
<ScriptGoogleMaps api-key="your-api-key">
107
+
<ScriptGoogleMapsMarkerClusterer>
108
+
<template #renderer="{ cluster }">
109
+
<div
110
+
style="
111
+
background: #4285f4;
112
+
color: white;
113
+
border-radius: 50%;
114
+
width: 40px;
115
+
height: 40px;
116
+
display: flex;
117
+
align-items: center;
118
+
justify-content: center;
119
+
font-weight: bold;
120
+
"
121
+
>
122
+
{{ cluster.count }}
123
+
</div>
124
+
</template>
125
+
126
+
<ScriptGoogleMapsMarker
127
+
v-for="loc in locations"
128
+
:key="loc.id"
129
+
:position="loc.position"
130
+
/>
131
+
</ScriptGoogleMapsMarkerClusterer>
132
+
</ScriptGoogleMaps>
133
+
</template>
134
+
```
135
+
136
+
The `#renderer` slot overrides the `renderer` option. Each cluster gets its own `AdvancedMarkerElement` with the slot content as its visual.
137
+
100
138
::callout
101
139
The clusterer only renders its default slot after the clusterer instance is ready. This prevents child markers from mounting before the clusterer can receive them.
0 commit comments