mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 13:15:30 +01:00
Clean up player marker transitions to/from visible map
This commit is contained in:
parent
58df3a8441
commit
95c9520cc9
@ -48,6 +48,8 @@ L.CustomMarker = L.Class.extend({
|
||||
}
|
||||
|
||||
map.off('viewreset', this._reset, this);
|
||||
|
||||
map = null;
|
||||
},
|
||||
|
||||
getLatLng: function() {
|
||||
@ -60,6 +62,8 @@ L.CustomMarker = L.Class.extend({
|
||||
},
|
||||
|
||||
_reset: function() {
|
||||
if(this._map == null)
|
||||
return;
|
||||
var pos = this._map.latLngToLayerPoint(this._latlng);
|
||||
|
||||
if (this._element) {
|
||||
|
@ -7,7 +7,8 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||
var div = document.createElement('div');
|
||||
var playerImage;
|
||||
|
||||
$(player.marker._element).toggle(dynmap.world === player.location.world);
|
||||
var markerPosition = dynmap.getProjection().fromLocationToLatLng(player.location);
|
||||
player.marker.setLatLng(markerPosition);
|
||||
|
||||
$(div)
|
||||
.addClass('Marker')
|
||||
@ -63,18 +64,25 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||
player.healthContainer.css('display','none');
|
||||
}
|
||||
}
|
||||
|
||||
return div;
|
||||
}});
|
||||
if(dynmap.world === player.location.world)
|
||||
dynmap.map.addLayer(player.marker);
|
||||
});
|
||||
$(dynmap).bind('playerremoved', function(event, player) {
|
||||
// Remove the marker.
|
||||
if(dynmap.map.hasLayer(player.marker))
|
||||
dynmap.map.removeLayer(player.marker);
|
||||
});
|
||||
$(dynmap).bind('playerupdated', function(event, player) {
|
||||
if(dynmap.world === player.location.world) {
|
||||
// Add if needed
|
||||
if(dynmap.map.hasLayer(player.marker) == false)
|
||||
dynmap.map.addLayer(player.marker);
|
||||
else {
|
||||
// Update the marker.
|
||||
var markerPosition = dynmap.getProjection().fromLocationToLatLng(player.location);
|
||||
$(player.marker._element).toggle(dynmap.world === player.location.world);
|
||||
player.marker.setLatLng(markerPosition);
|
||||
// Update health
|
||||
if (configuration.showplayerhealth) {
|
||||
@ -86,6 +94,10 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||
player.healthContainer.css('display','none');
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(dynmap.map.hasLayer(player.marker)) {
|
||||
dynmap.map.removeLayer(player.marker);
|
||||
}
|
||||
});
|
||||
// Remove marker on start of map change
|
||||
$(dynmap).bind('mapchanging', function(event) {
|
||||
@ -93,7 +105,7 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||
for(name in dynmap.players) {
|
||||
var player = dynmap.players[name];
|
||||
// Turn off marker - let update turn it back on
|
||||
$(player.marker._element).toggle(false);
|
||||
dynmap.map.removeLayer(player.marker);
|
||||
}
|
||||
});
|
||||
// Remove marker on map change - let update place it again
|
||||
@ -101,9 +113,14 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||
var name;
|
||||
for(name in dynmap.players) {
|
||||
var player = dynmap.players[name];
|
||||
if(dynmap.world === player.location.world) {
|
||||
if(dynmap.map.hasLayer(player.marker) == false)
|
||||
dynmap.map.addLayer(player.marker);
|
||||
var markerPosition = dynmap.getProjection().fromLocationToLatLng(player.location);
|
||||
player.marker.setLatLng(markerPosition);
|
||||
$(player.marker._element).toggle(dynmap.world === player.location.world);
|
||||
} else if(dynmap.map.hasLayer(player.marker)) {
|
||||
dynmap.map.removeLayer(player.marker);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user