Changed all stackblitz for playcode examples.
This commit is contained in:
@@ -1,21 +1,26 @@
|
||||
# How to access Google Maps object
|
||||
|
||||
[Interactive example on CodeSandbox](https://stackblitz.com/edit/vue-google-maps-marker-khyhfk?file=src/components/ComponentWithMap.vue)
|
||||
[Interactive example on Playcode](https://playcode.io/1041251)
|
||||
|
||||
To access Google maps object, or do something when map is loaded, use a ref on the `GMapMap` object.
|
||||
|
||||
## Example
|
||||
|
||||
```html
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
const center = ref({ lat: 51.093048, lng: 6.84212 })
|
||||
const markers = ref([{ position: { lat: 51.093048, lng: 6.84212 } }])
|
||||
|
||||
const myMapRef = ref(null)
|
||||
|
||||
watch(myMapRef, (newValue) => console.log(newValue))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<GMapMap
|
||||
:center="center"
|
||||
ref="myMapRef"
|
||||
:zoom="10"
|
||||
map-type-id="terrain"
|
||||
style="width: 100vw; height: 20rem"
|
||||
>
|
||||
<GMapCluster :zoomOnClick="true">
|
||||
<GMapMap ref="myMapRef" :center="center" :zoom="7" style="width: 500px; height: 300px">
|
||||
<GMapCluster :maxZoom="12">
|
||||
<GMapMarker
|
||||
:key="index"
|
||||
v-for="(m, index) in markers"
|
||||
@@ -27,51 +32,4 @@ To access Google maps object, or do something when map is loaded, use a ref on t
|
||||
</GMapCluster>
|
||||
</GMapMap>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
mounted() {
|
||||
this.$refs.myMapRef.$mapPromise.then((mapObject) => {
|
||||
console.log('map is loaded now', mapObject)
|
||||
})
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
center: { lat: 51.093048, lng: 6.84212 },
|
||||
markers: [
|
||||
{
|
||||
position: {
|
||||
lat: 51.093048,
|
||||
lng: 6.84212,
|
||||
},
|
||||
},
|
||||
{
|
||||
position: {
|
||||
lat: 51.198429,
|
||||
lng: 6.69529,
|
||||
},
|
||||
},
|
||||
{
|
||||
position: {
|
||||
lat: 51.165218,
|
||||
lng: 7.067116,
|
||||
},
|
||||
},
|
||||
{
|
||||
position: {
|
||||
lat: 51.09256,
|
||||
lng: 6.84074,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user