@@ -125,6 +125,62 @@ https://en.wikipedia.org/w/index.php?title=Uluru
+
+## Use with vModel
+
+You can use v-model on the `InfoWindow` to manage it's open/closed state
+
+
+```vue
+
+
+
+
+
+
+
Uluru
+
+
Uluru, also referred to as Ayers Rock, is a large
+ sandstone rock formation in the southern part of the
+ Northern Territory, central Australia. It lies 335 km (208 mi)
+ south west of the nearest large town, Alice Springs; 450 km
+ (280 mi) by road. Kata Tjuta and Uluru are the two major
+ features of the Uluru - Kata Tjuta National Park. Uluru is
+ sacred to the Pitjantjatjara and Yankunytjatjara, the
+ Aboriginal people of the area. It has many springs, waterholes,
+ rock caves and ancient paintings. Uluru is listed as a World
+ Heritage Site.
+
Attribution: Uluru,
+ https://en.wikipedia.org/w/index.php?title=Uluru
+ (last visited June 22, 2009).
+
+
+
+
+
+
+
+
+```
+
## Events
You can listen for [the following events](https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindow-Events) on the `InfoWindow` component.
diff --git a/package.json b/package.json
index b441fbe..1110b3e 100644
--- a/package.json
+++ b/package.json
@@ -40,6 +40,7 @@
},
"scripts": {
"dev": "vite",
+ "prepare": "pnpm run build",
"clean": "rimraf dist/**/*",
"lint": "npx eslint --ext .ts,.vue src dev docs --fix",
"build:umd": "node ./scripts/build-umd.js",
@@ -56,6 +57,7 @@
"fast-deep-equal": "^3.1.3"
},
"devDependencies": {
+ "pnpm": "^8.7.6",
"@types/google.maps": "^3.53.6",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
@@ -77,7 +79,7 @@
"vue-tsc": "^1.8.8"
},
"peerDependencies": {
- "vue": "^3.3.4"
+ "vue": "^3"
},
"engines": {
"node": ">=16.11.0"
diff --git a/src/components/InfoWindow.vue b/src/components/InfoWindow.vue
index 68bd60a..b1c2680 100644
--- a/src/components/InfoWindow.vue
+++ b/src/components/InfoWindow.vue
@@ -32,9 +32,12 @@ export default defineComponent({
type: Object as PropType
,
default: () => ({}),
},
+ modelValue: {
+ type: Boolean,
+ },
},
- emits: infoWindowEvents,
+ emits: [...infoWindowEvents, "update:modelValue"],
setup(props, { slots, emit, expose }) {
const infoWindow = ref();
@@ -44,12 +47,28 @@ export default defineComponent({
const api = inject(apiSymbol, ref());
const anchor = inject(markerSymbol, ref());
let anchorClickListener: google.maps.MapsEventListener;
+ let internalVal = props.modelValue; // Doesn't need to be reactive
const hasSlotContent = computed(() => slots.default?.().some((vnode) => vnode.type !== Comment));
- const open = (opts?: google.maps.InfoWindowOpenOptions) =>
- infoWindow.value?.open({ map: map.value, anchor: anchor.value, ...opts });
- const close = () => infoWindow.value?.close();
+ const updateVModel = (val: boolean) => {
+ internalVal = val;
+ emit('update:modelValue', val);
+ }
+
+ const open = (opts?: google.maps.InfoWindowOpenOptions) => {
+ if (infoWindow.value) {
+ infoWindow.value.open({ map: map.value, anchor: anchor.value, ...opts });
+ updateVModel(true);
+ }
+ };
+
+ const close = () => {
+ if (infoWindow.value) {
+ infoWindow.value.close();
+ updateVModel(false);
+ }
+ };
onMounted(() => {
watch(
@@ -77,13 +96,16 @@ export default defineComponent({
anchorClickListener = anchor.value.addListener("click", () => {
open();
});
- } else {
+ }
+
+ if (!anchor.value || internalVal) {
open();
}
infoWindowEvents.forEach((event) => {
infoWindow.value?.addListener(event, (e: unknown) => emit(event, e));
});
+ infoWindow.value?.addListener('closeclick', () => updateVModel(false));
}
}
},
@@ -91,6 +113,12 @@ export default defineComponent({
immediate: true,
}
);
+
+ watch(() => props.modelValue, (val) => {
+ if (val !== internalVal) {
+ val ? open() : close();
+ }
+ });
});
onBeforeUnmount(() => {