Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions alarm_dashboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ def navigation_page() -> str:
"navigation.html",
crest_url=crest_url,
department_name=config.fire_department_name,
default_latitude=config.default_latitude,
default_longitude=config.default_longitude,
default_location_name=config.default_location_name,
)

@app.route("/history")
Expand Down
66 changes: 17 additions & 49 deletions alarm_dashboard/static/js/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ let mapInstance = null;
let routeLayer = null;
let startMarker = null;
let destinationMarker = null;
const navigationConfig = window.navigationConfig || {};
const configuredStart = navigationConfig.defaultStart || null;

function setStatus(message, type = 'info') {
if (!statusEl) {
Expand Down Expand Up @@ -172,47 +174,6 @@ function fetchAlarm() {
});
}

function requestCurrentPosition() {
if (typeof navigator === 'undefined' || !navigator.geolocation) {
return Promise.reject(new Error('Standortdienste werden von diesem Gerät nicht unterstützt.'));
}
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(
(position) => {
resolve({
lat: position.coords.latitude,
lon: position.coords.longitude,
accuracy: position.coords.accuracy,
});
},
(error) => {
let message = 'Der aktuelle Standort konnte nicht ermittelt werden.';
if (error && typeof error.code === 'number') {
switch (error.code) {
case error.PERMISSION_DENIED:
message = 'Der Zugriff auf den Standort wurde verweigert.';
break;
case error.POSITION_UNAVAILABLE:
message = 'Der Standort ist derzeit nicht verfügbar.';
break;
case error.TIMEOUT:
message = 'Die Standortbestimmung hat zu lange gedauert.';
break;
default:
break;
}
}
reject(new Error(message));
},
{
enableHighAccuracy: true,
timeout: 15000,
maximumAge: 0,
},
);
});
}

async function requestRoute(start, destination) {
const baseUrl = 'https://router.project-osrm.org/route/v1/driving/';
const query = `${start.lon},${start.lat};${destination.lon},${destination.lat}`;
Expand Down Expand Up @@ -337,15 +298,25 @@ async function initializeNavigation() {
return;
}

setStatus('Bestimme aktuellen Standort …');
const position = await requestCurrentPosition();
const startCoordinates = resolveCoordinates(configuredStart);
if (!startCoordinates) {
const message = 'Es ist kein fester Startpunkt für die Navigation konfiguriert.';
setStatus(message, 'error');
showMapMessage(message);
return;
}
if (startEl) {
startEl.textContent = formatCoordinatePair(position);
const label =
configuredStart && typeof configuredStart.label === 'string'
? configuredStart.label.trim()
: '';
const formattedCoordinates = formatCoordinatePair(startCoordinates);
startEl.textContent = label ? `${label} (${formattedCoordinates})` : formattedCoordinates;
}

setStatus('Berechne Route …');
const route = await requestRoute(position, destinationCoordinates);
updateRouteOnMap(position, destinationCoordinates, route);
const route = await requestRoute(startCoordinates, destinationCoordinates);
updateRouteOnMap(startCoordinates, destinationCoordinates, route);
setStatus('Route bereit. Gute Fahrt!');
} catch (error) {
console.error('Navigation konnte nicht geladen werden', error);
Expand All @@ -363,9 +334,6 @@ async function initializeNavigation() {
if (!fallbackShown) {
showMapMessage(message);
}
if (startEl) {
startEl.textContent = 'Unbekannt';
}
if (distanceEl) {
distanceEl.textContent = '–';
}
Expand Down
11 changes: 10 additions & 1 deletion alarm_dashboard/templates/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2 id="navigation-title">Navigation</h2>
<ul class="navigation-details" aria-live="polite" aria-label="Routeninformationen">
<li>
<strong>Start</strong>
<span id="navigation-start">Standort wird bestimmt …</span>
<span id="navigation-start"></span>
</li>
<li>
<strong>Ziel</strong>
Expand Down Expand Up @@ -88,6 +88,15 @@ <h2 id="navigation-title">Navigation</h2>
crossorigin=""
defer
></script>
<script>
window.navigationConfig = {
defaultStart: {
lat: {{ default_latitude | tojson }},
lon: {{ default_longitude | tojson }},
label: {{ default_location_name | tojson }}
}
};
</script>
<script src="/static/js/navigation.js" defer></script>
</body>
</html>