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){
return playerMarker 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(){ function getMap(){
var map = L.map( 'map', { var map = L.map( 'map', {
center: [52.2, 5.3], center: [52.2, 5.3],

2
app/templates/game_bunny_dashboard.html

@ -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 %}
@ -57,6 +56,7 @@
{% 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() map = getMap()

12
app/templates/game_owner_dashboard.html

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

1
app/templates/player_base.html

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

Loading…
Cancel
Save