From e9282585122bdd21ae4a8ebe2463eb75290baebf Mon Sep 17 00:00:00 2001 From: Code WvS Date: Sun, 8 Mar 2015 11:54:46 +0100 Subject: simplify user location tracking --- snap.html | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'snap.html') diff --git a/snap.html b/snap.html index c6e845f..597ac17 100755 --- a/snap.html +++ b/snap.html @@ -66,19 +66,14 @@ // Grabbing values via global variables from deep inside Snap! is easier // Possible drawback: Multiple worlds could conflict - function setGlobalPosition (e) { + function locationfound(e) { + if (!window.geoposition) { + // Sets the view on the first locate + map.setView(e.latlng, 18); + } window.geoposition = e.latlng; } - // Sets the view on the first locate - function firstLocate (e) { - map.stopLocate(); - map.setView(e.latlng, 18); - setGlobalPosition(e); - map.on('locationfound', setGlobalPosition); - map.locate({watch: true, enableHighAccuracy: true}); - } - window.map = map; window.layer = layer; @@ -107,8 +102,8 @@ }).addTo(map); // continuously update the local location variable - map.on('locationfound', firstLocate); - map.locate({enableHighAccuracy: true}); + map.on('locationfound', locationfound); + map.locate({watch: true, enableHighAccuracy: true}); // OSMBuildings provides fancy 3D buildings new OSMBuildings(map).load(); -- cgit v1.3.1