-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
57 lines (46 loc) · 1.77 KB
/
Copy pathmap.js
File metadata and controls
57 lines (46 loc) · 1.77 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
let init_graph_btn = document.getElementById('init_graph_btn');
init_graph_btn.addEventListener('click', plotInitialGraph);
let shortest_path_btn = document.getElementById('shortest_path_btn');
shortest_path_btn.addEventListener('click', showShortestPath);
function addMarker(coordinate) {
L.marker(coordinate).addTo(myMap);
}
function addPath(p1_coordinate, p2_coordinate, color) {
L.polyline([p1_coordinate, p2_coordinate], { color: color }).addTo(myMap);
}
function addPopup(coordinate, content) {
L.popup()
.setLatLng([coordinate[0]+0.0001, coordinate[1]])
.setContent(content)
.addTo(myMap);
}
function plotInitialGraph() {
const url = 'http://127.0.0.1:5000/initial_graph'
fetch(url)
.then(response => response.json())
.then(data => {
Object.keys(data).forEach(key => {
addMarker(data[key]['coordinate']);
addPopup(data[key]['coordinate'], key);
Object.keys(data[key]['neighbors']).forEach(neighbor_index => {
addPath(data[key]['coordinate'], data[key]['neighbors'][neighbor_index], 'blue');
});
});
})
}
function showShortestPath() {
const url = 'http://127.0.0.1:5000/shortest_path'
fetch(url)
.then(response => response.json())
.then(data => {
let first_vertex_pointer = 0;
let second_vertex_pointer = 1;
while (second_vertex_pointer < data.length) {
const first_vertex = data[first_vertex_pointer];
const second_vertex = data[second_vertex_pointer];
addPath(first_vertex, second_vertex, 'red');
first_vertex_pointer++;
second_vertex_pointer++;
}
})
}