biketrack-plainjs/map.js
2022-08-17 11:32:42 +02:00

50 lines
1.4 KiB
JavaScript

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(){
console.log("prepare")
var route = getAllRoutes('coordinates');
return route;
}
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];
//var marker = L.marker([49.41607523,8.67220049]).addTo(map);
polyline = L.polyline(current_route, {color: color[i]}).addTo(map);
var currentime = await getCurrentTime();
// does stuff ??
var ul = document.getElementById("list");
var li = document.createElement("li");
li.appendChild(document.createTextNode("Last travelled route on: " + currentime + "" ));
ul.appendChild(li);
//important for maps
map.fitBounds(polyline.getBounds());
map.fitBounds(polyline.getBounds());
return currentime;
}
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();
}