biketrack-plainjs/map.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-07-18 15:18:07 +02:00
2022-07-19 16:26:53 +02:00
var map = L.map('map').setView([49.41607523, 8.672200499], 19);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 44,
attribution: '© OpenStreetMap'
}).addTo(map);
// helper function for displayRoute()
async function prepare(){
2022-08-02 15:58:18 +02:00
console.log("prepare")
2022-08-17 11:32:42 +02:00
var route = getAllRoutes('coordinates');
2022-08-02 15:58:18 +02:00
return route;
2022-07-19 16:26:53 +02:00
}
2022-08-17 11:32:42 +02:00
async function displayLastRoute() {
clearMap()
//color theming
let color = ["blue","red","green","purple","cyan","yellow"];
var i = Math.floor(Math.random() * 5) ;
let current = await prepare();
console.log("Length:")
console.log(current.length);
var len = current.length - 1;
const current_route = current[len];
2022-08-02 15:58:18 +02:00
//var marker = L.marker([49.41607523,8.67220049]).addTo(map);
2022-08-17 11:32:42 +02:00
polyline = L.polyline(current_route, {color: color[i]}).addTo(map);
2022-08-02 15:58:18 +02:00
var currentime = await getCurrentTime();
// does stuff ??
var ul = document.getElementById("list");
var li = document.createElement("li");
2022-08-17 11:32:42 +02:00
li.appendChild(document.createTextNode("Last travelled route on: " + currentime + "" ));
2022-07-22 13:03:03 +02:00
ul.appendChild(li);
2022-08-02 15:58:18 +02:00
//important for maps
2022-08-17 11:32:42 +02:00
map.fitBounds(polyline.getBounds());
map.fitBounds(polyline.getBounds());
2022-08-02 15:58:18 +02:00
return currentime;
2022-07-19 16:26:53 +02:00
}
2022-08-17 11:32:42 +02:00
2022-07-19 16:26:53 +02:00
async function showBike(){
var current_cord = await getCurrentCoordinate()
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
L.marker(current_cord).addTo(map)
.bindPopup(' Your BIKE!')
.openPopup();
}