Changed all stackblitz for playcode examples.

This commit is contained in:
NathanAP
2022-12-20 09:11:56 -03:00
parent 2cba776dc8
commit 7f400c6f3d
6 changed files with 61 additions and 131 deletions

View File

@@ -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>
```