inocan-group / vue3-google-map

A set of composable components for easy use of Google Maps in your Vue 3 projects.
https://vue3-google-map.com
MIT License
264 stars 50 forks source link

The map zoom doesn't seem to be working correctly #184

Closed MadeInShineA closed 5 months ago

MadeInShineA commented 7 months ago

I would like for the map to set the zoom level to 8 when a marker is clicked and that the zoom level is < 6

To do so I implemented this function

const zoom = ref(4);
function clickMarkerEvent(i) {
    console.log(zoom.value)
    if(zoom.value < 6){
        console.log('Zooming')
        zoom.value = 8;
    }

And I call it whenever a marker is clicked

<Marker v-for="(address, i) in addresses.data" @click="clickMarkerEvent" :options="{position: address.position, icon: {url: address.icon,  scaledSize: { width: 25, height: 25 }}}">
        ...
 </Marker>

However, it works as expected the first time I click on a marker but then, eventho I zoom and dezoom, the zoom value seems to be static

My conclusions are that the zoom value isn't changed when the map is zoomed or dezoomed but does change the map zoom if changed programmatically

0x011B commented 7 months ago

This is intended behavior; a property doesn't automatically behave like a v-model (getter & setter).

You have to get the zoom via the @zoom_changed event. It doesn't output anything (again, intended behavior), so you have to get the zoom with getZoom and likely set the zoom with setZoom instead of just changing the property.