fetch OSM Data
This commit is contained in:
parent
e52aacbf28
commit
dc84436346
6 changed files with 58 additions and 57 deletions
27
README.md
27
README.md
|
@ -1,26 +1,3 @@
|
||||||
```paython
|
# A11y Elevator List for HVV
|
||||||
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
class CORSRequestHandler(SimpleHTTPRequestHandler):
|
|
||||||
|
|
||||||
def end_headers(self):
|
|
||||||
self.send_header('Access-Control-Allow-Origin', 'origin')
|
|
||||||
self.send_header('Access-Control-Allow-Methods', '*')
|
|
||||||
self.send_header('Access-Control-Allow-Headers', '*')
|
|
||||||
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
|
|
||||||
return super(CORSRequestHandler, self).end_headers()
|
|
||||||
|
|
||||||
def do_OPTIONS(self):
|
|
||||||
self.send_response(200)
|
|
||||||
self.end_headers()
|
|
||||||
|
|
||||||
host = sys.argv[1] if len(sys.argv) > 2 else '0.0.0.0'
|
|
||||||
port = int(sys.argv[len(sys.argv)-1]) if len(sys.argv) > 1 else 8080
|
|
||||||
|
|
||||||
print("Listening on {}:{}".format(host, port))
|
|
||||||
httpd = HTTPServer((host, port), CORSRequestHandler)
|
|
||||||
httpd.serve_forever()
|
|
||||||
```
|
|
||||||
|
|
||||||
|
This site provides an (at least more) accessible version of the HVV Website for (not) working elevators: https://www.hvv.de/de/aufzuege
|
|
@ -32,7 +32,7 @@
|
||||||
<a href="https://www.hvv.de/de/aufzuege">HVV Website</a>
|
<a href="https://www.hvv.de/de/aufzuege">HVV Website</a>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
bla...
|
The Source code of this page is available under: <a href="https://git.kritzl.dev/kritzl/hvvstuhl.de" target="_blank">git.kritzl.dev</a>
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|
53
elevators.js
53
elevators.js
|
@ -24,21 +24,38 @@ let geolocation = [null, null];
|
||||||
|
|
||||||
async function loadOsmData() {
|
async function loadOsmData() {
|
||||||
const elevatorNodes = document.querySelectorAll('.elevator');
|
const elevatorNodes = document.querySelectorAll('.elevator');
|
||||||
|
const nodeIdList = [];
|
||||||
for (const elevator of elevatorNodes) {
|
for (const elevator of elevatorNodes) {
|
||||||
elevator.querySelector('.osm').insertAdjacentHTML("beforeend", '<dl class="osmTags">loading...</dl>')
|
const osmContainer = elevator.querySelector('.osm');
|
||||||
|
const nodeId = osmContainer.dataset.nodeid;
|
||||||
|
if (nodeId > 0) {
|
||||||
|
elevator.querySelector('.osm').insertAdjacentHTML("beforeend", '<dl class="osmTags">loading...</dl>');
|
||||||
|
nodeIdList.push(nodeId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const elevator of elevatorNodes) {
|
const osmData = await fetch(`https://overpass-api.de/api/interpreter?data=[out:json];node(id:${nodeIdList.join(',')});out%20body;`, {});
|
||||||
const osmContainer = elevator.querySelector('.osmTags');
|
const osmJson = await osmData.json();
|
||||||
const nodeId = elevator.querySelector('.osm').dataset.nodeid;
|
|
||||||
const osmData = await fetch(`https://overpass-api.de/api/interpreter?data=[out:json];node(${nodeId});out%20body;`, {});
|
if (!osmJson.hasOwnProperty('elements')) return;
|
||||||
const responseData = await osmData.json();
|
|
||||||
|
for (const elevator of elevatorNodes) {
|
||||||
|
const tagContainer = elevator.querySelector('.osmTags');
|
||||||
|
const nodeId = elevator.querySelector('.osm').dataset.nodeid;
|
||||||
|
|
||||||
|
const nodes = osmJson.elements.filter(node => node.id === parseInt(nodeId))
|
||||||
|
if (!nodes.length) {
|
||||||
|
tagContainer.innerHTML = 'keine Daten';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const nodeInfo = nodes[0];
|
||||||
|
|
||||||
|
if (!nodeInfo.hasOwnProperty('tags')) {
|
||||||
|
tagContainer.innerHTML = 'keine Daten';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const tags = nodeInfo['tags'];
|
||||||
|
|
||||||
if (responseData.elements.length) {
|
|
||||||
const node = responseData.elements[0];
|
|
||||||
const tags = node['tags'];
|
|
||||||
console.log(tags)
|
|
||||||
if (tags['highway'] === 'elevator') {
|
if (tags['highway'] === 'elevator') {
|
||||||
let osmTemplate = '';
|
let osmTemplate = '';
|
||||||
osmTemplate += `<div><dt><span data-icon="location" class="size-l"></span>Link zur Karte</dt><dd><a href="https://www.openstreetmap.org/node/${nodeId}" target="_blank">
|
osmTemplate += `<div><dt><span data-icon="location" class="size-l"></span>Link zur Karte</dt><dd><a href="https://www.openstreetmap.org/node/${nodeId}" target="_blank">
|
||||||
|
@ -56,10 +73,8 @@ Auf Karte anzeigen
|
||||||
if (tags.hasOwnProperty('bicycle')) {
|
if (tags.hasOwnProperty('bicycle')) {
|
||||||
osmTemplate += `<div><dt><span data-icon="bicycle" class="size-l"></span>Fahrräder</dt><dd>${tags['bicycle'] === 'yes' ? 'Ja' : 'Nein'}</dd></div>`;
|
osmTemplate += `<div><dt><span data-icon="bicycle" class="size-l"></span>Fahrräder</dt><dd>${tags['bicycle'] === 'yes' ? 'Ja' : 'Nein'}</dd></div>`;
|
||||||
}
|
}
|
||||||
osmContainer.innerHTML = ''; // clear loading state
|
tagContainer.innerHTML = ''; // clear loading state
|
||||||
osmContainer.insertAdjacentHTML('beforeend', osmTemplate);
|
tagContainer.insertAdjacentHTML('beforeend', osmTemplate);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,6 +189,9 @@ function renderData() {
|
||||||
dateContainer.innerHTML = dateTimeStyle.format(date);
|
dateContainer.innerHTML = dateTimeStyle.format(date);
|
||||||
|
|
||||||
let stationIndex = 0;
|
let stationIndex = 0;
|
||||||
|
|
||||||
|
//clear list before update
|
||||||
|
listContainer.innerHTML = '';
|
||||||
for (const station of stations) {
|
for (const station of stations) {
|
||||||
const stationName = station.mainSubStation.stationName;
|
const stationName = station.mainSubStation.stationName;
|
||||||
const lines = new Set();
|
const lines = new Set();
|
||||||
|
@ -345,6 +363,11 @@ document.querySelector('#loadElevators')
|
||||||
loadElevators().then(() => renderData());
|
loadElevators().then(() => renderData());
|
||||||
})
|
})
|
||||||
|
|
||||||
|
document.querySelector('#loadOSM')
|
||||||
|
.addEventListener('click', (e) => {
|
||||||
|
loadOsmData();
|
||||||
|
})
|
||||||
|
|
||||||
renderData();
|
renderData();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
<div>
|
<div>
|
||||||
<span>Last Updated: <b id="lastUpdated"></b></span>
|
<span>Last Updated: <b id="lastUpdated"></b></span>
|
||||||
<button id="loadElevators">Daten vom HVV abrufen</button>
|
<button id="loadElevators">Daten vom HVV abrufen</button>
|
||||||
|
<button id="loadOSM">OSM Daten abrufen</button>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ button, input {
|
||||||
|
|
||||||
button {
|
button {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: var(--space-m);
|
gap: var(--space-m);
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ button, input {
|
||||||
|
|
||||||
button {
|
button {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: var(--space-m);
|
gap: var(--space-m);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue