forked from schoenfr/gn-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgn-api.html
More file actions
117 lines (100 loc) · 2.63 KB
/
Copy pathgn-api.html
File metadata and controls
117 lines (100 loc) · 2.63 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-ajax/iron-ajax.html">
<!--
//TODO: Description
@demo demo/index.html
-->
<dom-module id="gn-api">
<template>
<iron-ajax
auto
url="https://greennav.isp.uni-luebeck.de/greennav/vehicles"
handle-as="json"
last-response="{{ vehicles }}"></iron-ajax>
<iron-ajax
auto
id="route"
handle-as="json"
last-response="{{ route }}"></iron-ajax>
<iron-ajax
auto
id="range"
handle-as="json"
last-response="{{ range }}"></iron-ajax>
</template>
<script>
Polymer({
is: 'gn-api',
properties: {
/**
* List of available vehicles obtained from the backend
*/
vehicles: {
type: Array,
notify: true
},
/**
* Set the vehicle to route with. Needed for route and range
* calculation.
*
* Possible values are listed in the vehicles variable
*/
vehicle: String,
/**
* Route/range start as OSM-ID
*/
startOsmId: Number,
/**
* Route target as OSM-ID
*/
targetOsmId: Number,
/**
* Battery load percentage.
* Can be any value from 100 to 0
*/
battery: Number,
/**
* Result of the routing. Needs vehicle, startOsmId,
* targetOsmId and battery to be defined. It's not
* calculated automatically, call getRoute() first!
*/
route: {
type: Object,
notify: true
},
/**
* Result of the range. Needs vehicle, startOsmId
* and battery to be defined. It's not
* calculated automatically, call getRange() first!
*/
range: {
type: Object,
notify: true
}
},
/**
* Sets the route variable
*/
getRoute : function() {
var ajax = document.querySelector('#route');
ajax.url = "https://greennav.isp.uni-luebeck.de/greennav/" +
"vehicles/" + this.vehicle +
"/routes/" + this.startOsmId * 100 +
"-" + this.targetOsmId * 100 +
"/opt/energy" +
"?battery=" + this.battery +
"&algorithm=EnergyAStar";
},
/**
* Sets the range variable
*/
getRange : function() {
var ajax = document.querySelector('#range');
ajax.url = "https://greennav.isp.uni-luebeck.de/greennav/" +
"vehicles/" + this.vehicle +
"/ranges/" + this.startOsmId * 100 +
"?battery=" + this.battery;
}
});
</script>
</dom-module>