You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.6 KiB

  1. var map = L.map('map', { zoomControl: false }).setView([45.516, -122.660], 14, null, null, 24);
  2. L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
  3. attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
  4. maxZoom: 18,
  5. id: 'mapbox.streets',
  6. accessToken: 'pk.eyJ1IjoiYWFyb25wayIsImEiOiI1T0tpNjdzIn0.OQjXyI3xSt8Dj8na3l90Sg'
  7. }).addTo(map);
  8. new L.Control.Zoom({ position: 'topleft' }).addTo(map);
  9. var geojsonLineOptions = {
  10. color: "#0033ff",
  11. weight: 4,
  12. opacity: 0.5
  13. };
  14. var startIcon = L.icon({
  15. iconUrl: '/assets/map-pin-start.png',
  16. iconSize: [18,28],
  17. iconAnchor: [9,28]
  18. });
  19. // Load the current location and show on the map
  20. var currentLocationMarker;
  21. function getCurrentLocation() {
  22. $.getJSON("/share/current.json?token="+$("#share_token").val(), function(data){
  23. if(data.data) {
  24. moveMarkerToPosition(data.data);
  25. map.setView(currentLocationMarker.getLatLng());
  26. }
  27. setTimeout(getCurrentLocation, 5000);
  28. });
  29. }
  30. getCurrentLocation();
  31. function moveMarkerToPosition(feature) {
  32. if(feature && feature.geometry) {
  33. var coord = pointFromGeoJSON(feature.geometry.coordinates);
  34. if(coord) {
  35. if(!currentLocationMarker) {
  36. currentLocationMarker = L.marker(coord).addTo(map);
  37. } else {
  38. currentLocationMarker.setLatLng(coord);
  39. }
  40. }
  41. }
  42. }
  43. function pointFromGeoJSON(geo) {
  44. return L.latLng(geo[1], geo[0])
  45. }