Ver código fonte

adding route change emit

Jared Norris 8 anos atrás
pai
commit
1d1bacc474

+ 3
- 2
VueApp/src/components/ElevationGraph.vue Ver arquivo

@@ -14,6 +14,7 @@
14 14
         components: { GChart },
15 15
         data () {
16 16
           return {
17
+            currentRoute: null,
17 18
             elevationService: null,
18 19
             chartData: [],
19 20
             chartOptions: {
@@ -24,11 +25,11 @@
24 25
           }
25 26
         },
26 27
         methods: {
27
-          getPathElevation (path) {
28
+          getPathElevation (currentRoute) {
28 29
             this.chartData = []
29 30
             this.elevationService = new google.maps.ElevationService() // eslint-disable-line no-undef
30 31
             this.elevationService.getElevationAlongPath({
31
-              'path': path,
32
+              'path': currentRoute,
32 33
               'samples': 256
33 34
             }, function (elevations, status) {
34 35
                if (status === 'OK') {

+ 7
- 1
VueApp/src/components/GoogleMap.vue Ver arquivo

@@ -16,6 +16,7 @@
16 16
         <button @click="gotoPlace(currentPlace)">scroll to location</button>
17 17
         <button @click="removeMarkers">clear route</button>
18 18
         <button @click="locateUser">geolocate</button>
19
+        <button @click="emitRoute">calculate elevation</button>
19 20
       </label>
20 21
       <br/>
21 22
     </div>
@@ -40,7 +41,8 @@
40 41
         markers: [],
41 42
         currentPlace: null,
42 43
         directionsService: null,
43
-        directionsDisplay: null
44
+        directionsDisplay: null,
45
+        currentRoute: null
44 46
       }
45 47
     },
46 48
     methods: {
@@ -92,6 +94,7 @@
92 94
         }, function (response, status) {
93 95
           if (status === 'OK') {
94 96
             vm.directionsDisplay.setDirections(response)
97
+            this.currentRoute = response
95 98
           } else {
96 99
             alert('Directions request failed due to ' + status)
97 100
           }
@@ -99,6 +102,9 @@
99 102
       },
100 103
       clearRoute () {
101 104
         if (this.directionsDisplay) this.directionsDisplay.setMap(null)
105
+      },
106
+      emitRoute () {
107
+        if (this.currentRoute) this.$emit('currentRoute', this.currentRoute)
102 108
       }
103 109
     }
104 110
   }