performance improvements
This commit is contained in:
parent
bad67e5fc8
commit
5cb0a6c478
50
functions.js
50
functions.js
@ -119,8 +119,8 @@ async function createDb(){
|
||||
//console.log(newArray)
|
||||
return newArray;
|
||||
}
|
||||
|
||||
|
||||
//array to store routes absolute
|
||||
var Absolute_Route = [];
|
||||
async function getAllRoutes(){
|
||||
var buffer_for_i = 0;
|
||||
var db2 = await createDb()
|
||||
@ -180,7 +180,10 @@ async function getAllRoutes(){
|
||||
return parseFloat(elem2);
|
||||
});
|
||||
});
|
||||
|
||||
// maybe in loop?
|
||||
Absolute_Route[0] = route0;
|
||||
Absolute_Route[1] = route1;
|
||||
console.log("routes written in buffer")
|
||||
return [route0, route1];
|
||||
}
|
||||
|
||||
@ -198,6 +201,7 @@ async function createlistitem() {
|
||||
ul.appendChild(li);
|
||||
}
|
||||
async function clearMap() {
|
||||
console.log("clearing map")
|
||||
for(i in map._layers) {
|
||||
if(map._layers[i]._path != undefined) {
|
||||
try {
|
||||
@ -210,19 +214,21 @@ async function clearMap() {
|
||||
}
|
||||
|
||||
}
|
||||
async function allRoutes(number_of_ze_route) {
|
||||
async function allRoutes(number_of_the_route) {
|
||||
|
||||
//color theming
|
||||
var color = ["blue","red","green","purple","gray","yellow"];
|
||||
var i = Math.floor(Math.random() * 5) ;
|
||||
console.log("calling prepare")
|
||||
let current = await prepare();
|
||||
const current_route = current[number_of_ze_route];
|
||||
clearMap()
|
||||
const current_route = current[number_of_the_route];
|
||||
|
||||
clearMap();
|
||||
polyline = L.polyline(current_route, {color: color[i]}).addTo(map);
|
||||
var currentime = await getCurrentTime();
|
||||
var ul = document.getElementById("list");
|
||||
var li = document.createElement("li");
|
||||
li.appendChild(document.createTextNode("Route "+ (number_of_ze_route + 1) + " was travelled on: " + currentime + "" ));
|
||||
li.appendChild(document.createTextNode("Route "+ (number_of_the_route + 1) + " was travelled on: " + currentime + "" ));
|
||||
ul.appendChild(li);
|
||||
|
||||
//important for maps
|
||||
@ -231,30 +237,48 @@ async function allRoutes(number_of_ze_route) {
|
||||
|
||||
return currentime;
|
||||
}
|
||||
async function singleRoute(route_nr){
|
||||
const current_route = Absolute_Route[route_nr];
|
||||
console.log(Absolute_Route[route_nr]);
|
||||
var color = ["blue","red","green","purple","gray","yellow"];
|
||||
var i = Math.floor(Math.random() * 5) ;
|
||||
clearMap();
|
||||
console.log("painting map");
|
||||
polyline = L.polyline(current_route, {color: color[i]}).addTo(map);
|
||||
//var currentime = await getCurrentTime();
|
||||
var ul = document.getElementById("list");
|
||||
var li = document.createElement("li");
|
||||
ul.appendChild(li);
|
||||
|
||||
//important for maps
|
||||
map.fitBounds(polyline.getBounds());
|
||||
map.fitBounds(polyline.getBounds());
|
||||
console.log("finished singelRoute()");
|
||||
}
|
||||
async function showRoutes(){
|
||||
console.log("Calling getAllRoutes")
|
||||
var len_of_Routes = await getAllRoutes();
|
||||
var len = len_of_Routes.length ;
|
||||
console.log("Gotten all routes");
|
||||
console.log(len);
|
||||
|
||||
var i = 0;
|
||||
|
||||
|
||||
console.log("this is i: " + i)
|
||||
console.log("this is len: " + len)
|
||||
console.log("creating buttons")
|
||||
let btn0 = document.createElement("button");
|
||||
btn0.innerHTML = ("Route 1");
|
||||
btn0.onclick = function () {
|
||||
allRoutes((0));
|
||||
singleRoute(0);
|
||||
};
|
||||
let btn1 = document.createElement("button");
|
||||
btn1.innerHTML = ("Route 2");
|
||||
btn1.onclick = function () {
|
||||
allRoutes((1));
|
||||
singleRoute(1);
|
||||
};
|
||||
|
||||
i = i + 1;
|
||||
document.body.appendChild(btn0);
|
||||
document.body.appendChild(document.createElement('br'));
|
||||
document.body.appendChild(btn1);
|
||||
console.log("Finsihed showing routes")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user