vue-google-maps icon indicating copy to clipboard operation
vue-google-maps copied to clipboard

Getting map center point after drag

Open SomewhatCloudy opened this issue 2 years ago • 4 comments

I've got a whole load of markers so I'd like to dynamically load them in based upon the map center. However I don't see an elegant way to get this data.

Ideally the dragend event (and other drag events) on <GMapMap> should return the new center location data. Or is there a better way of doing this?

SomewhatCloudy avatar Mar 08 '22 20:03 SomewhatCloudy

Theoretically, you ~bind~ model the center and then you have it. Or, at least as a user that is what I would expect. Can you confirm whether that is working?

Edit: v-model:center="center"

<template>
  {{ center }}
  <GMapMap :center="center" />
</template>

<script setup>
import { reactive } from "vue";

const center = reactive({ lat: 0, lng: 0 });
</script>

aentwist avatar Mar 22 '22 04:03 aentwist

Nope, that didn't work. Thanks though.

SomewhatCloudy avatar Mar 24 '22 15:03 SomewhatCloudy

I had a look through the code and found these events on the GMapMap component:

  center_changed
  zoom_changed
  bounds_changed

Which also provides the relevant information as a callback. Hope this helps someone else in the future!

SomewhatCloudy avatar Mar 25 '22 09:03 SomewhatCloudy

Oops - of course binding it wouldn't propagate the update back. I would still consider this an issue, because this should be available through v-model here. With the power of Vue 3 v-model, there no longer needs to be any strange v-bind.sync patterns going on when there is more than one value to model.

aentwist avatar Mar 26 '22 04:03 aentwist