|
|
@@ -8,17 +8,17 @@
|
|
8
|
8
|
<ul>
|
|
9
|
9
|
<li> scroll to location: scroll an autocompleted location into viewport. </li>
|
|
10
|
10
|
<li> clear map: clear route and markers from map. </li>
|
|
11
|
|
- <li> geo-locate: locate user based on geographic location (must be enabled in browser). </li>
|
|
|
11
|
+ <li> geolocate: locate user based on geographic location (must be enabled in browser). </li>
|
|
12
|
12
|
</ul>
|
|
13
|
13
|
<div>
|
|
14
|
14
|
<label>
|
|
15
|
15
|
<gmap-autocomplete @place_changed="setPlace"></gmap-autocomplete>
|
|
16
|
|
- <button @click="gotoPlace">scroll to location</button>
|
|
|
16
|
+ <button @click="gotoPlace(currentPlace)">scroll to location</button>
|
|
|
17
|
+ <button @click="removeMarkers">clear route</button>
|
|
|
18
|
+ <button @click="locateUser">geolocate</button>
|
|
17
|
19
|
</label>
|
|
18
|
20
|
<br/>
|
|
19
|
21
|
</div>
|
|
20
|
|
- <button @click="removeMarkers">clear map</button>
|
|
21
|
|
- <button @click="locateUser">geo-locate</button>
|
|
22
|
22
|
<br>
|
|
23
|
23
|
<gmap-map
|
|
24
|
24
|
@click="addMarker"
|
|
|
@@ -50,12 +50,12 @@
|
|
50
|
50
|
lng: place.geometry.location.lng()
|
|
51
|
51
|
}
|
|
52
|
52
|
},
|
|
53
|
|
- gotoPlace () {
|
|
54
|
|
- this.$refs.gMap.panTo(this.currentPlace)
|
|
|
53
|
+ gotoPlace (location) {
|
|
|
54
|
+ this.$refs.gMap.panTo(location)
|
|
55
|
55
|
},
|
|
56
|
56
|
locateUser () {
|
|
57
|
57
|
navigator.geolocation.getCurrentPosition(position => {
|
|
58
|
|
- this.$refs.gMap.panTo({
|
|
|
58
|
+ this.gotoPlace({
|
|
59
|
59
|
lat: position.coords.latitude,
|
|
60
|
60
|
lng: position.coords.longitude
|
|
61
|
61
|
})
|
|
|
@@ -70,20 +70,20 @@
|
|
70
|
70
|
this.markers[0] = { position: marker }
|
|
71
|
71
|
} else if (this.markers.length >= 1) {
|
|
72
|
72
|
this.markers[1] = { position: marker }
|
|
73
|
|
- this.getRoute(this.markers[0], this.markers[1])
|
|
|
73
|
+ this.setRoute(this.markers[0], this.markers[1])
|
|
74
|
74
|
this.markers[0] = this.markers[1]
|
|
75
|
75
|
}
|
|
76
|
76
|
},
|
|
77
|
77
|
removeMarkers () {
|
|
|
78
|
+ this.clearRoute()
|
|
78
|
79
|
this.markers = []
|
|
79
|
|
- if (this.directionsDisplay) this.directionsDisplay.setMap(null)
|
|
80
|
80
|
},
|
|
81
|
|
- getRoute: function (a, b) {
|
|
82
|
|
- if (this.directionsDisplay) this.directionsDisplay.setMap(null)
|
|
|
81
|
+ setRoute: function (a, b) {
|
|
|
82
|
+ this.clearRoute()
|
|
83
|
83
|
this.directionsService = new google.maps.DirectionsService() // eslint-disable-line no-undef
|
|
84
|
84
|
this.directionsDisplay = new google.maps.DirectionsRenderer({ draggable: true }) // eslint-disable-line no-undef
|
|
85
|
85
|
this.directionsDisplay.setMap(this.$refs.gMap.$mapObject)
|
|
86
|
|
- // ---------------------------------------------------------------
|
|
|
86
|
+ // -------------------------------------------------------
|
|
87
|
87
|
let vm = this
|
|
88
|
88
|
vm.directionsService.route({
|
|
89
|
89
|
origin: a.position,
|
|
|
@@ -96,6 +96,9 @@
|
|
96
|
96
|
alert('Directions request failed due to ' + status)
|
|
97
|
97
|
}
|
|
98
|
98
|
})
|
|
|
99
|
+ },
|
|
|
100
|
+ clearRoute () {
|
|
|
101
|
+ if (this.directionsDisplay) this.directionsDisplay.setMap(null)
|
|
99
|
102
|
}
|
|
100
|
103
|
}
|
|
101
|
104
|
}
|