factorise moving and change color
This commit is contained in:
parent
88ecea941f
commit
1154f13962
3 changed files with 24 additions and 42 deletions
|
@ -3,7 +3,6 @@ var server = location.hostname;
|
|||
var port = location.port;
|
||||
var socket;
|
||||
var id;
|
||||
var colors = {};
|
||||
var markers = {};
|
||||
|
||||
var CircleIcon = L.Icon.extend({
|
||||
|
@ -57,25 +56,6 @@ function setup_socket_common(){
|
|||
socket = io.connect({rejectUnauthorized: false, auth: {id: id}},
|
||||
protocol+"://"+server+":"+port);
|
||||
|
||||
socket.on("moving", function(data){
|
||||
console.log("moving", data);
|
||||
if(!(data.id in markers)){
|
||||
if(!(data.id in colors))
|
||||
colors[data.id] = 0;
|
||||
var icon;
|
||||
if(data.id == id)
|
||||
icon = self_icons[colors[data.id]];
|
||||
else
|
||||
icon = icons[colors[data.id]];
|
||||
markers[data.id] = L.marker(data.position, {"icon": icon}).addTo(map);
|
||||
if(data.id == id)
|
||||
markers[data.id].setZIndexOffset(10000);
|
||||
markers[data.id].bindPopup(data.id);
|
||||
} else{
|
||||
markers[data.id].setLatLng(data.position);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("popup", function(data){
|
||||
alert(data.content);
|
||||
});
|
||||
|
@ -91,24 +71,34 @@ function setup_socket_common(){
|
|||
}
|
||||
|
||||
function setup_socket_not_admin(){
|
||||
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){
|
||||
socket.on("moving", function(data){
|
||||
console.log("moving", data);
|
||||
if(!(data.id in markers)){
|
||||
var icon;
|
||||
if(data.id == id)
|
||||
icon = self_icons[data.color];
|
||||
else
|
||||
icon = icons[data.color];
|
||||
markers[data.id] = L.marker(data.position, {"icon": icon}).addTo(map);
|
||||
markers[data.id].color = data.color; //do we really need to store this ?
|
||||
if(data.id == id)
|
||||
markers[data.id].setZIndexOffset(10000);
|
||||
markers[data.id].bindPopup(data.id);
|
||||
} else{
|
||||
markers[data.id].setLatLng(data.position);
|
||||
markers[data.id].color = data.color;
|
||||
if(data.id == id)
|
||||
if(data.color == -1)
|
||||
markers[data.id].setIcon(self_invisible);
|
||||
else
|
||||
markers[data.id].setIcon(self_icons[data.color]);
|
||||
else
|
||||
markers[data.id].setIcon(self_icons[data.color]);
|
||||
else
|
||||
if(data.color == -1)
|
||||
markers[data.id].setLatLng([0,0]);
|
||||
else
|
||||
markers[data.id].setIcon(icons[data.color]);
|
||||
}
|
||||
});
|
||||
markers[data.id].setIcon(icons[data.color]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue