|
|
@ -4,7 +4,6 @@ |
|
|
|
{{ 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 player_app_content %} |
|
|
|
{% block player_app_content %} |
|
|
@ -75,25 +74,60 @@ |
|
|
|
|
|
|
|
|
|
|
|
{% 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 bunnieMarkers = [] |
|
|
|
var bunnies = JSON.parse( |
|
|
|
var bunnies = JSON.parse( |
|
|
|
'{{ json.dumps(game.last_locations(game.bunnies(), offset=hunter_delay), cls=location_encoder)|safe }}') |
|
|
|
'{{ json.dumps(game.last_locations(game.bunnies(), offset=hunter_delay), cls=location_encoder)|safe }}') |
|
|
|
for (var i = 0; i < bunnies.length; i++) { |
|
|
|
updateBunnieMarkers() |
|
|
|
addPlayerMarker(map, bunnies[i]) |
|
|
|
|
|
|
|
markers.push([bunnies[i].latitude, bunnies[i].longitude]) |
|
|
|
if (bunnieMarkers.length > 1) { |
|
|
|
|
|
|
|
map.fitBounds(bunnieMarkers); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var self = JSON.parse('{{ json.dumps(current_user.last_location(), cls=location_encoder)|safe }}') |
|
|
|
function updateBunnieMarkers(){ |
|
|
|
if (self) { |
|
|
|
if(bunnieMarkers != undefined){ |
|
|
|
addPlayerMarker(map, self, greenPlayerIcon) |
|
|
|
bunnieMarkers.forEach(function(marker){ |
|
|
|
markers.push([self.latitude, self.longitude]) |
|
|
|
marker.remove() |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bunnieMarkers = [] |
|
|
|
|
|
|
|
for (var i = 0; i < bunnies.length; i++) { |
|
|
|
|
|
|
|
bunnieMarkers.push(addPlayerMarker(map, bunnies[i], greenPlayerIcon)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (markers.length > 0) { |
|
|
|
// Poll Locations |
|
|
|
map.fitBounds(markers); |
|
|
|
usernames = JSON.parse('{{ json.dumps(game.usernames())|safe }}').filter(name => name != '{{ current_user.name }}') |
|
|
|
|
|
|
|
setInterval(function() { |
|
|
|
|
|
|
|
pollLocations( |
|
|
|
|
|
|
|
"{{ url_for('main.poll_locations', game_name=game.name) }}", |
|
|
|
|
|
|
|
usernames, |
|
|
|
|
|
|
|
'accumulative', |
|
|
|
|
|
|
|
bunnies, |
|
|
|
|
|
|
|
handleResponse |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
getPosition(updateMyLocation) |
|
|
|
|
|
|
|
}, 10 * 1000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleResponse(data){ |
|
|
|
|
|
|
|
data.forEach(function (location) { |
|
|
|
|
|
|
|
bunnie = bunnies.filter(function (bunnie) { |
|
|
|
|
|
|
|
return bunnie.username == location.username; |
|
|
|
|
|
|
|
})[0]; |
|
|
|
|
|
|
|
if (new Date(location.timestamp_utc) > new Date(bunnie.timestamp_utc)){ |
|
|
|
|
|
|
|
//lastLocation = bunnie[bunnie.length-1] Not necesary because there is just one of each bunnie |
|
|
|
|
|
|
|
if (bunnie.latitude == location.latitude && bunnie.longitude == location.longitude){ |
|
|
|
|
|
|
|
bunnie.timestamp_utc = location.timestamp_utc |
|
|
|
|
|
|
|
} else{ |
|
|
|
|
|
|
|
bunnies = bunnies.filter(p => p !== bunnie) |
|
|
|
|
|
|
|
bunnies.push(location) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
updateBunnieMarkers() |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
{% endblock %} |
|
|
|
{% endblock %} |