From 0722cd0a636d272502a03434dfe91386c0624d82 Mon Sep 17 00:00:00 2001 From: Code WvS Date: Sun, 1 Mar 2015 15:35:40 +0100 Subject: set the initial view to user's position; add new sprites to the center of the view --- snap.html | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'snap.html') diff --git a/snap.html b/snap.html index d9ead90..598b71c 100755 --- a/snap.html +++ b/snap.html @@ -69,6 +69,14 @@ window.geoposition = e.latlng; } + // Sets the view on the first locate + function firstLocate (e) { + setGlobalPosition(e); + map.stopLocate(); + map.on('locationfound', setGlobalPosition); + map.locate({watch: true, enableHighAccuracy: true}); + } + window.map = map; window.layer = layer; @@ -76,7 +84,7 @@ map = L.map('map', { keyboard: false, closePopupOnClick: false - }).setView([52.5170365, 13.3888599], 10); + }); // The map steals the key events, so the 'world' canvas has to be focused map.on('mouseover', function() {document.getElementById('world').focus();}); @@ -91,8 +99,8 @@ }).addTo(map); // continuously update the local location variable - map.on('locationfound', setGlobalPosition); - map.locate({watch: true, enableHighAccuracy: true}); + map.on('locationfound', firstLocate); + map.locate({setView: true, enableHighAccuracy: true}); // OSMBuildings provides fancy 3D buildings new OSMBuildings(map).load(); -- cgit v1.3.1