|
|
|
@ -4,7 +4,6 @@
@@ -4,7 +4,6 @@
|
|
|
|
|
{{ super() }} |
|
|
|
|
<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/utils.js') }}"></script> |
|
|
|
|
{% endblock %} |
|
|
|
|
|
|
|
|
|
{% block player_app_content %} |
|
|
|
@ -75,25 +74,60 @@
@@ -75,25 +74,60 @@
|
|
|
|
|
|
|
|
|
|
{% block scripts %} |
|
|
|
|
{{ super() }} |
|
|
|
|
<script src="{{ url_for('static', filename='assets/leaflet/utils.js') }}"></script> |
|
|
|
|
<script type="text/javascript" , crossorigin="anonymous"> |
|
|
|
|
// Leaflet Map |
|
|
|
|
map = getMap() |
|
|
|
|
markers = [] |
|
|
|
|
var map = getMap() |
|
|
|
|
var bunnieMarkers = [] |
|
|
|
|
var bunnies = JSON.parse( |
|
|
|
|
'{{ json.dumps(game.last_locations(game.bunnies(), offset=hunter_delay), cls=location_encoder)|safe }}') |
|
|
|
|
for (var i = 0; i < bunnies.length; i++) { |
|
|
|
|
addPlayerMarker(map, bunnies[i]) |
|
|
|
|
markers.push([bunnies[i].latitude, bunnies[i].longitude]) |
|
|
|
|
updateBunnieMarkers() |
|
|
|
|
|
|
|
|
|
if (bunnieMarkers.length > 1) { |
|
|
|
|
map.fitBounds(bunnieMarkers); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var self = JSON.parse('{{ json.dumps(current_user.last_location(), cls=location_encoder)|safe }}') |
|
|
|
|
if (self) { |
|
|
|
|
addPlayerMarker(map, self, greenPlayerIcon) |
|
|
|
|
markers.push([self.latitude, self.longitude]) |
|
|
|
|
function updateBunnieMarkers(){ |
|
|
|
|
if(bunnieMarkers != undefined){ |
|
|
|
|
bunnieMarkers.forEach(function(marker){ |
|
|
|
|
marker.remove() |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
bunnieMarkers = [] |
|
|
|
|
for (var i = 0; i < bunnies.length; i++) { |
|
|
|
|
bunnieMarkers.push(addPlayerMarker(map, bunnies[i], greenPlayerIcon)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (markers.length > 0) { |
|
|
|
|
map.fitBounds(markers); |
|
|
|
|
|
|
|
|
|
// Poll Locations |
|
|
|
|
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> |
|
|
|
|
{% endblock %} |