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,11 +51,22 @@ function onGeo(geo) {
|
||||||
lon: geo.coords.longitude,
|
lon: geo.coords.longitude,
|
||||||
heading: geo.heading
|
heading: geo.heading
|
||||||
}
|
}
|
||||||
|
// 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
|
// call listeners
|
||||||
geoListeners.forEach(function(f) {
|
geoListeners.forEach(function(f) {
|
||||||
f(currentPosition)
|
f(currentPosition)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function formatDistance(x) {
|
function formatDistance(x) {
|
||||||
if (x >= 1000) {
|
if (x >= 1000) {
|
||||||
|
@ -70,27 +83,13 @@ function makeLink(link) {
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
var h3 = $('<h3 id="foodlocator">Imbißmöglichkeiten anzeigen</h3>')
|
function showPOIs(json) {
|
||||||
$('article').append(h3)
|
geoListeners = []
|
||||||
|
var dl = $('#food')
|
||||||
|
dl.empty()
|
||||||
|
|
||||||
var ran = false
|
currentCenter = currentPosition
|
||||||
h3.click(function() {
|
|
||||||
if (ran) return
|
|
||||||
ran = true
|
|
||||||
|
|
||||||
navigator.geolocation.getCurrentPosition(function(geo) {
|
|
||||||
onGeo(geo)
|
|
||||||
navigator.geolocation.watchPosition(onGeo, null, {
|
|
||||||
enableHighAccuracy: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
h3.addClass('expanded')
|
|
||||||
h3.text("Lade Imbißmöglichkeiten...")
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: "pois.json",
|
|
||||||
success: function(json) {
|
|
||||||
var pois = json.elements.map(function(info) {
|
var pois = json.elements.map(function(info) {
|
||||||
return new POI(info)
|
return new POI(info)
|
||||||
}).sort(function(a, b) {
|
}).sort(function(a, b) {
|
||||||
|
@ -100,7 +99,6 @@ h3.click(function() {
|
||||||
pois.pop()
|
pois.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
var dl = $('<dl id="food"></dl>')
|
|
||||||
pois.forEach(function(poi) {
|
pois.forEach(function(poi) {
|
||||||
if (!poi.info.tags.name) {
|
if (!poi.info.tags.name) {
|
||||||
console.warn("No name:", poi.info)
|
console.warn("No name:", poi.info)
|
||||||
|
@ -136,7 +134,33 @@ h3.click(function() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
$('article').append(dl)
|
}
|
||||||
|
|
||||||
|
var h3 = $('<h3 id="foodlocator">Imbißmöglichkeiten anzeigen</h3>')
|
||||||
|
$('article').append(h3)
|
||||||
|
|
||||||
|
var ran = false
|
||||||
|
h3.click(function() {
|
||||||
|
if (ran) return
|
||||||
|
ran = true
|
||||||
|
|
||||||
|
navigator.geolocation.getCurrentPosition(function(geo) {
|
||||||
|
onGeo(geo)
|
||||||
|
navigator.geolocation.watchPosition(onGeo, null, {
|
||||||
|
enableHighAccuracy: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
h3.addClass('expanded')
|
||||||
|
h3.text("Lade Imbißmöglichkeiten...")
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "pois.json",
|
||||||
|
success: function(json) {
|
||||||
|
$('article').append('<dl id="food"></dl>')
|
||||||
|
showPOIs(json)
|
||||||
|
poisJson = json
|
||||||
|
|
||||||
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
Block a user