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
feat(google-maps): OverlayView defaultOpen prop and LatLng position widening
Two additive changes to <ScriptGoogleMapsOverlayView>:
1. Add `defaultOpen` prop for the uncontrolled mode. The overlay still
opens on mount by default; pass `:default-open="false"` to start
closed without taking control of the open state via v-model. Bound
v-model:open continues to take precedence.
2. Widen the `position` prop to accept `google.maps.LatLng |
LatLngLiteral` so values returned by Maps APIs (e.g.
`resolveQueryToLatLng`, marker positions) can be passed straight
through without manual conversion.
Implementation notes:
- Refactored to reactive prop destructure with inline defaults
(matching the project preference); withDefaults removed
- defineModel kept for the `open` model so its `default: undefined`
opts out of Vue's boolean prop coercion (which would otherwise turn
an unset `open` into `false` and break the uncontrolled default)
- Added `normalizeLatLng` helper in `useGoogleMapsResource` that
detects callable `.lat`/`.lng` accessors instead of relying on
`instanceof google.maps.LatLng` (mocks in tests return plain objects)
- The `props.position` watcher source is normalized so the watch
identity is stable for both LatLng instances and literals
- Inline default for `defaultOpen` is `true`, preserving v0 behaviour
Docs: added "Controlled vs Uncontrolled Open State" and "Position
Format" sections to overlay-view.md.
Tests: new file `test/nuxt-runtime/google-maps-overlay-view.nuxt.test.ts`
covering the uncontrolled default, defaultOpen=false, controlled
explicit :open prop, and both position shapes via mountSuspended with a
minimal mock OverlayView base class. Plus pure-helper tests for
normalizeLatLng.
Copy file name to clipboardExpand all lines: docs/content/scripts/google-maps/2.api/11.overlay-view.md
+66Lines changed: 66 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,45 @@ When nested inside a `ScriptGoogleMapsMarker`, the overlay automatically inherit
31
31
</template>
32
32
```
33
33
34
+
## Controlled vs Uncontrolled Open State
35
+
36
+
The overlay supports two open-state patterns: uncontrolled (component-managed) and controlled (parent-managed via `v-model:open`).
37
+
38
+
**Uncontrolled.** The component owns its open state. The overlay opens by default; pass `:default-open="false"` to start closed. This is the simplest pattern when you don't need to react to state changes from the parent.
<!-- Starts closed; toggle later via a template ref or marker click -->
48
+
<ScriptGoogleMapsOverlayView
49
+
:position="{ lat: -34.397, lng: 150.644 }"
50
+
:default-open="false"
51
+
>
52
+
<div>Initially hidden</div>
53
+
</ScriptGoogleMapsOverlayView>
54
+
</template>
55
+
```
56
+
57
+
**Controlled.** Bind `v-model:open` to a parent ref. The parent owns the state and the overlay reflects it. The overlay updates the bound ref when something internal flips it (for example, the marker-cluster auto-hide behaviour).
When `v-model:open` is bound, `defaultOpen` has no effect; pass an initial value to the bound ref instead.
72
+
34
73
## Popup on Marker Click
35
74
36
75
Using `v-model:open` keeps the overlay mounted, toggling visibility via CSS. This avoids remount cost and preserves internal state.
@@ -94,6 +133,33 @@ For simple cases where remounting is acceptable, `v-if` also works:
94
133
</template>
95
134
```
96
135
136
+
## Position Format
137
+
138
+
The `position` prop accepts either a plain `LatLngLiteral` (`{ lat, lng }`) or a `google.maps.LatLng` instance, so you can pass values straight from the Maps API without converting them first.
139
+
140
+
```vue
141
+
<script setup lang="ts">
142
+
const mapRef = ref()
143
+
144
+
async function showSydney() {
145
+
// Resolve a query into a LatLng-shaped value via the Maps API
146
+
const sydney = await mapRef.value?.resolveQueryToLatLng('Sydney, Australia')
147
+
// Pass it through unchanged: works for both shapes
When an overlay opens, the map automatically pans so the overlay is fully visible, matching the native `InfoWindow` behavior. The default padding is 40px from the map edge.
0 commit comments