Browse Source

add own location to owner dashboard

testing
Burathar 4 years ago
parent
commit
982a220bc2
  1. 18
      app/static/assets/leaflet/utils.js
  2. 2
      app/templates/game_bunny_dashboard.html
  3. 12
      app/templates/game_owner_dashboard.html
  4. 1
      app/templates/player_base.html

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

@ -74,6 +74,24 @@ function addPlayerMarker(map, player, icon=bluePlayerIcon){ @@ -74,6 +74,24 @@ function addPlayerMarker(map, player, icon=bluePlayerIcon){
return playerMarker
}
var myLocationMarker
function updateMyLocation(position){
if(myLocationMarker == undefined){
myLocationMarker = L.marker([
position.coords.latitude,
position.coords.longitude
], {icon: greenPlayerIcon}).addTo(map)
myLocationMarker.bindTooltip('Your current location').openPopup();
}
else{
var newLocation = new L.LatLng(
position.coords.latitude,
position.coords.longitude
);
myLocationMarker.setLatLng(newLocation);
}
}
function getMap(){
var map = L.map( 'map', {
center: [52.2, 5.3],

2
app/templates/game_bunny_dashboard.html

@ -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 %}
@ -57,6 +56,7 @@ @@ -57,6 +56,7 @@
{% block scripts %}
{{ super() }}
<script src="{{ url_for('static', filename='assets/leaflet/utils.js') }}"></script>
<script type="text/javascript", crossorigin="anonymous">
// Leaflet Map
map = getMap()

12
app/templates/game_owner_dashboard.html

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
{{ 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/geolocation_utils.js') }}"></script>
{% endblock %}
{% block app_content %}
@ -110,6 +111,7 @@ @@ -110,6 +111,7 @@
objectMarkers.push([objectives[i].latitude, objectives[i].longitude])
}
var players = JSON.parse('{{ json.dumps(game.last_player_locations(), cls=location_encoder)|safe }}')
updatePlayerMarkers()
@ -129,15 +131,6 @@ @@ -129,15 +131,6 @@
}
}
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() {
@ -148,6 +141,7 @@ @@ -148,6 +141,7 @@
players,
handleResponse
)
getPosition(updateMyLocation)
}, 30 * 1000);
function handleResponse(data){

1
app/templates/player_base.html

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
{% block scripts %}
{{ super() }}
<script src="{{ url_for('static', filename='assets/geolocation_utils.js') }}"></script>
<script>
$(document).ready(getPosition(postCoordinates))

Loading…
Cancel
Save