Rewrote UI, added option to export as gpx

This commit is contained in:
Pedan
2025-07-29 17:16:14 +02:00
parent 05a8d7abbd
commit 24e735e113
3 changed files with 214 additions and 65 deletions

View File

@@ -27,6 +27,26 @@ document.addEventListener('DOMContentLoaded', function() {
}
}
function formatAddress(item) {
if (!item.address) return item.display_name;
const addr = item.address;
let street = addr.road || addr.pedestrian || addr.cycleway || addr.footway || addr.street || '';
let number = addr.house_number || '';
let postcode = addr.postcode || '';
let city = addr.city || addr.town || addr.village || addr.hamlet || addr.municipality || addr.county || '';
// Build formatted string: Street Number, Postal code City
let address = '';
if (street) address += street;
if (number) address += (address ? ' ' : '') + number;
if (postcode || city) {
address += (address ? ', ' : '');
address += postcode;
if (postcode && city) address += ' ';
address += city;
}
return address;
}
function showSuggestions(inputId, suggestionsId, value) {
var suggestionsBox = document.getElementById(suggestionsId);
if (!value) {
@@ -34,7 +54,7 @@ document.addEventListener('DOMContentLoaded', function() {
suggestionsBox.style.display = 'none';
return;
}
fetch('https://nominatim.openstreetmap.org/search?format=json&q=' + encodeURIComponent(value))
fetch('https://nominatim.openstreetmap.org/search?format=json&addressdetails=1&q=' + encodeURIComponent(value))
.then(response => response.json())
.then(data => {
suggestionsBox.innerHTML = '';
@@ -43,10 +63,11 @@ document.addEventListener('DOMContentLoaded', function() {
var option = document.createElement('button');
option.type = 'button';
option.className = 'list-group-item list-group-item-action';
option.textContent = item.display_name;
option.textContent = formatAddress(item);
option.title = item.display_name; // Show full address on hover
option.onclick = function() {
var input = document.getElementById(inputId);
input.value = item.display_name;
input.value = formatAddress(item);
input.dataset.lat = item.lat;
input.dataset.lon = item.lon;
suggestionsBox.innerHTML = '';