From 45be8fc7773090670b23606c88c3a8ac3fe76beb Mon Sep 17 00:00:00 2001 From: catvayor Date: Fri, 9 Sep 2022 17:16:20 +0200 Subject: [PATCH 1/2] send old data to new client --- traque.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/traque.js b/traque.js index ee692c6..d31676b 100644 --- a/traque.js +++ b/traque.js @@ -59,6 +59,7 @@ io.sockets.on('connection', function(socket){ equipes.push(socket); socket.shown = true; socket.color = 0; + socket.position = [0,0]; socket.on('geoLoc', function(d){ socket.position = d.position; if(socket.shown) @@ -71,11 +72,11 @@ io.sockets.on('connection', function(socket){ socket.shown = false; else{ if(!socket.shown) - for(i in equipes) + for(i in equipes) equipes[i].emit('moving', {"id": socket.id, "position": socket.position}); socket.shown = true; } - for(i in equipes) + for(i in equipes) equipes[i].emit('changeColor', {"id": socket.id, "color": d.color}); }); socket.on('setName', function(d){ @@ -83,7 +84,15 @@ io.sockets.on('connection', function(socket){ for(i in equipes) equipes[i].emit('setName', {"id": socket.id, "name": d.name}); }); + socket.emit('yourId', {"id": socket.id}); + for(i in equipes){ + if(!equipes[i].shown) + continue; + socket.emit('setName', {"id": i, "name": equipes[i].name}); + socket.emit('changeColor', {"id": i, "color": equipes[i].color}); + socket.emit('moving', {"id": i, "position": equipes[i].position}); + } }); console.log("Launch server"); From 370e8bdedbb9e4b75ac423a6f95cdc7f78c4530e Mon Sep 17 00:00:00 2001 From: Sylvain Gay Date: Mon, 12 Sep 2022 09:29:28 +0200 Subject: [PATCH 2/2] Issue #3 -- implemented invisibility --- map.html | 14 +++++++++++++- traque.js | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/map.html b/map.html index e8c5c5d..b2dd1df 100644 --- a/map.html +++ b/map.html @@ -59,6 +59,7 @@ }) ]; var self_icons = icons; + var self_invisible_icon = icons[1]; ////////////////////////////////////////////////////////////////////////////// // INIT MAP @@ -91,8 +92,17 @@ socket.on("changeColor", function(data){ console.log("changeColor", data); + if(data.id in colors && colors[data.id] == -1 && data.id in markers) + markers[data.id].addTo(map); colors[data.id] = data.color; - if(data.id in markers){ + if(data.color == -1){ + if(data.id in markers){ + if(data.id == id) + markers[data.id].setIcon(self_invisible_icon); + else + markers[data.id].remove(); + } + } else if(data.id in markers){ if(data.id == id) markers[data.id].setIcon(self_icons[data.color]); else @@ -111,6 +121,8 @@ else icon = icons[colors[data.id]]; markers[data.id] = L.marker(data.position, {"icon": icon}).addTo(map); + if(colors[data.id] == -1) + markers[data.id].remove(); if(data.id in names) markers[data.id].bindPopup(names[data.id]); } else{ diff --git a/traque.js b/traque.js index d31676b..4337589 100644 --- a/traque.js +++ b/traque.js @@ -65,6 +65,8 @@ io.sockets.on('connection', function(socket){ if(socket.shown) for(i in equipes) equipes[i].emit('moving', {"id": socket.id, "position": d.position}); + else + socket.emit('moving', {"id": socket.id, "position": d.position}); }); socket.on('changeColor', function(d){ socket.color = d.color - 0;