-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathmap.html
More file actions
214 lines (181 loc) · 6.71 KB
/
map.html
File metadata and controls
214 lines (181 loc) · 6.71 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GPS Tracking Map</title>
<!-- Leaflet CSS -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
}
.header {
background-color: #2c3e50;
color: white;
padding: 20px;
text-align: center;
}
h1 {
margin: 0;
font-size: 24px;
}
.info-panel {
background-color: white;
padding: 15px;
margin: 10px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
#map {
height: 600px;
margin: 10px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.legend {
background-color: white;
padding: 10px;
margin: 10px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.legend-item {
display: flex;
align-items: center;
margin: 5px 0;
}
.legend-marker {
width: 20px;
height: 20px;
border-radius: 50%;
margin-right: 10px;
}
.speed-low { background-color: #27ae60; }
.speed-medium { background-color: #f39c12; }
.speed-high { background-color: #e74c3c; }
</style>
</head>
<body>
<div class="header">
<h1>GPS Tracking Map</h1>
</div>
<div class="info-panel">
<p><strong>Total Points:</strong> <span id="pointCount">0</span></p>
<p><strong>Route Distance:</strong> Approximately <span id="distance">0</span> meters</p>
</div>
<div id="map"></div>
<div class="legend">
<h3>Speed Legend</h3>
<div class="legend-item">
<div class="legend-marker speed-low"></div>
<span>Low Speed (< 18)</span>
</div>
<div class="legend-item">
<div class="legend-marker speed-medium"></div>
<span>Medium Speed (18-20)</span>
</div>
<div class="legend-item">
<div class="legend-marker speed-high"></div>
<span>High Speed (> 20)</span>
</div>
</div>
<!-- Leaflet JS -->
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="./output.json"></script>
<script>
// Calculate center of all points
const centerLat = data.reduce((sum, point) => sum + point.latitude, 0) / data.length;
const centerLng = data.reduce((sum, point) => sum + point.longitude, 0) / data.length;
// Initialize map
const map = L.map('map').setView([centerLat, centerLng], 14);
// Add OpenStreetMap tiles
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors',
maxZoom: 19
}).addTo(map);
// Function to get marker color based on speed
function getMarkerColor(speed) {
if (speed < 18) return '#27ae60'; // Green
if (speed <= 20) return '#f39c12'; // Orange
return '#e74c3c'; // Red
}
// Function to extract speed from info string
function extractSpeed(infoString) {
const match = infoString.match(/Speed = (\d+)/);
return match ? parseInt(match[1]) : 0;
}
// Create custom icon function
function createCustomIcon(color) {
return L.divIcon({
className: 'custom-marker',
html: `<div style="background-color: ${color}; width: 24px; height: 24px; border-radius: 50%; border: 3px solid white; box-shadow: 0 2px 4px rgba(0,0,0,0.3);"></div>`,
iconSize: [24, 24],
iconAnchor: [12, 12]
});
}
// Add markers and create polyline
const latLngs = [];
data.forEach((point, index) => {
const speed = extractSpeed(point.info);
const color = getMarkerColor(speed);
const icon = createCustomIcon(color);
const marker = L.marker([point.latitude, point.longitude], { icon: icon })
.addTo(map)
.bindPopup(`
<div style="text-align: center;">
<strong>Point ${index + 1}</strong><br>
${point.info}<br>
<small>Lat: ${point.latitude.toFixed(6)}<br>
Lng: ${point.longitude.toFixed(6)}</small>
</div>
`);
latLngs.push([point.latitude, point.longitude]);
});
// Draw route line
if (latLngs.length > 1) {
L.polyline(latLngs, {
color: '#3498db',
weight: 3,
opacity: 0.7,
dashArray: '10, 5'
}).addTo(map);
}
// Calculate approximate distance
function calculateDistance(lat1, lon1, lat2, lon2) {
const R = 6371e3; // Earth's radius in meters
const φ1 = lat1 * Math.PI / 180;
const φ2 = lat2 * Math.PI / 180;
const Δφ = (lat2 - lat1) * Math.PI / 180;
const Δλ = (lon2 - lon1) * Math.PI / 180;
const a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
Math.cos(φ1) * Math.cos(φ2) *
Math.sin(Δλ/2) * Math.sin(Δλ/2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return R * c;
}
let totalDistance = 0;
for (let i = 0; i < data.length - 1; i++) {
totalDistance += calculateDistance(
data[i].latitude,
data[i].longitude,
data[i + 1].latitude,
data[i + 1].longitude
);
}
// Update info panel
document.getElementById('pointCount').textContent = data.length;
document.getElementById('distance').textContent = totalDistance.toFixed(0);
// Fit map to show all markers
if (latLngs.length > 0) {
map.fitBounds(latLngs, { padding: [50, 50] });
}
</script>
</body>
</html>