-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
270 lines (230 loc) · 8.21 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<head>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="javascript/dijkstra.js" type="text/javascript"></script>
<script src="javascript/distanceCalc.js" type="text/javascript"></script>
<script src="javascript/mapParsing.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/styling.css">
</head>
<title>DH-405 Project</title>
<style>
body {
width: 45em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
<body>
<div>
<h1>DH-405 Shortest-Path Route Extraction</h1>
<p>Routing demo between intersections extracted from a map of New York (1829)</p>
</div>
<section class="container">
<div class="mapDiv" id="mapDiv"></div>
<div class="infoDiv">
<h3> Distance Calculator </h3>
<p id="coordinates" class="infoText"></p>
<p id="distance" class="infoText"></p>
<p id="humanWalk" class="infoText"></p>
<p id="horseWalk" class="infoText"></p>
<p id="horseTrot" class="infoText"></p>
<p id="totalDistance" class="infoText"></p>
<p id="placeholder"><br>Select start and end points on the map to show the shortest paths</p>
<div class="tooltip">Speed Assumptions
<span class="tooltiptext">
We make the following assumptions about travel speed:<br>
<br>
Human walking speed is <b>1.4 m/s</b> <br>
Horse walking speed is <b>1.9 m/s</b> <br>
Horse trotting speed is <b>3.6 m/s</b> <br>
</span>
</div>
<p id="warning">Max # of destinations reached</p>
</div>
<button id="clearPaths" onclick="clearPaths()">Clear Paths</button>
<button id="toggleNetwork" onclick="toggleNetwork(this)">Show Network</button>
<p id="credits">Project created by:<br>Jonathan Donas & Florian Buchner</p>
</section>
<script>
/////////////////////////////// Plotly ///////////////////////////////
infoVisible(false);
// Plot the edges
var edgeTrace = {
visible: false,
x: edgesX,
y: edgesY,
line: {
width: 1,
color: '#e1e1e1'
},
hoverinfo: 'none',
mode: 'lines'
};
// Plot the nodes
var nodeTrace = {
x: nodesX,
y: nodesY,
text: nodeNames,
mode: 'markers',
hoverinfo: 'text',
marker: {
color: 'white',
size: 5,
opacity: 0
}
};
var myPlot = document.getElementById('mapDiv');
var data = [edgeTrace, nodeTrace];
var layout = {
showlegend: false,
hovermode: 'closest',
margin: {
b: 0,
l: 0,
r: 0,
t: 0
},
xaxis: {
showgrid: false,
zeroline: false,
showticklabels: false,
fixedrange: true,
},
yaxis: {
showgrid: false,
zeroline: false,
showticklabels: false,
fixedrange: true
},
// Background image of the map
images: [{
'source': backgroundImage,
'sizing': 'stretch',
'xref': 'paper',
'yref': 'paper',
'x': -0.073,
'y': 1.000,
'layer': 'below',
'sizex': 1.173,
'sizey': 1.017,
'opacity': 1
}]
};
Plotly.newPlot('mapDiv', data, layout, {
displayModeBar: false
});
// Keep track of extra traces that are displayed
var lastNodeName = null;
var nodesDrawnX = [];
var nodesDrawnY = [];
var tracesAdded = 0;
// Action for when a node is clicked on
myPlot.on('plotly_click', function(data) {
if (tracesAdded == 5) {
warningId = document.getElementById("warning")
warningId.style.visibility = "visible";
setTimeout(function() {
warningId.style.visibility = "hidden";
}, 3000);
return;
}
var x = data.points[0].x;
var y = data.points[0].y;
var nodeName = coordsToName([x, y]);
var newNodeTrace = {
x: [],
y: [],
mode: 'markers',
hoverinfo: 'none',
marker: {
color: '#2a2a2a',
size: 13
}
};
if (lastNodeName == null) {
// Draw the starting node
newNodeTrace.x = [x];
newNodeTrace.y = [y]
nodesDrawnX = [x];
nodesDrawnY = [y];
Plotly.addTraces('mapDiv', newNodeTrace)
infoUpdate(nodeName, null, distance);
infoVisible(true);
} else {
// Draw the path to the next node
var path = Dijkstra(paths, lastNodeName, nodeName);
// In case of no path, return rather than crash
if (path == null)
return;
var Xs = [];
var Ys = [];
for (var i = 0; i < path.length; i++) {
var nodeCoords = nameToCoords(path[i]);
Xs.push(nodeCoords[0]);
Ys.push(nodeCoords[1]);
}
var newEdgeTrace = {
x: Xs,
y: Ys,
line: {
width: 5,
color: '#4a80f5'
},
hoverinfo: 'none',
mode: 'lines'
};
// Remove the trace that draws endpoint nodes, then re-add so it appears on top
var endNodeCoords = nameToCoords(path[path.length - 1]);
nodesDrawnX.push(endNodeCoords[0]);
nodesDrawnY.push(endNodeCoords[1]);
newNodeTrace.x = nodesDrawnX;
newNodeTrace.y = nodesDrawnY;
// Draw the new path
var newTraces = [newEdgeTrace, newNodeTrace];
Plotly.addTraces('mapDiv', newTraces);
Plotly.deleteTraces('mapDiv', -3);
// Show the real-world distance between two points
var distance = getDistanceMetres(path);
infoUpdate(lastNodeName, nodeName, distance);
}
lastNodeName = nodeName;
tracesAdded++;
});
// Action to clear the map
function clearPaths() {
if (tracesAdded == 0) {
return;
}
var tracesToDelete = [];
for (var i = 0 - tracesAdded; i < 0; i++) {
tracesToDelete.push(i);
}
Plotly.deleteTraces('mapDiv', tracesToDelete);
lastNodeName = null;
nodesDrawnX = [];
nodesDrawnY = [];
tracesAdded = 0;
infoVisible(false);
}
// Toggles if the network is visible
var networkVisible = false;
function toggleNetwork(button) {
var newData;
if (networkVisible) {
button.innerHTML = "Show Network";
newData = {
'visible': [false, undefined],
'marker.opacity': [undefined, 0]
};
} else {
button.innerHTML = "Hide Network";
newData = {
'visible': [true, undefined],
'marker.opacity': [undefined, 0.8]
};
}
Plotly.restyle('mapDiv', newData, [0, 1]);
networkVisible = !networkVisible;
}
</script>
</body>