Separated playermarkers to a component.
This commit is contained in:
parent
7464e5b809
commit
6eface57ae
4 changed files with 43 additions and 32 deletions
40
web/js/playermarkers.js
Normal file
40
web/js/playermarkers.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||
return {
|
||||
initialize: function() {
|
||||
$(dynmap).bind('playeradded', function(event, player) {
|
||||
// Create the player-marker.
|
||||
var markerPosition = dynmap.map.getProjection().fromWorldToLatLng(player.location.x, player.location.y, player.location.z);
|
||||
player.marker = new CustomMarker(markerPosition, dynmap.map, function(div) {
|
||||
var playerImage;
|
||||
$(div)
|
||||
.addClass('Marker')
|
||||
.addClass('playerMarker')
|
||||
.append(playerImage = $('<img/>')
|
||||
.attr({ src: 'images/player.png' }))
|
||||
.append($('<span/>')
|
||||
.addClass('playerName')
|
||||
.text(player.name));
|
||||
|
||||
if (configuration.showplayerfaces) {
|
||||
getMinecraftHead(player.name, 32, function(head) {
|
||||
$(head)
|
||||
.addClass('playericon')
|
||||
.prependTo(div);
|
||||
playerImage.remove();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
$(dynmap).bind('playerremoved', function(event, player) {
|
||||
// Remove the marker.
|
||||
player.marker.remove();
|
||||
});
|
||||
$(dynmap).bind('playerupdated', function(event, player) {
|
||||
// Update the marker.
|
||||
var markerPosition = dynmap.map.getProjection().fromWorldToLatLng(player.location.x, player.location.y, player.location.z);
|
||||
player.marker.toggle(dynmap.world === player.location.world);
|
||||
player.marker.setPosition(markerPosition);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue