-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
180 lines (162 loc) · 5.42 KB
/
index.html
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Best Project on this Subject Ever!</title>
</head>
<body>
<div>
<span style="background-color: #ff0000">WALK</span>
<span style="background-color: #0000ff">METRO</span>
<span style="background-color: #00ff00">BUS</span>
</div>
<div id="map" style="height: 600px;width: 80%; margin-left: 0"></div>
<div style="display: flex;margin: auto">
<div>
<div>
Fastest:
<button id="d">Dijkstra</button>
<button id="a">AStar</button>
<button id="alt">ALT</button>
<button id="gt">Genetic Time</button>
</div>
<div style="margin-top: 10px">
Cheapest:
<button id="gp">Genetic Price</button>
</div>
</div>
<div style="display: flex;margin: auto;flex-direction: column">
<div>
Price: <span id="price"></span>€
</div>
<div>
Time: <span id="time"></span>
</div>
<div>
Alg Time: <span id="alg_time"></span>ms
</div>
</div>
</div>
<script crossorigin=""
integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ=="
src="https://unpkg.com/leaflet@1.8.0/dist/leaflet.js"></script>
<link crossorigin="" href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css"
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
rel="stylesheet"/>
<script>
let map = L.map('map').setView([38.02503, -8.558739], 12);
let tiles = L.tileLayer('http://localhost:8000/{z}/{x}/{y}.png', {
maxZoom: 20,
attribution: '© OpenStreetMap',
}).addTo(map);
let first = null
let last = null
let firstPoint = null
let lastPoint = null
let LeafIcon = L.Icon.extend({
options: {
iconSize: [38, 95],
shadowSize: [50, 64],
iconAnchor: [22, 94],
shadowAnchor: [4, 62],
popupAnchor: [-3, -76]
}
})
let redIcon = new LeafIcon({
iconUrl: 'img/red.png',
})
let greenIcon = new LeafIcon({
iconUrl: 'img/green.png',
})
map.on('click', function(e) {
var popLocation= e.latlng;
console.log(e.latlng)
if (first != null && last != null){
first = null
last = null
map.removeLayer(firstPoint);
map.removeLayer(lastPoint);
}
if (first == null){
first = e.latlng
firstPoint = L.marker(first, {icon: greenIcon})
.addTo(map)
.bindPopup("Start");
}
else if (last == null){
last = e.latlng
lastPoint = L.marker(last, {icon: redIcon})
.addTo(map)
.bindPopup("Destination");
}
});
function sendRequest(coordsS,coordsD,method){
var myHeaders = new Headers();
var myInit = { method: 'GET',
headers: myHeaders,
cache: 'default' };
console.log(coordsS,coordsD)
fetch('http://localhost:8085/?method='+method+'&slat='+coordsS.lat+"&slon="+coordsS.lng+"&dlat="+coordsD.lat+"&dlon="+coordsD.lng,myInit)
.then((response) => {
return response.json()
}).then((response)=>{
sessionStorage.setItem("price",response["price"])
sessionStorage.setItem("time",response["time"])
sessionStorage.setItem("alg_time",response["alg_time"])
location.reload()
})
}
let d = document.getElementById("d")
let a = document.getElementById("a")
let alt = document.getElementById("alt")
let gt = document.getElementById("gt")
let gp = document.getElementById("gp")
let price = document.getElementById("price")
let time = document.getElementById("time")
let alg_time = document.getElementById("alg_time")
load_labels("price",price)
load_labels("time",time)
load_labels("alg_time",alg_time)
register_button(d,"d")
register_button(a,"a")
register_button(alt,"alt")
register_button(gt,"gt")
register_button(gp,"gp")
function register_button(elem,method){
if (elem){
elem.addEventListener("click",() =>{
if (first == null || last == null){
alert("Please Select the Start and Ending Points")
}
sendRequest(first,last,method)
})
}
}
function load_labels(key,elem){
elem.innerText = sessionStorage.getItem(key)
}
function setCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
</script>
</body>
</html>