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){ @@ -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{

10
app/templates/game_bunny_dashboard.html

@ -66,12 +66,12 @@ @@ -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);

4
app/templates/game_owner_dashboard.html

@ -104,6 +104,7 @@ @@ -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 @@ @@ -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 @@ @@ -119,6 +119,8 @@
map.fitBounds(objectMarkers.concat(playerMarkers));
}
getPosition(updateMyLocation);
function updatePlayerMarkers(){
if(playerMarkers != undefined){
playerMarkers.forEach(function(marker){

12
app/templates/game_player.html

@ -80,10 +80,11 @@ @@ -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 @@ @@ -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 @@ @@ -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();
}
});

Loading…
Cancel
Save