|
|
@ -4,10 +4,10 @@ |
|
|
|
{{ super() }} |
|
|
|
{{ super() }} |
|
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='assets/leaflet/leaflet.css') }}" /> |
|
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='assets/leaflet/leaflet.css') }}" /> |
|
|
|
<script src="{{ url_for('static', filename='assets/leaflet/leaflet.js') }}"></script> |
|
|
|
<script src="{{ url_for('static', filename='assets/leaflet/leaflet.js') }}"></script> |
|
|
|
<script src="{{ url_for('static', filename='assets/leaflet/utils.js') }}"></script> |
|
|
|
|
|
|
|
{% endblock %} |
|
|
|
{% endblock %} |
|
|
|
|
|
|
|
|
|
|
|
{% block app_content %} |
|
|
|
{% block app_content %} |
|
|
|
|
|
|
|
<meta name="csrf-token" content="{{ csrf_token() }}"> |
|
|
|
<h1>{{ game.name }} Dashboard</h1> |
|
|
|
<h1>{{ game.name }} Dashboard</h1> |
|
|
|
<a href="{{ url_for('game.change_game_settings', game_name=game.name) }}"> |
|
|
|
<a href="{{ url_for('game.change_game_settings', game_name=game.name) }}"> |
|
|
|
<button class="btn btn-primary">Change Game Settings</button> |
|
|
|
<button class="btn btn-primary">Change Game Settings</button> |
|
|
@ -97,25 +97,65 @@ |
|
|
|
|
|
|
|
|
|
|
|
{% block scripts %} |
|
|
|
{% block scripts %} |
|
|
|
{{ super() }} |
|
|
|
{{ super() }} |
|
|
|
|
|
|
|
<script src="{{ url_for('static', filename='assets/leaflet/utils.js') }}"></script> |
|
|
|
<script type="text/javascript", crossorigin="anonymous"> |
|
|
|
<script type="text/javascript", crossorigin="anonymous"> |
|
|
|
// Leaflet Map |
|
|
|
// Leaflet Map |
|
|
|
map = getMap() |
|
|
|
var map = getMap() |
|
|
|
markers = [] |
|
|
|
var objectMarkers = [] |
|
|
|
|
|
|
|
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++){ |
|
|
|
addObjectiveMarker(map, objectives[i]) |
|
|
|
addObjectiveMarker(map, objectives[i]) |
|
|
|
markers.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 }}') |
|
|
|
for (var i = 0; i < players.length; i++){ |
|
|
|
updatePlayerMarkers() |
|
|
|
addPlayerMarker(map, players[i]) |
|
|
|
|
|
|
|
markers.push([players[i].latitude, players[i].longitude]) |
|
|
|
if (objectMarkers.length + playerMarkers.length > 0) { |
|
|
|
|
|
|
|
map.fitBounds(objectMarkers.concat(playerMarkers)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (markers.length > 0) { |
|
|
|
function updatePlayerMarkers(){ |
|
|
|
map.fitBounds(markers); |
|
|
|
if(playerMarkers != undefined){ |
|
|
|
|
|
|
|
playerMarkers.forEach(function(marker){ |
|
|
|
|
|
|
|
marker.remove() |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
playerMarkers = [] |
|
|
|
|
|
|
|
for (var i = 0; i < players.length; i++) { |
|
|
|
|
|
|
|
playerMarkers.push(addPlayerMarker(map, players[i], bluePlayerIcon)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Poll Locations |
|
|
|
|
|
|
|
usernames = JSON.parse('{{ json.dumps(game.usernames())|safe }}') |
|
|
|
|
|
|
|
setInterval(function() { |
|
|
|
|
|
|
|
pollLocations( |
|
|
|
|
|
|
|
"{{ url_for('main.poll_locations', game_name=game.name) }}", |
|
|
|
|
|
|
|
usernames, |
|
|
|
|
|
|
|
'accumulative', |
|
|
|
|
|
|
|
players, |
|
|
|
|
|
|
|
handleResponse |
|
|
|
|
|
|
|
)}, 30 * 1000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleResponse(data){ |
|
|
|
|
|
|
|
data.forEach(function (location) { |
|
|
|
|
|
|
|
player = players.filter(function (player) { |
|
|
|
|
|
|
|
return player.username == location.username; |
|
|
|
|
|
|
|
})[0]; |
|
|
|
|
|
|
|
if (new Date(location.timestamp_utc) > new Date(player.timestamp_utc)){ |
|
|
|
|
|
|
|
//lastLocation = player[player.length-1] Not necesary because there is just one of each player |
|
|
|
|
|
|
|
if (player.latitude == location.latitude && player.longitude == location.longitude){ |
|
|
|
|
|
|
|
player.timestamp_utc = location.timestamp_utc |
|
|
|
|
|
|
|
} else{ |
|
|
|
|
|
|
|
players = players.filter(p => p !== player) |
|
|
|
|
|
|
|
players.push(location) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
updatePlayerMarkers() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
</script> |
|
|
|
</script> |
|
|
|