diff --git a/app/static/assets/leaflet/utils.js b/app/static/assets/leaflet/utils.js index fc1a460..d093b24 100644 --- a/app/static/assets/leaflet/utils.js +++ b/app/static/assets/leaflet/utils.js @@ -74,6 +74,24 @@ function addPlayerMarker(map, player, icon=bluePlayerIcon){ return playerMarker } +var myLocationMarker +function updateMyLocation(position){ + if(myLocationMarker == undefined){ + myLocationMarker = L.marker([ + position.coords.latitude, + position.coords.longitude + ], {icon: greenPlayerIcon}).addTo(map) + myLocationMarker.bindTooltip('Your current location').openPopup(); + } + else{ + var newLocation = new L.LatLng( + position.coords.latitude, + position.coords.longitude + ); + myLocationMarker.setLatLng(newLocation); + } +} + function getMap(){ var map = L.map( 'map', { center: [52.2, 5.3], diff --git a/app/templates/game_bunny_dashboard.html b/app/templates/game_bunny_dashboard.html index b7b5205..bd4fcdf 100644 --- a/app/templates/game_bunny_dashboard.html +++ b/app/templates/game_bunny_dashboard.html @@ -4,7 +4,6 @@ {{ super() }} - {% endblock %} {% block player_app_content %} @@ -57,6 +56,7 @@ {% block scripts %} {{ super() }} + + {% endblock %} {% block app_content %} @@ -110,6 +111,7 @@ objectMarkers.push([objectives[i].latitude, objectives[i].longitude]) } + var players = JSON.parse('{{ json.dumps(game.last_player_locations(), cls=location_encoder)|safe }}') updatePlayerMarkers() @@ -129,15 +131,6 @@ } } - function sendLocation(){ - if (navigator.geolocation) { - navigator.geolocation.getCurrentPosition(postCoordinates, showError); - - } else { - console.log('Geolocation is not supported by this browser.') - } - } - // Poll Locations usernames = JSON.parse('{{ json.dumps(game.usernames())|safe }}') setInterval(function() { @@ -148,6 +141,7 @@ players, handleResponse ) + getPosition(updateMyLocation) }, 30 * 1000); function handleResponse(data){ diff --git a/app/templates/player_base.html b/app/templates/player_base.html index 56b5db0..d2c0685 100644 --- a/app/templates/player_base.html +++ b/app/templates/player_base.html @@ -7,6 +7,7 @@ {% block scripts %} {{ super() }} +