From 370e8bdedbb9e4b75ac423a6f95cdc7f78c4530e Mon Sep 17 00:00:00 2001 From: Sylvain Gay Date: Mon, 12 Sep 2022 09:29:28 +0200 Subject: [PATCH] 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;