From 47c2fab7410d753068c7a51005ab41eefa18f365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20W=C3=B6lpert?= Date: Mon, 18 Jul 2022 16:53:53 +0200 Subject: [PATCH] added getAllCoordinates function --- execution.js | 11 +++++++ functions.js | 35 ++++++++++++++++++++-- index.html | 83 ++++++++++++++++++++++++++++------------------------ map.js | 48 +++--------------------------- 4 files changed, 93 insertions(+), 84 deletions(-) create mode 100644 execution.js diff --git a/execution.js b/execution.js new file mode 100644 index 0000000..c4d8217 --- /dev/null +++ b/execution.js @@ -0,0 +1,11 @@ +(async () =>{ + console.log( getAllCoordinates('route2')) + + + + +//var polyline = L.polyline(newArray, {color: 'red'}).addTo(map); +//map.fitBounds(polyline.getBounds()); +//connectDB('route2') + +})(); \ No newline at end of file diff --git a/functions.js b/functions.js index 6fbda00..947ff22 100644 --- a/functions.js +++ b/functions.js @@ -23,8 +23,8 @@ initIPFS() const address = db.address console.log(address) console.log(db.address.toString()) - //await db.put('2022-07-01T10:49:07', '49.41185089/8.67646861') - //await db.put('2022-07-01T10:49:12', '49.41166303/8.67652893') + await db.put('2022-07-01T10:49:07', '49.41185089/8.67646861') + await db.put('2022-07-01T10:49:12', '49.41166303/8.67652893') let csv = "./new.csv" const value = db.all //console.log(value) @@ -54,6 +54,37 @@ async function connectDB(dbname){ const route2 = db_route2.all console.log(route2); } +async function getActualCoordinates(){ + + +} +async function getAllCoordinates(dbname){ + + // creater db with name db2 +var db2 = await createDb(dbname) +const all_coordinates = db2.all +// coordinates in this schema 49.123/8.2311 +var coordinates = Object.values(all_coordinates) +// parse to string for split and then split by / +var coordinate_string = coordinates.toString() +var between_string = coordinate_string.split("/") +var final_string = between_string.toString() +//comma string looks now like this : 49.1212,8.1231,49.1231, ... +var comma_string = final_string.split(',') +// create new Array and put string back in to array for using paths/polylines with leafleat +var newArray =[]; +// use for loop for iterating over string and put it in the right order +for (var i = 0; i < comma_string.length; i++) { + + var increment = i+1; + newArray.push([comma_string[i], comma_string[increment]]) + increment = increment+1 + i = i+1 + +} +console.log(newArray); +return newArray; +} diff --git a/index.html b/index.html index 68c744f..baf1e5b 100644 --- a/index.html +++ b/index.html @@ -8,10 +8,46 @@ integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ==" crossorigin=""> + Track your bike +
-
-
-
-

Statistics

- -
- Route X -
-
- -
-
-
- kilometers traveled - 2 Km -
-
- traveled time - 2 min -
- -
- -
-
- -
-
-
-
-
- @@ -92,13 +98,16 @@ - - var data = jQuery.csv.toObjects(csv); + - + - diff --git a/map.js b/map.js index fdcc311..bac276c 100644 --- a/map.js +++ b/map.js @@ -1,58 +1,18 @@ -(async () =>{ -var db2 = await createDb('route2') -const value = db2.all -console.log(value) -//loadRoute('route2') -//loadRoute('route2') -console.log(Object.keys(value)) -console.log(Object.values(value)) -var coordinates = Object.values(value) -var mystring = coordinates.toString() -console.log(mystring) -var hope = mystring.split("/") -console.log(typeof(hope)) -//console.log(hope) -var my2string = hope.toString() -var comma = my2string.split(',') -console.log("this is comma:"+comma) -console.log(comma) -var newArray =[]; -for (var i = 0; i < comma.length; i++) { - var plus = 1 - //var newArray = [[]]; - //newArray[i] += [comma[i], comma[i+plus] ] - var increment = i+1; - console.log(i) - console.log("increment" +increment) - newArray.push([comma[i], comma[increment]]) - increment = increment+1 - i = i+1 - //newArray[i][i+plus] +=comma[i+plus] -} -console.log(newArray); var map = L.map('map').setView([49.416075235, 8.6722049], 13); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { zoom: 44, attribution: '© OpenStreetMap' -}).addTo(map); - -var polyline = L.polyline(newArray, {color: 'red'}).addTo(map); -map.fitBounds(polyline.getBounds()); -//connectDB('route2') - -})(); - - +}).addTo(map) - L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map); + //L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map); //var marker = L.marker([49.41607523,8.67220049]).addTo(map); - var polyline = L.polyline(newArray, {color: 'red'}).addTo(map); - map.fitBounds(polyline.getBounds()); + //var polyline = L.polyline(newArray, {color: 'red'}).addTo(map); + //map.fitBounds(polyline.getBounds());