forked from GuillaumeLeclerc/vue-google-maps
-
Notifications
You must be signed in to change notification settings - Fork 472
/
Copy pathinfowindow.html
85 lines (75 loc) · 2.36 KB
/
infowindow.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<body>
<div id="root">
A basic example of using a single infowindow for 3 markers.
<gmap-map :center="center" :zoom="15" style="width: 100%; height: 500px">
<gmap-info-window :options="infoOptions" :position="infoWindowPos" :opened="infoWinOpen" @closeclick="infoWinOpen=false">
</gmap-info-window>
<gmap-marker :key="i" v-for="(m,i) in markers" :position="m.position" :clickable="true" @click="toggleInfoWindow(m,i)"></gmap-marker>
</gmap-map>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.0/vue.js"></script>
<script src="vue-google-maps.js"></script>
<script>
Vue.use(VueGoogleMaps, {
load: {
key: 'AIzaSyDf43lPdwlF98RCBsJOFNKOkoEjkwxb5Sc'
},
});
document.addEventListener('DOMContentLoaded', function() {
new Vue({
el: '#root',
data: {
center: {
lat: 47.376332,
lng: 8.547511
},
infoWindowPos: null,
infoWinOpen: false,
currentMidx: null,
infoOptions: {
content: '',
//optional: offset infowindow so it visually sits nicely on top of our marker
pixelOffset: {
width: 0,
height: -35
}
},
markers: [{
position: {
lat: 47.376332,
lng: 8.547511
},
infoText: '<strong>Marker 1</strong>'
}, {
position: {
lat: 47.374592,
lng: 8.548867
},
infoText: '<strong>Marker 2</strong>'
}, {
position: {
lat: 47.379592,
lng: 8.549867
},
infoText: '<strong>Marker 3</strong>'
}]
},
methods: {
toggleInfoWindow: function(marker, idx) {
this.infoWindowPos = marker.position;
this.infoOptions.content = marker.infoText;
//check if its the same marker that was selected if yes toggle
if (this.currentMidx == idx) {
this.infoWinOpen = !this.infoWinOpen;
}
//if different marker set infowindow to open and reset current marker index
else {
this.infoWinOpen = true;
this.currentMidx = idx;
}
}
}
});
});
</script>
</body>