Skip to content

Instantly share code, notes, and snippets.

@mtermoul
Created July 29, 2018 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtermoul/59909499eef0e37a56a8f09a10408f29 to your computer and use it in GitHub Desktop.
Save mtermoul/59909499eef0e37a56a8f09a10408f29 to your computer and use it in GitHub Desktop.
Show Google maps on vue component.
<template>
<div class="map-panel-container elevation-8 brown lighten-4">
<googlemaps-map
ref="map"
class="map"
:center.sync="mapCenter"
:zoom.sync="zoom">
<googlemaps-marker
v-for="marker in mapMarkers"
:key="marker.id"
:title="marker.title"
:animation="marker.animation"
:icon="marker.icon"
:position="marker.position"
@click="onMapMarkerClick(marker.id)"
@mouseover="onMapMarkerMouseOver(marker.id)"
@mouseout="onMapMarkerMouseOut(marker.id)">
</googlemaps-marker>
</googlemaps-map>
</div>
</template>
<script>
import {mapActions} from 'vuex'
import EventBus from '../eventBus'
export default {
data () {
return {
mapCenter: {lat: 0, lng: 0},
zoom: 11,
mapMarkers: null,
...
}
},
computed: {
selectedLocation () {
return this.$store.getters.selectedLocation
},
selectedStore: {
get () {
return this.$store.getters.selectedStore
},
set (value) {
this.updateSelectedStore(value)
}
},
stores () {
return this.$store.getters.stores
},
...
},
watch: {
selectedLocation () {
this.updateMapCenter(this.selectedLocation)
},
selectedStore (newValue, oldValue) {
this.selectMapMarker(oldValue, false)
this.selectMapMarker(newValue, true)
}
},
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment