|
|
@ -9,6 +9,7 @@ |
|
|
|
{% endblock %} |
|
|
|
{% endblock %} |
|
|
|
|
|
|
|
|
|
|
|
{% block app_content %} |
|
|
|
{% block app_content %} |
|
|
|
|
|
|
|
<meta name="csrf-token" content="{{ csrf_token() }}"> |
|
|
|
<h1>Player: {{ player.user.name }}</h1> |
|
|
|
<h1>Player: {{ player.user.name }}</h1> |
|
|
|
<hr> |
|
|
|
<hr> |
|
|
|
<div class="row"> |
|
|
|
<div class="row"> |
|
|
@ -82,20 +83,93 @@ |
|
|
|
locations = [] |
|
|
|
locations = [] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < locations.length; i++) { |
|
|
|
var markers, lastMarker; |
|
|
|
addPlayerMarker(map, locations[i]) |
|
|
|
updateMarkers(); |
|
|
|
|
|
|
|
var polyline; |
|
|
|
|
|
|
|
updatePolyline(); |
|
|
|
|
|
|
|
// zoom the map to the polyline |
|
|
|
|
|
|
|
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) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (locations.length > 0) { |
|
|
|
function updatePolyline(){ |
|
|
|
var polyline = L.polyline(locations.map(l => [l.latitude, l.longitude]), { |
|
|
|
if(polyline != undefined){ |
|
|
|
|
|
|
|
map.removeLayer(polyline) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (locations.length == 0) { return } |
|
|
|
|
|
|
|
polyline = L.polyline(locations.map(l => [l.latitude, l.longitude]), { |
|
|
|
color: 'blue', |
|
|
|
color: 'blue', |
|
|
|
opacity: 0.6, |
|
|
|
opacity: 0.6, |
|
|
|
}).addTo(map); |
|
|
|
}).addTo(map); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// zoom the map to the polyline |
|
|
|
// Poll Locations |
|
|
|
map.fitBounds(polyline.getBounds(), { |
|
|
|
var csrftoken = $('meta[name=csrf-token]').attr('content') |
|
|
|
maxZoom : 13 |
|
|
|
$.ajaxSetup({ |
|
|
|
|
|
|
|
beforeSend: function(xhr, settings) { |
|
|
|
|
|
|
|
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) { |
|
|
|
|
|
|
|
xhr.setRequestHeader("X-CSRFToken", csrftoken) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get_newest_date(locations){ |
|
|
|
|
|
|
|
return new Date(Math.max.apply(null, locations.map(function(e) { |
|
|
|
|
|
|
|
return new Date(e.timestamp_utc); |
|
|
|
|
|
|
|
}))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setInterval(function() {pollLocations()}, 10 * 1000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function pollLocations() { |
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
|
|
|
|
type: "POST", |
|
|
|
|
|
|
|
url: "{{ url_for('main.poll_locations', game_name=player.game.name) }}", |
|
|
|
|
|
|
|
data: JSON.stringify({ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requested_users: ['{{ player.user.name }}'], |
|
|
|
|
|
|
|
mode: 'accumulative', |
|
|
|
|
|
|
|
last_update: moment(get_newest_date(locations)).format("YYYY-MM-DD HH:mm:ss:SSSS") |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
contentType: "application/json; charset=utf-8", |
|
|
|
|
|
|
|
dataType: 'json', |
|
|
|
|
|
|
|
success: handleResponse, |
|
|
|
|
|
|
|
error: function(error) { |
|
|
|
|
|
|
|
console.log(error); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleResponse(data){ |
|
|
|
|
|
|
|
data.filter(item => item.latitude && item.longitude && item.timestamp_utc && item.username) |
|
|
|
|
|
|
|
.forEach(function (item, index) { |
|
|
|
|
|
|
|
if (item.username == '{{ player.user.name }}' && new Date(item.timestamp_utc) > get_newest_date(locations) ){ |
|
|
|
|
|
|
|
lastItem = locations[locations.length-1] |
|
|
|
|
|
|
|
if (lastItem.latitude == item.latitude && lastItem.longitude == item.longitude){ |
|
|
|
|
|
|
|
lastItem.timestamp_utc = item.timestamp_utc |
|
|
|
|
|
|
|
} else{ |
|
|
|
|
|
|
|
locations.push(item) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
updatePolyline() |
|
|
|
|
|
|
|
updateMarkers() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Ajax for Generate Code button |
|
|
|
//Ajax for Generate Code button |
|
|
|