datenspuren food: reset & reorder if moved >= 100m
This commit is contained in:
parent
8e0da31036
commit
927fde3fb3
|
@ -1,7 +1,9 @@
|
|||
var poisJson
|
||||
var currentPosition = {
|
||||
lat: 51.0420162,
|
||||
lon: 13.7976983
|
||||
}
|
||||
var currentCenter
|
||||
var geoListeners = []
|
||||
|
||||
function POI(info) {
|
||||
|
@ -49,10 +51,21 @@ function onGeo(geo) {
|
|||
lon: geo.coords.longitude,
|
||||
heading: geo.heading
|
||||
}
|
||||
// call listeners
|
||||
geoListeners.forEach(function(f) {
|
||||
f(currentPosition)
|
||||
// if distance > 100m to old center (not currentPosition!), reset list
|
||||
var dist = WGS84Util.distanceBetween({
|
||||
coordinates: [currentCenter.lon, currentCenter.lat]
|
||||
}, {
|
||||
coordinates: [currentPosition.lon, currentPosition.lat]
|
||||
})
|
||||
if (dist >= 100) {
|
||||
if (poisJson)
|
||||
showPOIs(poisJson)
|
||||
} else {
|
||||
// call listeners
|
||||
geoListeners.forEach(function(f) {
|
||||
f(currentPosition)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function formatDistance(x) {
|
||||
|
@ -70,6 +83,59 @@ function makeLink(link) {
|
|||
return a
|
||||
}
|
||||
|
||||
function showPOIs(json) {
|
||||
geoListeners = []
|
||||
var dl = $('#food')
|
||||
dl.empty()
|
||||
|
||||
currentCenter = currentPosition
|
||||
|
||||
var pois = json.elements.map(function(info) {
|
||||
return new POI(info)
|
||||
}).sort(function(a, b) {
|
||||
return a.getDistance() - b.getDistance()
|
||||
})
|
||||
while(pois.length > 20 && pois[pois.length - 1].getDistance() > 1000) {
|
||||
pois.pop()
|
||||
}
|
||||
|
||||
pois.forEach(function(poi) {
|
||||
if (!poi.info.tags.name) {
|
||||
console.warn("No name:", poi.info)
|
||||
return // Skip
|
||||
}
|
||||
|
||||
var dt = $('<dt><a></a></dt>')
|
||||
dt.find('a').
|
||||
attr('href', "https://www.openstreetmap.org/" + poi.info.type + "/" + poi.info.id).
|
||||
text(poi.info.tags.name)
|
||||
if (poi.info.tags.wheelchair == 'yes')
|
||||
dt.append("<span class='wheelchair'>♿</span>")
|
||||
|
||||
if (poi.info.tags['addr:street'] && poi.info.tags['addr:housenumber']) {
|
||||
var addr = $('<span class="addr"></span>')
|
||||
addr.text(poi.info.tags['addr:street'] + " " +
|
||||
poi.info.tags['addr:housenumber'])
|
||||
dt.append(addr)
|
||||
}
|
||||
if (poi.info.tags.website) {
|
||||
var addr = $('<span class="website"></span>')
|
||||
addr.append(makeLink(poi.info.tags.website))
|
||||
dt.append(addr)
|
||||
}
|
||||
dt.prepend(poi.makeArrowEl())
|
||||
dl.append(dt)
|
||||
|
||||
if (poi.info.tags.opening_hours) {
|
||||
poi.info.tags.opening_hours.split(/\s*;\s*/g).forEach(function(range) {
|
||||
var dd = $('<dd></dd>')
|
||||
dd.text(range)
|
||||
dl.append(dd)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var h3 = $('<h3 id="foodlocator">Imbißmöglichkeiten anzeigen</h3>')
|
||||
$('article').append(h3)
|
||||
|
||||
|
@ -91,52 +157,10 @@ h3.click(function() {
|
|||
$.ajax({
|
||||
url: "pois.json",
|
||||
success: function(json) {
|
||||
var pois = json.elements.map(function(info) {
|
||||
return new POI(info)
|
||||
}).sort(function(a, b) {
|
||||
return a.getDistance() - b.getDistance()
|
||||
})
|
||||
while(pois.length > 20 && pois[pois.length - 1].getDistance() > 1000) {
|
||||
pois.pop()
|
||||
}
|
||||
$('article').append('<dl id="food"></dl>')
|
||||
showPOIs(json)
|
||||
poisJson = json
|
||||
|
||||
var dl = $('<dl id="food"></dl>')
|
||||
pois.forEach(function(poi) {
|
||||
if (!poi.info.tags.name) {
|
||||
console.warn("No name:", poi.info)
|
||||
return // Skip
|
||||
}
|
||||
|
||||
var dt = $('<dt><a></a></dt>')
|
||||
dt.find('a').
|
||||
attr('href', "https://www.openstreetmap.org/" + poi.info.type + "/" + poi.info.id).
|
||||
text(poi.info.tags.name)
|
||||
if (poi.info.tags.wheelchair == 'yes')
|
||||
dt.append("<span class='wheelchair'>♿</span>")
|
||||
|
||||
if (poi.info.tags['addr:street'] && poi.info.tags['addr:housenumber']) {
|
||||
var addr = $('<span class="addr"></span>')
|
||||
addr.text(poi.info.tags['addr:street'] + " " +
|
||||
poi.info.tags['addr:housenumber'])
|
||||
dt.append(addr)
|
||||
}
|
||||
if (poi.info.tags.website) {
|
||||
var addr = $('<span class="website"></span>')
|
||||
addr.append(makeLink(poi.info.tags.website))
|
||||
dt.append(addr)
|
||||
}
|
||||
dt.prepend(poi.makeArrowEl())
|
||||
dl.append(dt)
|
||||
|
||||
if (poi.info.tags.opening_hours) {
|
||||
poi.info.tags.opening_hours.split(/\s*;\s*/g).forEach(function(range) {
|
||||
var dd = $('<dd></dd>')
|
||||
dd.text(range)
|
||||
dl.append(dd)
|
||||
})
|
||||
}
|
||||
})
|
||||
$('article').append(dl)
|
||||
h3.text("Imbißmöglichkeiten in der Umgebung")
|
||||
$('article').append("<p style='margin-top: 1.5em'>Quelle: OpenStreetMap. Stündlich aktualisiert mithilfe Overpass Turbo.</p>")
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue