f5d92f1d36
Major Features: - Multi-format GPS data import (Wigle CSV, GPS JSON, filename GPS) - Data source tracking (test/mock/production) - Database cleanup tools for managing test data - JSON file persistence for simplified server - UI improvements for map controls Backend: - Added wardriving_importer.py with WigleCSVImporter, GPSJSONImporter, BatchImporter - Added data_source and session_id tracking to captures - New API endpoints: DELETE /api/v1/admin/cleanup - Auto-save/load functionality for captures_simple.json - Updated stats endpoint to show data source breakdown CLI Tools: - scripts/import_wardriving_data.py - Batch import with --data-source flag - scripts/cleanup_database.py - Clean by source, session, or all - scripts/create_test_dataset.py - Generate GPS-tagged test data - scripts/test_wardriving_import.py - Test suite for importers Frontend: - Fixed map controls z-index and positioning issues - Moved controls to top-right to avoid zoom button overlap - Fixed Leaflet zoom controls rendering over header - Changed controls to position:fixed for persistent visibility - Export map object to window.map for proper invalidateSize Documentation: - docs/WARDRIVING_IMPORT.md - Complete import guide - docs/DATA_CLEANUP_GUIDE.md - Cleanup system documentation - docs/TEST_LOCATIONS.md - Test GPS coordinates reference - TEST_RESULTS_SUMMARY.md - Format testing results Test Data: - Created test_dataset_gps with 15 captures across 5 US cities - All test data marked with data_source="test" for easy cleanup Testing: - Verified Wigle CSV import (1 capture from West LA) - Verified GPS filename import (3 captures from UCLA area) - Verified GPS JSON companion files (15 captures, 5 cities) - Verified cleanup functionality (deleted 15 test captures) - Verified data persistence across server restarts 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
209 lines
6.0 KiB
JavaScript
209 lines
6.0 KiB
JavaScript
// GigLez - Map Visualization
|
|
|
|
let map;
|
|
let markerLayer;
|
|
let markerClusterGroup;
|
|
let capturesData = [];
|
|
|
|
// Frequency color mapping
|
|
const FREQUENCY_COLORS = {
|
|
315: '#10b981', // Green
|
|
433: '#3b82f6', // Blue
|
|
868: '#f59e0b', // Orange
|
|
915: '#ef4444', // Red
|
|
default: '#6b7280' // Gray
|
|
};
|
|
|
|
// Initialize map
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
initMap();
|
|
loadCaptures();
|
|
setupMapControls();
|
|
});
|
|
|
|
function initMap() {
|
|
// Create map centered on US
|
|
map = L.map('map').setView([39.8283, -98.5795], 4);
|
|
|
|
// Add OpenStreetMap tiles
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
|
maxZoom: 19
|
|
}).addTo(map);
|
|
|
|
// Create marker cluster group
|
|
markerClusterGroup = L.markerClusterGroup({
|
|
maxClusterRadius: 50,
|
|
spiderfyOnMaxZoom: true,
|
|
showCoverageOnHover: false,
|
|
zoomToBoundsOnClick: true
|
|
});
|
|
|
|
// Create regular marker layer
|
|
markerLayer = L.layerGroup();
|
|
|
|
// Add cluster group by default
|
|
map.addLayer(markerClusterGroup);
|
|
|
|
// Export map to window for access from other modules
|
|
window.map = map;
|
|
}
|
|
|
|
function setupMapControls() {
|
|
// Cluster toggle
|
|
document.getElementById('cluster-toggle').addEventListener('change', (e) => {
|
|
if (e.target.checked) {
|
|
map.removeLayer(markerLayer);
|
|
map.addLayer(markerClusterGroup);
|
|
} else {
|
|
map.removeLayer(markerClusterGroup);
|
|
map.addLayer(markerLayer);
|
|
}
|
|
renderMarkers();
|
|
});
|
|
|
|
// Frequency filter
|
|
document.getElementById('frequency-filter').addEventListener('change', () => {
|
|
renderMarkers();
|
|
});
|
|
|
|
// Heatmap toggle (placeholder)
|
|
document.getElementById('heatmap-toggle').addEventListener('change', (e) => {
|
|
if (e.target.checked) {
|
|
alert('Heatmap view coming soon!');
|
|
e.target.checked = false;
|
|
}
|
|
});
|
|
}
|
|
|
|
async function loadCaptures() {
|
|
try {
|
|
const response = await fetch('/api/v1/query/captures?limit=1000');
|
|
|
|
if (!response.ok) {
|
|
console.error('Failed to load captures');
|
|
return;
|
|
}
|
|
|
|
const data = await response.json();
|
|
capturesData = data.captures || [];
|
|
|
|
renderMarkers();
|
|
updateStats();
|
|
|
|
} catch (error) {
|
|
console.error('Error loading captures:', error);
|
|
}
|
|
}
|
|
|
|
function renderMarkers() {
|
|
// Clear existing markers
|
|
markerClusterGroup.clearLayers();
|
|
markerLayer.clearLayers();
|
|
|
|
// Get frequency filter
|
|
const frequencyFilter = document.getElementById('frequency-filter').value;
|
|
|
|
// Filter captures
|
|
let filtered = capturesData;
|
|
|
|
if (frequencyFilter) {
|
|
const targetFreq = parseInt(frequencyFilter) * 1e6;
|
|
filtered = capturesData.filter(c => {
|
|
const freq = c.frequency / 1e6;
|
|
return Math.abs(freq - parseInt(frequencyFilter)) < 50;
|
|
});
|
|
}
|
|
|
|
// Create markers
|
|
filtered.forEach(capture => {
|
|
const marker = createMarker(capture);
|
|
|
|
// Add to both layers (only one will be visible)
|
|
markerClusterGroup.addLayer(marker);
|
|
markerLayer.addLayer(marker);
|
|
});
|
|
|
|
// Update count
|
|
document.getElementById('total-captures').textContent = filtered.length;
|
|
}
|
|
|
|
function createMarker(capture) {
|
|
// Determine color based on frequency
|
|
const freqMHz = Math.round(capture.frequency / 1e6);
|
|
let color = FREQUENCY_COLORS.default;
|
|
|
|
for (const [freq, col] of Object.entries(FREQUENCY_COLORS)) {
|
|
if (freq === 'default') continue;
|
|
if (Math.abs(freqMHz - parseInt(freq)) < 50) {
|
|
color = col;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Create custom icon
|
|
const icon = L.divIcon({
|
|
className: 'custom-marker',
|
|
html: `<div style="background-color: ${color}; width: 12px; height: 12px; border-radius: 50%; border: 2px solid white; box-shadow: 0 0 4px rgba(0,0,0,0.3);"></div>`,
|
|
iconSize: [12, 12],
|
|
iconAnchor: [6, 6]
|
|
});
|
|
|
|
// Create marker
|
|
const marker = L.marker([capture.latitude, capture.longitude], { icon });
|
|
|
|
// Create popup
|
|
const popupContent = createPopupContent(capture);
|
|
marker.bindPopup(popupContent);
|
|
|
|
return marker;
|
|
}
|
|
|
|
function createPopupContent(capture) {
|
|
const freqMHz = (capture.frequency / 1e6).toFixed(2);
|
|
const date = new Date(capture.captured_at).toLocaleDateString();
|
|
|
|
let deviceInfo = 'Unknown Device';
|
|
if (capture.device_name) {
|
|
deviceInfo = `<strong>${capture.device_name}</strong>`;
|
|
if (capture.match_confidence) {
|
|
deviceInfo += ` (${(capture.match_confidence * 100).toFixed(0)}% confidence)`;
|
|
}
|
|
}
|
|
|
|
return `
|
|
<div class="marker-popup">
|
|
<h4>${deviceInfo}</h4>
|
|
<p><strong>Frequency:</strong> ${freqMHz} MHz</p>
|
|
<p><strong>Protocol:</strong> ${capture.protocol || 'RAW'}</p>
|
|
<p><strong>Captured:</strong> ${date}</p>
|
|
<p><strong>Location:</strong> ${capture.latitude.toFixed(6)}, ${capture.longitude.toFixed(6)}</p>
|
|
${capture.accuracy ? `<p><strong>Accuracy:</strong> ±${capture.accuracy.toFixed(1)}m</p>` : ''}
|
|
<button onclick="viewCaptureDetails('${capture.file_hash}')" class="btn btn-primary" style="margin-top: 0.5rem;">
|
|
View Details
|
|
</button>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
function updateStats() {
|
|
// Total captures
|
|
document.getElementById('total-captures').textContent = capturesData.length;
|
|
|
|
// Unique devices
|
|
const uniqueDevices = new Set(
|
|
capturesData
|
|
.filter(c => c.device_name)
|
|
.map(c => c.device_name)
|
|
).size;
|
|
document.getElementById('unique-devices').textContent = uniqueDevices;
|
|
}
|
|
|
|
function viewCaptureDetails(fileHash) {
|
|
// Navigate to detail page (to be implemented)
|
|
alert(`Viewing details for capture: ${fileHash}`);
|
|
}
|
|
|
|
// Export for external use
|
|
window.reloadMapData = loadCaptures;
|