v0.6.1: minor fixes

- fixed modal style
- modified some texts
- worked on stationsNearMe functionality (WIP)
- correct sorting of OSM level list
This commit is contained in:
kritzl 2024-06-09 18:42:15 +02:00
parent e72ad0cf07
commit 085329929f
10 changed files with 218 additions and 55 deletions

View file

@ -232,7 +232,7 @@ async function loadOsmData() {
if (!internalData.stations[stationIndex].hasOwnProperty('coordinates')) {
const substitute = substituteData.filter(subs => subs.name === internalData.stations[stationIndex].name)
if (substitute.length && substitute.hasOwnProperty('coordinates')) {
if (substitute.length && substitute[0].hasOwnProperty('coordinates')) {
internalData.stations[stationIndex]['coordinates'] = substitute[0].coordinates;
}
}
@ -316,9 +316,23 @@ function sortStations(stationA, stationB) {
return 0;
}
function sortInt(valueA, valueB) {
const a = parseInt(valueA)
const b = parseInt(valueB)
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
// names must be equal
return 0;
}
function sortStationsByDistance(stationA, stationB) {
const distanceA = stationA.distance; // ignore upper and lowercase
const distanceB = stationB.distance; // ignore upper and lowercase
const distanceA = stationA.distance ?? 0; // ignore upper and lowercase
const distanceB = stationB.distance ?? 0; // ignore upper and lowercase
if (distanceA < distanceB) {
return -1;
}
@ -415,7 +429,9 @@ function renderData(location = null) {
}
}
stations = stations.sort(sortStationsByDistance);
if (sortByDistance) {
stations = stations.sort(sortStationsByDistance);
}
for (const stationIndex in stations) {
const station = stations[stationIndex];
@ -478,7 +494,7 @@ function renderData(location = null) {
osmTemplate += `<div><dt><span data-icon="info" class="size-l"></span>Beschreibung</dt><dd>${node.tags['description']}</dd></div>`;
}
if (node.tags.hasOwnProperty('level')) {
osmTemplate += `<div><dt><span data-icon="up-down" class="size-l"></span>Ebenen</dt><dd>${node.tags['level'].split(';').sort().join(', ')}</dd></div>`;
osmTemplate += `<div><dt><span data-icon="up-down" class="size-l"></span>Ebenen</dt><dd>${node.tags['level'].split(';').sort(sortInt).join(', ')}</dd></div>`;
}
if (node.tags.hasOwnProperty('wheelchair')) {
osmTemplate += `<div><dt><span data-icon="wheelchair" class="size-l"></span>Rollstühle</dt><dd>${node.tags['wheelchair'] === 'yes' ? 'Ja' : 'Nein'}</dd></div>`;
@ -551,7 +567,11 @@ function renderData(location = null) {
<div class="typeList">
${station.types.sort().map(t => `<span class="typeChip" data-type="${t}">${t}</span>`).join('')}
</div>
${typeof station.distance !== 'undefined' ? `<div class="distance"><b>${Math.round(station.distance / 100) / 10}</b><br>km</div>` : ''}
${sortByDistance
? typeof station.distance !== 'undefined'
? `<div class="distance"><b>${Math.round(station.distance / 100) / 10}</b><br>km</div>`
: '<div class="distance">? km</div>'
: ''}
</div>
<div class="stationTitle">
<h3>${station.name}</h3>
@ -646,12 +666,13 @@ document.querySelector('#stationsNearMe')
if (geolocationPermission !== 'granted') {
allowGeolocation();
} else {
sortByDistance = e.target.ariaPressed = true;
// If geolocation is already set.
// If not the location watcher will re-render our data.
if (geolocation !== null) {
renderData(geolocation)
}
sortByDistance = e.target.ariaPressed = true;
}
}
} else {