diff --git a/index.js b/index.js index 36f76722b78ccf59877741a15c4e2e720df16f9e..d6c1d0560a6c3dd9582c5fa96abd9ada1074b908 100644 --- a/index.js +++ b/index.js @@ -56,6 +56,7 @@ io.on('connection', socket => { // server automatically listens for "connection" lat: row.latitude, lng: row.longitude, id: row.id_arret, + destination: row.destination, } })); // for (row of positions) { @@ -86,6 +87,14 @@ io.on('connection', socket => { // server automatically listens for "connection" // }, err => console.log(err)); // }); + + socket.on('get-road', line => { + getPreciseRoad(line).then( coords => { + socket.emit('road', coords); + }); + }); + + socket.on('get-demo', () => { @@ -169,9 +178,25 @@ getStopsForLine = (line) => { else resolve(rows); }); }); +} +getPreciseRoad = (line) => { + return new Promise((resolve, reject) => { + con.query(`SELECT direction, ST_AsGeoJSON(parcours) as coords FROM trace WHERE ligne LIKE "${line}"`, (err, res) => { + if (err) { + console.log(err); + reject(err); + } else { + resolve(res[0]) + console.log(res); + } + }) + }); } + + + sendPositionToDb = (p, id) => {