hide players not in the current layer

This commit is contained in:
NatureFreshMilk 2019-03-22 13:16:28 +01:00
parent b545f3580a
commit 1ba10ec549

View File

@ -52,10 +52,29 @@ var PlayerOverlay = L.LayerGroup.extend({
return marker; return marker;
}, },
isPlayerInCurrentLayer: function(player){
var mapLayer = this.layerMgr.getCurrentLayer()
return (player.pos.y >= mapLayer.from && player.pos.y <= mapLayer.to)
},
onMinetestUpdate: function(info){ onMinetestUpdate: function(info){
var self = this; var self = this;
this.players.forEach(function(player){ this.players.forEach(function(player){
var isInLayer = self.isPlayerInCurrentLayer(player);
if (!isInLayer){
if (self.currentObjects[player.name]){
//player is displayed and not on the layer anymore
//Remove the marker and reference
self.currentObjects[player.name].remove();
delete self.currentObjects[player.name];
}
return;
}
if (self.currentObjects[player.name]){ if (self.currentObjects[player.name]){
//marker exists //marker exists
self.currentObjects[player.name].setLatLng([player.pos.z, player.pos.x]); self.currentObjects[player.name].setLatLng([player.pos.z, player.pos.x]);
@ -91,7 +110,10 @@ var PlayerOverlay = L.LayerGroup.extend({
var mapLayer = this.layerMgr.getCurrentLayer() var mapLayer = this.layerMgr.getCurrentLayer()
this.players.forEach(function(player){ this.players.forEach(function(player){
//TODO: filter layer if (!self.isPlayerInCurrentLayer(player)){
//not in current layer
return;
}
var marker = self.createMarker(player); var marker = self.createMarker(player);
marker.addTo(self); marker.addTo(self);