Files
nebuleair_pro_4g/html/map.html
Your Name 7e8bf1294c update
2025-02-24 16:17:13 +01:00

266 lines
9.4 KiB
HTML
Executable File

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NebuleAir</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/leaflet/leaflet.css" />
<script src="assets/leaflet/leaflet.js"></script>
<style>
body {
overflow-x: hidden;
}
#sidebar a.nav-link {
position: relative;
display: flex;
align-items: center;
}
#sidebar a.nav-link:hover {
background-color: rgba(0, 0, 0, 0.5);
}
#sidebar a.nav-link svg {
margin-right: 8px; /* Add spacing between icons and text */
}
#sidebar {
transition: transform 0.3s ease-in-out;
}
.offcanvas-backdrop {
z-index: 1040;
}
</style>
</head>
<body>
<!-- Topbar -->
<span id="topbar"></span>
<!-- Sidebar Offcanvas for Mobile -->
<div class="offcanvas offcanvas-start text-white bg-dark" tabindex="-1" id="sidebarOffcanvas" aria-labelledby="sidebarOffcanvasLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="sidebarOffcanvasLabel">NebuleAir</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body" id="sidebar_mobile">
</div>
</div>
<div class="container-fluid mt-5">
<div class="row">
<aside class="col-md-2 col-lg-1 d-none d-md-block vh-100 position-fixed bg-dark text-white" id="sidebar">
</aside>
<!-- Main content -->
<main class="col-md-10 ms-sm-auto col-lg-11 offset-md-2 offset-lg-1 px-md-4">
<h1 class="mt-4">Localisation</h1>
<div class="row">
<div class="col-sm-6 mb-2">
<div class="card">
<div class="card-body">
<h3 class="mt-1">Zone localisation du capteur</h3>
<p class="card-text">Mis à jour automatiquement par le capteur. </p>
<div class="row">
<div class="col-6 mb-3">
<label for="device_name" class="form-label">Latitude</label>
<input type="text" class="form-control" id="device_latitude_raw" disabled>
</div>
<div class="col-6 mb-3">
<label for="device_name" class="form-label">Longitude</label>
<input type="text" class="form-control" id="device_longitude_raw" disabled>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-6 mb-2">
<div class="card">
<div class="card-body">
<h3 class="mt-1">Point précis</h3>
<p class="card-text">Mis à jour manuellement (sur aircarto.fr ou sur cette interface si le capteur est connecté au WIFI) </p>
<div class="row">
<div class="col-6 mb-3">
<label for="device_name" class="form-label">Latitude</label>
<input type="text" class="form-control" id="device_latitude_precision" onchange="update_config('latitude_precision', this.value)">
</div>
<div class="col-6 mb-3">
<label for="device_name" class="form-label">Longitude</label>
<input type="text" class="form-control" id="device_longitude_precision" onchange="update_config('longitude_precision', this.value)">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div id="map" style="height: 70vh;"></div>
</div>
</main>
</div>
</div>
<!-- JAVASCRIPT -->
<!-- Link Ajax locally -->
<script src="assets/jquery/jquery-3.7.1.min.js"></script>
<!-- Link Bootstrap JS and Popper.js locally -->
<script src="assets/js/bootstrap.bundle.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const elementsToLoad = [
{ id: 'topbar', file: 'topbar.html' },
{ id: 'sidebar', file: 'sidebar.html' },
{ id: 'sidebar_mobile', file: 'sidebar.html' }
];
elementsToLoad.forEach(({ id, file }) => {
fetch(file)
.then(response => response.text())
.then(data => {
const element = document.getElementById(id);
if (element) {
element.innerHTML = data;
}
})
.catch(error => console.error(`Error loading ${file}:`, error));
});
});
let map;
let marker;
// Function to load and update map
function loadConfigAndUpdateMap() {
fetch('../config.json')
.then(response => response.json())
.then(data => {
console.log("Getting config file (update)");
// Get device details
const deviceID = data.deviceID.trim().toUpperCase();
const deviceName = data.deviceName;
const device_latitude_precision = parseFloat(data.latitude_precision);
const device_longitude_precision = parseFloat(data.longitude_precision);
const device_latitude_raw = parseFloat(data.latitude_raw);
const device_longitude_raw = parseFloat(data.longitude_raw);
console.log("Latitude (precision): " + device_latitude_precision);
console.log("Longitude (precision): " + device_longitude_precision);
// Update input fields
document.getElementById("device_latitude_precision").value = device_latitude_precision;
document.getElementById("device_longitude_precision").value = device_longitude_precision;
document.getElementById("device_latitude_raw").value = device_latitude_raw;
document.getElementById("device_longitude_raw").value = device_longitude_raw;
// If map is not initialized, create it
if (!map) {
map = L.map('map').setView([device_latitude_precision, device_longitude_precision], 15);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
// Add draggable marker (point precision)
marker = L.marker([device_latitude_precision, device_longitude_precision], { draggable: true }).addTo(map);
//add a circle
var circle = L.circle([device_latitude_raw, device_longitude_raw], {
color: 'blue',
fillColor: '#f03',
fillOpacity: 0.5,
radius: 500
}).addTo(map);
// Event listener when marker is moved
marker.on('dragend', function (event) {
let newLatLng = marker.getLatLng();
console.log("Marker moved to:", newLatLng.lat, newLatLng.lng);
// Update the input fields with new values
document.getElementById("device_latitude").value = newLatLng.lat;
document.getElementById("device_longitude").value = newLatLng.lng;
// Call update function to save new values
update_config('latitude', newLatLng.lat);
setTimeout(() => { update_config('longitude', newLatLng.lng); }, 750);
});
} else {
// If the map already exists, update position
map.setView([device_latitude, device_longitude], 9);
// Move marker
marker.setLatLng([device_latitude, device_longitude]);
}
// Update device name in sidebar
document.querySelectorAll('.sideBar_sensorName').forEach((element) => {
element.innerText = deviceName;
});
// Get local RTC time
$.ajax({
url: 'launcher.php?type=RTC_time',
dataType: 'text',
method: 'GET',
success: function(response) {
console.log("Local RTC: " + response);
document.getElementById("RTC_time").textContent = response;
},
error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error);
}
});
})
.catch(error => console.error('Error loading config.json:', error));
}
// Function to update config and refresh the map
function update_config(param, value) {
console.log("Updating ", param, " : ", value);
$.ajax({
url: 'launcher.php?type=update_config&param=' + param + '&value=' + value,
dataType: 'text',
method: 'GET',
cache: false,
success: function(response) {
console.log(response);
},
error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error);
}
});
}
// Load config and initialize map on page load
window.onload = function () {
loadConfigAndUpdateMap();
};
</script>
</body>
</html>