datenspuren food: reset & reorder if moved >= 100m
This commit is contained in:
parent
8e0da31036
commit
927fde3fb3
|
@ -1,7 +1,9 @@
|
||||||
|
var poisJson
|
||||||
var currentPosition = {
|
var currentPosition = {
|
||||||
lat: 51.0420162,
|
lat: 51.0420162,
|
||||||
lon: 13.7976983
|
lon: 13.7976983
|
||||||
}
|
}
|
||||||
|
var currentCenter
|
||||||
var geoListeners = []
|
var geoListeners = []
|
||||||
|
|
||||||
function POI(info) {
|
function POI(info) {
|
||||||
|
@ -49,10 +51,21 @@ function onGeo(geo) {
|
||||||
lon: geo.coords.longitude,
|
lon: geo.coords.longitude,
|
||||||
heading: geo.heading
|
heading: geo.heading
|
||||||
}
|
}
|
||||||
// call listeners
|
// if distance > 100m to old center (not currentPosition!), reset list
|
||||||
geoListeners.forEach(function(f) {
|
var dist = WGS84Util.distanceBetween({
|
||||||
f(currentPosition)
|
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) {
|
function formatDistance(x) {
|
||||||
|
@ -70,6 +83,59 @@ function makeLink(link) {
|
||||||
return a
|
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>')
|
var h3 = $('<h3 id="foodlocator">Imbißmöglichkeiten anzeigen</h3>')
|
||||||
$('article').append(h3)
|
$('article').append(h3)
|
||||||
|
|
||||||
|
@ -91,52 +157,10 @@ h3.click(function() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "pois.json",
|
url: "pois.json",
|
||||||
success: function(json) {
|
success: function(json) {
|
||||||
var pois = json.elements.map(function(info) {
|
$('article').append('<dl id="food"></dl>')
|
||||||
return new POI(info)
|
showPOIs(json)
|
||||||
}).sort(function(a, b) {
|
poisJson = json
|
||||||
return a.getDistance() - b.getDistance()
|
|
||||||
})
|
|
||||||
while(pois.length > 20 && pois[pois.length - 1].getDistance() > 1000) {
|
|
||||||
pois.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
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")
|
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>")
|
$('article').append("<p style='margin-top: 1.5em'>Quelle: OpenStreetMap. Stündlich aktualisiert mithilfe Overpass Turbo.</p>")
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue