From f11c05ff1f0f19e92708d6e5eacd3d657fbdc419 Mon Sep 17 00:00:00 2001 From: Burathar Date: Thu, 13 Aug 2020 14:40:38 +0200 Subject: [PATCH] auto update own location on bunny and owner dashboard --- app/static/assets/leaflet/utils.js | 2 +- app/templates/game_bunny_dashboard.html | 10 +++++----- app/templates/game_owner_dashboard.html | 4 +++- app/templates/game_player.html | 12 +++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/static/assets/leaflet/utils.js b/app/static/assets/leaflet/utils.js index d093b24..2baab25 100644 --- a/app/static/assets/leaflet/utils.js +++ b/app/static/assets/leaflet/utils.js @@ -80,7 +80,7 @@ function updateMyLocation(position){ myLocationMarker = L.marker([ position.coords.latitude, position.coords.longitude - ], {icon: greenPlayerIcon}).addTo(map) + ], {icon: bluePlayerIcon}).addTo(map) myLocationMarker.bindTooltip('Your current location').openPopup(); } else{ diff --git a/app/templates/game_bunny_dashboard.html b/app/templates/game_bunny_dashboard.html index bd4fcdf..8a591e6 100644 --- a/app/templates/game_bunny_dashboard.html +++ b/app/templates/game_bunny_dashboard.html @@ -66,12 +66,12 @@ addObjectiveMarker(map, objectives[i]) markers.push([objectives[i].latitude, objectives[i].longitude]) } - - var self = JSON.parse('{{ json.dumps(current_user.last_location(), cls=location_encoder)|safe }}') - if (self){ - addPlayerMarker(map, self) - markers.push([self.latitude, self.longitude]) + + function updateSelf() { + getPosition(updateMyLocation) } + setInterval(updateSelf, 10 * 1000); + updateSelf() if (markers.length > 0) { map.fitBounds(markers); diff --git a/app/templates/game_owner_dashboard.html b/app/templates/game_owner_dashboard.html index 48485e3..36f65ef 100644 --- a/app/templates/game_owner_dashboard.html +++ b/app/templates/game_owner_dashboard.html @@ -104,6 +104,7 @@ var map = getMap() var objectMarkers = [] var playerMarkers = [] + var objectives = JSON.parse('{{ json.dumps(game.objectives, cls=objective_encoder)|safe }}') for (var i = 0; i < objectives.length; i++){ @@ -111,7 +112,6 @@ objectMarkers.push([objectives[i].latitude, objectives[i].longitude]) } - var players = JSON.parse('{{ json.dumps(game.last_player_locations(), cls=location_encoder)|safe }}') updatePlayerMarkers() @@ -119,6 +119,8 @@ map.fitBounds(objectMarkers.concat(playerMarkers)); } + getPosition(updateMyLocation); + function updatePlayerMarkers(){ if(playerMarkers != undefined){ playerMarkers.forEach(function(marker){ diff --git a/app/templates/game_player.html b/app/templates/game_player.html index b111a0f..2234642 100644 --- a/app/templates/game_player.html +++ b/app/templates/game_player.html @@ -80,10 +80,11 @@ var locations = JSON.parse('{{ json.dumps(player.locations_during_game(), cls=location_encoder)|safe }}') if (locations == null) { - locations = [] + locations = []; } - var markers, lastMarker; + var markers = []; + var lastMarker; updateMarkers(); var polyline; updatePolyline(); @@ -102,13 +103,14 @@ }); markers = [] } + if(locations.length == 0){ return } for (var i = 0; i < locations.length -1; i++) { markers.push(addPlayerMarker(map, locations[i], bluePlayerIconMini)) } if(lastMarker != undefined){ lastMarker.remove() - lastMarker = addPlayerMarker(map, locations[locations.length-1], bluePlayerIcon) } + lastMarker = addPlayerMarker(map, locations[locations.length-1], bluePlayerIcon) } function updatePolyline(){ @@ -147,16 +149,12 @@ updatePolyline() updateMarkers() } - console.log('test1') //Ajax for Generate Code button $(function () { - console.log('test2') $('a#generate_auth_hash').bind('click', function () { - console.log('test3') $.ajax({ url: "{{ url_for('auth.generate_auth_hash', username=player.user.name) }}", success: function (result) { - console.log('test4') location.reload(); } });