map.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. {% extends "layout.html" %}
  2. {% block head %}
  3. {{ super() }}
  4. <!-- Leaflet JS -->
  5. <script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.9/mapbox.js'></script>
  6. <!-- Leaflet CSS -->
  7. <link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.9/mapbox.css' rel='stylesheet'/>
  8. <!-- Map style -->
  9. <style>
  10. #map {
  11. height: 600px;
  12. }
  13. </style>
  14. {% endblock %}
  15. {% block content %}
  16. <h1 class="ui header">{{ title }}</h1>
  17. {% if current_user.is_authenticated %}
  18. <h2 class="ui header">Hi {{ current_user.name }}!</h2>
  19. {% endif %}
  20. <div id="map"></div>
  21. <script type="text/javascript">
  22. L.mapbox.accessToken = 'pk.eyJ1IjoibGVtYXgiLCJhIjoidnNDV1kzNCJ9.iH26jLhEuimYd6vLOO6v1g';
  23. var map = L.mapbox.map('map', 'mapbox.outdoors', {
  24. maxZoom: 20,
  25. fullscreenControl: true,
  26. zoomControl: false
  27. })
  28. var layers = {
  29. "Baisc": L.mapbox.tileLayer('mapbox.outdoors').addTo(map),
  30. "Light": L.mapbox.tileLayer('mapbox.light'),
  31. "Dark": L.mapbox.tileLayer('mapbox.dark'),
  32. "Comics": L.mapbox.tileLayer('mapbox.comic'),
  33. "Pencil": L.mapbox.tileLayer('mapbox.pencil')
  34. }
  35. L.control.layers(
  36. layers,
  37. null,
  38. {position: 'topleft'}
  39. ).addTo(map);
  40. map.setView({{[48.8534100, 2.3488000]}}, 13);
  41. markers = [];
  42. function remove_points(points){
  43. for (i in points){
  44. map.removeLayer(points[i])
  45. }
  46. }
  47. function refresh_points(){
  48. $.ajax({
  49. type: "POST",
  50. async: true,
  51. url: "/map/refresh"
  52. }).done(function(response){
  53. remove_points(markers);
  54. points = response.points;
  55. for (i in points){
  56. marker = L.marker(points[i]);
  57. markers.push(marker);
  58. marker.addTo(map);
  59. }
  60. });
  61. }
  62. refresh_points();
  63. window.setInterval(function(){
  64. refresh_points();
  65. }, 1000);
  66. </script>
  67. {% endblock %}