-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
graph.html
100 lines (85 loc) · 3.37 KB
/
graph.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Graph Visualization with Traffic Details</title>
<style>
body {
font-family: Arial, sans-serif;
background-image: linear-gradient(120deg, #a6c0fe 0%, #f68084 100%);
}
#map {
height: 600px;
border: none;
border-radius: 5px solid black;
}
.dark-popup {
.dark-popup {
background-color: #333;
color: #fff;
padding: 10px;
border: none;
border-radius: 10px;
width: 100px;
height: 150px;
}
}
</style>
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css">
</head>
<body>
<h1><center>Graph Visualization with Traffic Details</center></h1>
<div id="map"></div>
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script>
function initMap() {
var map = L.map('map').setView([0, 0], 1);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Get the graph data from sessionStorage
var graphData = JSON.parse(sessionStorage.getItem('graphData'));
if (graphData && graphData.path) {
var pathCoordinates = graphData.path;
// Add a start point marker with a custom icon
var startPoint = pathCoordinates[0];
var startIcon = L.icon({
iconUrl: 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-green.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
});
var startMarker = L.marker(startPoint, { icon: startIcon }).addTo(map);
startMarker.bindPopup('Start Point').openPopup();
// Add an end point marker
var endPoint = pathCoordinates[pathCoordinates.length - 1];
var endMarker = L.marker(endPoint).addTo(map);
endMarker.bindPopup('End Point').openPopup();
// Create a polyline to represent the graph
var polyline = L.polyline([], { color: 'purple' }).addTo(map);
var index = 0;
var animationInterval = setInterval(function() {
if (index >= pathCoordinates.length) {
clearInterval(animationInterval);
map.fitBounds(polyline.getBounds());
return;
}
// Animate the graph drawing
polyline.addLatLng(pathCoordinates[index]);
map.panTo(pathCoordinates[index]);
index++;
}, 30); // Adjust the animation speed here (lower value means faster)
// Show traffic details as a popup
var trafficDetails = graphData.traffic;
if (trafficDetails) {
var trafficPopup = L.popup({ className: 'dark-popup' })
.setLatLng([0, 0])
.setContent(trafficDetails)
.openOn(map);
}
}
}
initMap();
</script>
</body>
</html>