Clean up player marker transitions to/from visible map
This commit is contained in:
parent
ed8490fdbc
commit
fcc234bf3e
2 changed files with 42 additions and 21 deletions
|
|
@ -48,6 +48,8 @@ L.CustomMarker = L.Class.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
map.off('viewreset', this._reset, this);
|
map.off('viewreset', this._reset, this);
|
||||||
|
|
||||||
|
map = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
getLatLng: function() {
|
getLatLng: function() {
|
||||||
|
|
@ -60,6 +62,8 @@ L.CustomMarker = L.Class.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
_reset: function() {
|
_reset: function() {
|
||||||
|
if(this._map == null)
|
||||||
|
return;
|
||||||
var pos = this._map.latLngToLayerPoint(this._latlng);
|
var pos = this._map.latLngToLayerPoint(this._latlng);
|
||||||
|
|
||||||
if (this._element) {
|
if (this._element) {
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,10 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||||
player.marker = new L.CustomMarker(markerPosition, { elementCreator: function() {
|
player.marker = new L.CustomMarker(markerPosition, { elementCreator: function() {
|
||||||
var div = document.createElement('div');
|
var div = document.createElement('div');
|
||||||
var playerImage;
|
var playerImage;
|
||||||
|
|
||||||
$(player.marker._element).toggle(dynmap.world === player.location.world);
|
var markerPosition = dynmap.getProjection().fromLocationToLatLng(player.location);
|
||||||
|
player.marker.setLatLng(markerPosition);
|
||||||
|
|
||||||
$(div)
|
$(div)
|
||||||
.addClass('Marker')
|
.addClass('Marker')
|
||||||
.addClass('playerMarker')
|
.addClass('playerMarker')
|
||||||
|
|
@ -63,28 +64,39 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||||
player.healthContainer.css('display','none');
|
player.healthContainer.css('display','none');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return div;
|
return div;
|
||||||
}});
|
}});
|
||||||
dynmap.map.addLayer(player.marker);
|
if(dynmap.world === player.location.world)
|
||||||
|
dynmap.map.addLayer(player.marker);
|
||||||
});
|
});
|
||||||
$(dynmap).bind('playerremoved', function(event, player) {
|
$(dynmap).bind('playerremoved', function(event, player) {
|
||||||
// Remove the marker.
|
// Remove the marker.
|
||||||
dynmap.map.removeLayer(player.marker);
|
if(dynmap.map.hasLayer(player.marker))
|
||||||
|
dynmap.map.removeLayer(player.marker);
|
||||||
});
|
});
|
||||||
$(dynmap).bind('playerupdated', function(event, player) {
|
$(dynmap).bind('playerupdated', function(event, player) {
|
||||||
// Update the marker.
|
if(dynmap.world === player.location.world) {
|
||||||
var markerPosition = dynmap.getProjection().fromLocationToLatLng(player.location);
|
// Add if needed
|
||||||
$(player.marker._element).toggle(dynmap.world === player.location.world);
|
if(dynmap.map.hasLayer(player.marker) == false)
|
||||||
player.marker.setLatLng(markerPosition);
|
dynmap.map.addLayer(player.marker);
|
||||||
// Update health
|
else {
|
||||||
if (configuration.showplayerhealth) {
|
// Update the marker.
|
||||||
if (player.health !== undefined && player.armor !== undefined) {
|
var markerPosition = dynmap.getProjection().fromLocationToLatLng(player.location);
|
||||||
player.healthContainer.css('display','block');
|
player.marker.setLatLng(markerPosition);
|
||||||
player.healthBar.css('width', (player.health/2*5) + 'px');
|
// Update health
|
||||||
player.armorBar.css('width', (player.armor/2*5) + 'px');
|
if (configuration.showplayerhealth) {
|
||||||
} else {
|
if (player.health !== undefined && player.armor !== undefined) {
|
||||||
player.healthContainer.css('display','none');
|
player.healthContainer.css('display','block');
|
||||||
|
player.healthBar.css('width', (player.health/2*5) + 'px');
|
||||||
|
player.armorBar.css('width', (player.armor/2*5) + 'px');
|
||||||
|
} else {
|
||||||
|
player.healthContainer.css('display','none');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else if(dynmap.map.hasLayer(player.marker)) {
|
||||||
|
dynmap.map.removeLayer(player.marker);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Remove marker on start of map change
|
// Remove marker on start of map change
|
||||||
|
|
@ -93,7 +105,7 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||||
for(name in dynmap.players) {
|
for(name in dynmap.players) {
|
||||||
var player = dynmap.players[name];
|
var player = dynmap.players[name];
|
||||||
// Turn off marker - let update turn it back on
|
// 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
|
// Remove marker on map change - let update place it again
|
||||||
|
|
@ -101,9 +113,14 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||||
var name;
|
var name;
|
||||||
for(name in dynmap.players) {
|
for(name in dynmap.players) {
|
||||||
var player = dynmap.players[name];
|
var player = dynmap.players[name];
|
||||||
var markerPosition = dynmap.getProjection().fromLocationToLatLng(player.location);
|
if(dynmap.world === player.location.world) {
|
||||||
player.marker.setLatLng(markerPosition);
|
if(dynmap.map.hasLayer(player.marker) == false)
|
||||||
$(player.marker._element).toggle(dynmap.world === player.location.world);
|
dynmap.map.addLayer(player.marker);
|
||||||
|
var markerPosition = dynmap.getProjection().fromLocationToLatLng(player.location);
|
||||||
|
player.marker.setLatLng(markerPosition);
|
||||||
|
} else if(dynmap.map.hasLayer(player.marker)) {
|
||||||
|
dynmap.map.removeLayer(player.marker);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue