|
|
@@ -5,7 +5,10 @@
|
|
5
|
5
|
:data="chartData"
|
|
6
|
6
|
:options="chartOptions"
|
|
7
|
7
|
/>
|
|
8
|
|
- <div class="miles">{{ this.miles }}</div>
|
|
|
8
|
+ <div class="miles">
|
|
|
9
|
+ {{ distance }}
|
|
|
10
|
+ {{ unit }}
|
|
|
11
|
+ </div>
|
|
9
|
12
|
</div>
|
|
10
|
13
|
</template>
|
|
11
|
14
|
|
|
|
@@ -18,14 +21,19 @@
|
|
18
|
21
|
props: ['currentRoute'],
|
|
19
|
22
|
watch: {
|
|
20
|
23
|
currentRoute (newRoute) {
|
|
21
|
|
- console.log(newRoute)
|
|
22
|
|
- this.miles = newRoute.legs[0].distance.text
|
|
23
|
|
- this.getPathElevation(newRoute.overview_path)
|
|
|
24
|
+ const calc = newRoute.legs[0].distance.text.split(' ')
|
|
|
25
|
+ this.distance = calc[0]
|
|
|
26
|
+ this.unit = calc[1]
|
|
|
27
|
+ this.route = newRoute
|
|
|
28
|
+ this.getPathElevation()
|
|
24
|
29
|
}
|
|
25
|
30
|
},
|
|
26
|
31
|
data () {
|
|
27
|
32
|
return {
|
|
28
|
|
- miles: null,
|
|
|
33
|
+ route: null,
|
|
|
34
|
+ gradeReport: null,
|
|
|
35
|
+ distance: null,
|
|
|
36
|
+ unit: null,
|
|
29
|
37
|
avgGrade: null,
|
|
30
|
38
|
peakGrade: null,
|
|
31
|
39
|
elevationService: null,
|
|
|
@@ -40,17 +48,18 @@
|
|
40
|
48
|
}
|
|
41
|
49
|
},
|
|
42
|
50
|
methods: {
|
|
43
|
|
- getPathElevation (route) {
|
|
|
51
|
+ getPathElevation () {
|
|
44
|
52
|
this.elevationService = new google.maps.ElevationService() // eslint-disable-line no-undef
|
|
45
|
53
|
this.chartData = [
|
|
46
|
54
|
['', '', { role: 'style' }]
|
|
47
|
55
|
]
|
|
48
|
56
|
this.elevationService.getElevationAlongPath({
|
|
49
|
|
- 'path': route,
|
|
|
57
|
+ 'path': this.route.overview_path,
|
|
50
|
58
|
'samples': 264
|
|
51
|
59
|
}, (elevations, status) => {
|
|
52
|
60
|
if (status === 'OK') {
|
|
53
|
61
|
this.elevations = elevations
|
|
|
62
|
+ this.getGrades()
|
|
54
|
63
|
this.displayPathElevation()
|
|
55
|
64
|
}
|
|
56
|
65
|
})
|
|
|
@@ -64,12 +73,17 @@
|
|
64
|
73
|
: this.chartData.push(['', e.elevation, '#004E64'])
|
|
65
|
74
|
)
|
|
66
|
75
|
},
|
|
67
|
|
- getAverageGrade () {
|
|
68
|
|
- // let avg = 0
|
|
69
|
|
-
|
|
70
|
|
- },
|
|
71
|
|
- getPeakGrade () {
|
|
72
|
|
-
|
|
|
76
|
+ getGrades () {
|
|
|
77
|
+ const interval = (this.distance * 5280) / 264
|
|
|
78
|
+ this.gradeReport = []
|
|
|
79
|
+ for (let i = 0; i < this.elevations.length - 1; i++) {
|
|
|
80
|
+ this.gradeReport.push(
|
|
|
81
|
+ Math.abs(this.elevations[i].elevation - this.elevations[i + 1].elevation) / interval
|
|
|
82
|
+ )
|
|
|
83
|
+ }
|
|
|
84
|
+ console.log(interval)
|
|
|
85
|
+ console.log(this.elevations)
|
|
|
86
|
+ console.log(this.gradeReport)
|
|
73
|
87
|
}
|
|
74
|
88
|
}
|
|
75
|
89
|
}
|