Spaces:
Sleeping
Sleeping
File size: 14,572 Bytes
6740714 | 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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🚁 DroneAgent - Waypoint Editor</title>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.container {
display: flex;
height: 100vh;
}
.sidebar {
width: 350px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
padding: 20px;
overflow-y: auto;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}
.map-container {
flex: 1;
position: relative;
}
#map {
height: 100%;
width: 100%;
}
.header {
background: rgba(255, 255, 255, 0.2);
padding: 15px;
border-radius: 10px;
margin-bottom: 20px;
text-align: center;
}
.waypoint-item {
background: rgba(255, 255, 255, 0.1);
padding: 10px;
margin: 8px 0;
border-radius: 8px;
border-left: 4px solid #4CAF50;
cursor: pointer;
transition: all 0.3s ease;
}
.waypoint-item:hover {
background: rgba(255, 255, 255, 0.2);
transform: translateX(5px);
}
.waypoint-item.active {
background: rgba(76, 175, 80, 0.3);
border-left-color: #4CAF50;
}
.btn {
background: linear-gradient(45deg, #4CAF50, #45a049);
color: white;
border: none;
padding: 12px 20px;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
font-weight: bold;
transition: all 0.3s ease;
width: 100%;
margin: 8px 0;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(76, 175, 80, 0.3);
}
.btn:disabled {
background: #666;
cursor: not-allowed;
transform: none;
}
.status {
padding: 10px;
border-radius: 8px;
margin: 10px 0;
font-weight: bold;
}
.status.success {
background: rgba(76, 175, 80, 0.2);
border-left: 4px solid #4CAF50;
}
.status.error {
background: rgba(244, 67, 54, 0.2);
border-left: 4px solid #f44336;
}
.status.info {
background: rgba(33, 150, 243, 0.2);
border-left: 4px solid #2196F3;
}
.coordinate-display {
font-family: 'Courier New', monospace;
background: rgba(0, 0, 0, 0.2);
padding: 8px;
border-radius: 4px;
margin: 5px 0;
font-size: 12px;
}
.loading {
display: inline-block;
width: 20px;
height: 20px;
border: 3px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: white;
animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="container">
<div class="sidebar">
<div class="header">
<h2>🚁 Waypoint Editor</h2>
<p>Edit mission waypoints on the map</p>
</div>
<div id="status" class="status info">
Click "Load Mission" to get started
</div>
<button id="loadBtn" class="btn">📥 Load Mission Waypoints</button>
<button id="saveBtn" class="btn" disabled>💾 Confirm Flight with Edited Waypoints</button>
<button id="resetBtn" class="btn" disabled>🔄 Reset Changes</button>
<div id="waypointsList">
<!-- Waypoints will be loaded here -->
</div>
<div id="coordinatesDisplay" style="margin-top: 20px;">
<!-- Coordinate details will be shown here -->
</div>
</div>
<div class="map-container">
<div id="map"></div>
</div>
</div>
<script>
// Initialize map
const map = L.map('map').setView([16.047, 108.206], 15);
// Add OpenStreetMap tiles
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Store waypoints and markers
let waypoints = [];
let markers = [];
let originalWaypoints = [];
let selectedWaypointIndex = -1;
// API functions
async function loadWaypoints() {
try {
updateStatus('Loading waypoints...', 'info');
showLoading(true, 'loadBtn');
const response = await fetch('/mission/waypoints');
const data = await response.json();
if (data.status === 'success') {
waypoints = data.waypoints;
originalWaypoints = JSON.parse(JSON.stringify(waypoints)); // Deep copy
displayWaypoints();
updateMapMarkers();
updateStatus(`✅ Loaded ${waypoints.length} waypoints`, 'success');
document.getElementById('saveBtn').disabled = false;
document.getElementById('resetBtn').disabled = false;
} else {
updateStatus(`❌ ${data.message}`, 'error');
}
} catch (error) {
updateStatus(`❌ Error loading waypoints: ${error.message}`, 'error');
} finally {
showLoading(false, 'loadBtn');
}
}
async function confirmFlight() {
try {
updateStatus('Confirming flight...', 'info');
showLoading(true, 'saveBtn');
const confirmData = {
mission_id: `edited_mission_${Date.now()}`,
drone_id: 'drone_001',
waypoints: waypoints,
altitude: 70.0
};
const response = await fetch('/flight/confirm', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(confirmData)
});
const data = await response.json();
if (data.status === 'confirmed' || response.ok) {
updateStatus('✅ Flight confirmed with edited waypoints!', 'success');
alert('🎉 Flight confirmed successfully!\n\nYour edited waypoints have been saved and the flight mission is ready.');
} else {
updateStatus(`❌ Confirmation failed: ${data.message}`, 'error');
}
} catch (error) {
updateStatus(`❌ Error confirming flight: ${error.message}`, 'error');
} finally {
showLoading(false, 'saveBtn');
}
}
function resetChanges() {
waypoints = JSON.parse(JSON.stringify(originalWaypoints));
displayWaypoints();
updateMapMarkers();
updateStatus('🔄 Changes reset to original waypoints', 'info');
}
function displayWaypoints() {
const list = document.getElementById('waypointsList');
list.innerHTML = '<h3>📍 Waypoints</h3>';
waypoints.forEach((wp, index) => {
const item = document.createElement('div');
item.className = 'waypoint-item';
item.onclick = () => selectWaypoint(index);
const latDiff = originalWaypoints[index] ?
(wp.lat - originalWaypoints[index].lat).toFixed(6) : '0.000000';
const lngDiff = originalWaypoints[index] ?
(wp.lng - originalWaypoints[index].lng).toFixed(6) : '0.000000';
const hasChanged = Math.abs(latDiff) > 0.000001 || Math.abs(lngDiff) > 0.000001;
item.innerHTML = `
<strong>Waypoint ${index + 1}</strong><br>
<div class="coordinate-display">
Lat: ${wp.lat.toFixed(8)}<br>
Lng: ${wp.lng.toFixed(8)}
</div>
${hasChanged ? '<small style="color: #FFC107;">✏️ Modified</small>' : '<small style="color: #4CAF50;">✅ Original</small>'}
`;
list.appendChild(item);
});
}
function selectWaypoint(index) {
selectedWaypointIndex = index;
// Update UI
document.querySelectorAll('.waypoint-item').forEach((item, i) => {
item.classList.toggle('active', i === index);
});
// Pan map to selected waypoint
if (waypoints[index]) {
map.setView([waypoints[index].lat, waypoints[index].lng], 18);
}
updateCoordinateDisplay();
}
function updateCoordinateDisplay() {
const display = document.getElementById('coordinatesDisplay');
if (selectedWaypointIndex >= 0 && waypoints[selectedWaypointIndex]) {
const wp = waypoints[selectedWaypointIndex];
const original = originalWaypoints[selectedWaypointIndex];
display.innerHTML = `
<h4>🎯 Selected Waypoint ${selectedWaypointIndex + 1}</h4>
<div class="coordinate-display">
<strong>Current:</strong><br>
Latitude: ${wp.lat}<br>
Longitude: ${wp.lng}
</div>
${original ? `
<div class="coordinate-display">
<strong>Original:</strong><br>
Latitude: ${original.lat}<br>
Longitude: ${original.lng}
</div>
<div class="coordinate-display">
<strong>Difference:</strong><br>
Lat: ${(wp.lat - original.lat).toFixed(8)}<br>
Lng: ${(wp.lng - original.lng).toFixed(8)}
</div>
` : ''}
`;
} else {
display.innerHTML = '<p style="color: #999;">Click a waypoint to see details</p>';
}
}
function updateMapMarkers() {
// Clear existing markers
markers.forEach(marker => map.removeLayer(marker));
markers = [];
// Add new markers
waypoints.forEach((wp, index) => {
const marker = L.marker([wp.lat, wp.lng], {
draggable: true,
title: `Waypoint ${index + 1}`
});
// Create custom icon with waypoint number
const customIcon = L.divIcon({
className: 'waypoint-marker',
html: `<div style="
background: #4CAF50;
color: white;
border-radius: 50%;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
border: 2px solid white;
box-shadow: 0 2px 5px rgba(0,0,0,0.3);
">${index + 1}</div>`,
iconSize: [30, 30],
iconAnchor: [15, 15]
});
marker.setIcon(customIcon);
// Handle drag events
marker.on('dragend', function(event) {
const newPos = event.target.getLatLng();
waypoints[index] = {
lat: newPos.lat,
lng: newPos.lng
};
displayWaypoints();
updateCoordinateDisplay();
updateStatus('📍 Waypoint moved - click Save to confirm', 'info');
});
marker.addTo(map);
markers.push(marker);
});
// Fit map to show all waypoints
if (waypoints.length > 0) {
const bounds = L.latLngBounds(waypoints.map(wp => [wp.lat, wp.lng]));
map.fitBounds(bounds, { padding: [20, 20] });
}
}
function updateStatus(message, type) {
const status = document.getElementById('status');
status.textContent = message;
status.className = `status ${type}`;
}
function showLoading(show, buttonId) {
const button = document.getElementById(buttonId);
const loading = button.querySelector('.loading');
if (show) {
if (!loading) {
button.innerHTML = '<div class="loading"></div> Loading...';
}
button.disabled = true;
} else {
if (loading) {
button.innerHTML = button.innerHTML.replace('<div class="loading"></div> Loading...', button.textContent);
}
button.disabled = false;
}
}
// Event listeners
document.getElementById('loadBtn').addEventListener('click', loadWaypoints);
document.getElementById('saveBtn').addEventListener('click', confirmFlight);
document.getElementById('resetBtn').addEventListener('click', resetChanges);
// Initialize
updateStatus('🚁 Welcome to Waypoint Editor! Click "Load Mission" to get started.', 'info');
</script>
</body>
</html>
|