Browse Source

fix update marker when no playerlocation is registered. Fix situaton when no game endtime is defined

testing
Burathar 4 years ago
parent
commit
1cad73b72b
  1. 2
      app/main/routes.py
  2. 26
      app/static/assets/geolocation_utils.js
  3. 3
      app/static/assets/leaflet/utils.js
  4. 12
      app/templates/game_owner_dashboard.html
  5. 12
      app/templates/game_player.html
  6. 31
      app/templates/player_base.html

2
app/main/routes.py

@ -143,7 +143,7 @@ def get_user_locations(game, username, mode, last_update): @@ -143,7 +143,7 @@ def get_user_locations(game, username, mode, last_update):
if user is None:
return None
if mode == 'accumulative':
if game.end_time < last_update:
if game.end_time or datetime.min < last_update:
return []
locations = user.locations_during_game(game)
if not locations:

26
app/static/assets/geolocation_utils.js

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
function getPosition(locationHandler){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(locationHandler, showError);
} else {
console.log('Geolocation is not supported by this browser.')
}
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
console.log("User denied the request for Geolocation.")
alert("Please refresh page and allow location sharing, otherwise the game won't work :'(")
break;
case error.POSITION_UNAVAILABLE:
console.log("Location information is unavailable.")
break;
case error.TIMEOUT:
console.log("The request to get user location timed out.")
break;
case error.UNKNOWN_ERROR:
console.log("An unknown error occurred.")
break;
}
}

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

@ -122,6 +122,9 @@ function pollLocations(url, requestedUsers, mode, playerLocations, responseHandl @@ -122,6 +122,9 @@ function pollLocations(url, requestedUsers, mode, playerLocations, responseHandl
}
function get_latest_date(playerLocations){
if (playerLocations.length == 0){
return new Date('0001-01-01T00:00:00Z');
}
return new Date(Math.max.apply(null, playerLocations.map(function(e) {
return new Date(e.timestamp_utc);
})));

12
app/templates/game_owner_dashboard.html

@ -129,6 +129,15 @@ @@ -129,6 +129,15 @@
}
}
function sendLocation(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(postCoordinates, showError);
} else {
console.log('Geolocation is not supported by this browser.')
}
}
// Poll Locations
usernames = JSON.parse('{{ json.dumps(game.usernames())|safe }}')
setInterval(function() {
@ -138,7 +147,8 @@ @@ -138,7 +147,8 @@
'accumulative',
players,
handleResponse
)}, 30 * 1000);
)
}, 30 * 1000);
function handleResponse(data){
data.forEach(function (location) {

12
app/templates/game_player.html

@ -87,26 +87,29 @@ @@ -87,26 +87,29 @@
updateMarkers();
var polyline;
updatePolyline();
// zoom the map to the polyline
if(polyline != undefined){
map.fitBounds(polyline.getBounds(), {
maxZoom : 13
});
}
function updateMarkers(){
if(markers != undefined){
markers.forEach(function(marker){
marker.remove()
});
}
markers = []
}
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)
}
}
function updatePolyline(){
if(polyline != undefined){
@ -144,13 +147,16 @@ @@ -144,13 +147,16 @@
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();
}
});

31
app/templates/player_base.html

@ -8,18 +8,9 @@ @@ -8,18 +8,9 @@
{% block scripts %}
{{ super() }}
<script>
$(document).ready(sendLocation)
$(document).ready(getPosition(postCoordinates))
function sendLocation(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(postCoordinates, showError);
} else {
console.log('Geolocation is not supported by this browser.')
}
}
setInterval(function() {sendLocation()}, 65 * 1000);
setInterval(function() {getPosition(postCoordinates)}, 65 * 1000);
function postCoordinates(position) {
$.ajax({
@ -45,23 +36,5 @@ $.ajaxSetup({ @@ -45,23 +36,5 @@ $.ajaxSetup({
}
})
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
console.log("User denied the request for Geolocation.")
alert("Please refresh page and allow location sharing, otherwise the game won't work :'(")
break;
case error.POSITION_UNAVAILABLE:
console.log("Location information is unavailable.")
break;
case error.TIMEOUT:
console.log("The request to get user location timed out.")
break;
case error.UNKNOWN_ERROR:
console.log("An unknown error occurred.")
break;
}
}
</script>
{% endblock %}
Loading…
Cancel
Save