Browse Source

auto update own location on bunny and owner dashboard

testing
Burathar 4 years ago
parent
commit
f11c05ff1f
  1. 2
      app/static/assets/leaflet/utils.js
  2. 10
      app/templates/game_bunny_dashboard.html
  3. 4
      app/templates/game_owner_dashboard.html
  4. 12
      app/templates/game_player.html

2
app/static/assets/leaflet/utils.js

@ -80,7 +80,7 @@ function updateMyLocation(position){
myLocationMarker = L.marker([ myLocationMarker = L.marker([
position.coords.latitude, position.coords.latitude,
position.coords.longitude position.coords.longitude
], {icon: greenPlayerIcon}).addTo(map) ], {icon: bluePlayerIcon}).addTo(map)
myLocationMarker.bindTooltip('Your current location').openPopup(); myLocationMarker.bindTooltip('Your current location').openPopup();
} }
else{ else{

10
app/templates/game_bunny_dashboard.html

@ -66,12 +66,12 @@
addObjectiveMarker(map, objectives[i]) addObjectiveMarker(map, objectives[i])
markers.push([objectives[i].latitude, objectives[i].longitude]) markers.push([objectives[i].latitude, objectives[i].longitude])
} }
var self = JSON.parse('{{ json.dumps(current_user.last_location(), cls=location_encoder)|safe }}') function updateSelf() {
if (self){ getPosition(updateMyLocation)
addPlayerMarker(map, self)
markers.push([self.latitude, self.longitude])
} }
setInterval(updateSelf, 10 * 1000);
updateSelf()
if (markers.length > 0) { if (markers.length > 0) {
map.fitBounds(markers); map.fitBounds(markers);

4
app/templates/game_owner_dashboard.html

@ -104,6 +104,7 @@
var map = getMap() var map = getMap()
var objectMarkers = [] var objectMarkers = []
var playerMarkers = [] var playerMarkers = []
var objectives = JSON.parse('{{ json.dumps(game.objectives, cls=objective_encoder)|safe }}') var objectives = JSON.parse('{{ json.dumps(game.objectives, cls=objective_encoder)|safe }}')
for (var i = 0; i < objectives.length; i++){ for (var i = 0; i < objectives.length; i++){
@ -111,7 +112,6 @@
objectMarkers.push([objectives[i].latitude, objectives[i].longitude]) objectMarkers.push([objectives[i].latitude, objectives[i].longitude])
} }
var players = JSON.parse('{{ json.dumps(game.last_player_locations(), cls=location_encoder)|safe }}') var players = JSON.parse('{{ json.dumps(game.last_player_locations(), cls=location_encoder)|safe }}')
updatePlayerMarkers() updatePlayerMarkers()
@ -119,6 +119,8 @@
map.fitBounds(objectMarkers.concat(playerMarkers)); map.fitBounds(objectMarkers.concat(playerMarkers));
} }
getPosition(updateMyLocation);
function updatePlayerMarkers(){ function updatePlayerMarkers(){
if(playerMarkers != undefined){ if(playerMarkers != undefined){
playerMarkers.forEach(function(marker){ playerMarkers.forEach(function(marker){

12
app/templates/game_player.html

@ -80,10 +80,11 @@
var locations = JSON.parse('{{ json.dumps(player.locations_during_game(), cls=location_encoder)|safe }}') var locations = JSON.parse('{{ json.dumps(player.locations_during_game(), cls=location_encoder)|safe }}')
if (locations == null) { if (locations == null) {
locations = [] locations = [];
} }
var markers, lastMarker; var markers = [];
var lastMarker;
updateMarkers(); updateMarkers();
var polyline; var polyline;
updatePolyline(); updatePolyline();
@ -102,13 +103,14 @@
}); });
markers = [] markers = []
} }
if(locations.length == 0){ return }
for (var i = 0; i < locations.length -1; i++) { for (var i = 0; i < locations.length -1; i++) {
markers.push(addPlayerMarker(map, locations[i], bluePlayerIconMini)) markers.push(addPlayerMarker(map, locations[i], bluePlayerIconMini))
} }
if(lastMarker != undefined){ if(lastMarker != undefined){
lastMarker.remove() lastMarker.remove()
lastMarker = addPlayerMarker(map, locations[locations.length-1], bluePlayerIcon)
} }
lastMarker = addPlayerMarker(map, locations[locations.length-1], bluePlayerIcon)
} }
function updatePolyline(){ function updatePolyline(){
@ -147,16 +149,12 @@
updatePolyline() updatePolyline()
updateMarkers() updateMarkers()
} }
console.log('test1')
//Ajax for Generate Code button //Ajax for Generate Code button
$(function () { $(function () {
console.log('test2')
$('a#generate_auth_hash').bind('click', function () { $('a#generate_auth_hash').bind('click', function () {
console.log('test3')
$.ajax({ $.ajax({
url: "{{ url_for('auth.generate_auth_hash', username=player.user.name) }}", url: "{{ url_for('auth.generate_auth_hash', username=player.user.name) }}",
success: function (result) { success: function (result) {
console.log('test4')
location.reload(); location.reload();
} }
}); });

Loading…
Cancel
Save