2011-01-15 02:11:31 +01:00
|
|
|
//if (!console) console = { log: function() {} };
|
2011-01-10 23:58:39 +01:00
|
|
|
|
2011-02-06 15:09:15 +01:00
|
|
|
var maptypes = {};
|
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
function splitArgs(s) {
|
|
|
|
var r = s.split(' ');
|
|
|
|
delete arguments[0];
|
|
|
|
var obj = {};
|
|
|
|
var index = 0;
|
2011-01-15 02:11:31 +01:00
|
|
|
$.each(arguments, function(argumentIndex, argument) {
|
|
|
|
if (!argumentIndex) return;
|
2011-01-14 20:08:23 +01:00
|
|
|
var value = r[argumentIndex-1];
|
|
|
|
obj[argument] = value;
|
2011-01-15 02:11:31 +01:00
|
|
|
});
|
2011-01-14 20:08:23 +01:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
function swtch(value, options, defaultOption) {
|
|
|
|
return (options[value] || defaultOption)(value);
|
|
|
|
}
|
|
|
|
|
2011-01-12 01:28:45 +01:00
|
|
|
function DynMapType() { }
|
|
|
|
DynMapType.prototype = {
|
|
|
|
onTileUpdated: function(tile, tileName) {
|
2011-01-14 20:08:23 +01:00
|
|
|
var src = this.dynmap.getTileUrl(tileName);
|
2011-01-12 01:28:45 +01:00
|
|
|
tile.attr('src', src);
|
|
|
|
tile.show();
|
2010-12-31 13:33:51 +01:00
|
|
|
}
|
2011-01-12 01:28:45 +01:00
|
|
|
};
|
2010-12-31 13:33:51 +01:00
|
|
|
|
2011-01-12 01:28:45 +01:00
|
|
|
function MinecraftClock(element) { this.element = element; }
|
|
|
|
MinecraftClock.prototype = {
|
|
|
|
element: null,
|
|
|
|
timeout: null,
|
|
|
|
time: null,
|
|
|
|
create: function(element) {
|
|
|
|
if (!element) element = $('<div/>');
|
|
|
|
this.element = element;
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
setTime: function(time) {
|
|
|
|
if (this.timeout != null) {
|
|
|
|
window.clearTimeout(this.timeout);
|
|
|
|
this.timeout = null;
|
2010-12-31 13:33:51 +01:00
|
|
|
}
|
2011-01-12 01:28:45 +01:00
|
|
|
this.time = time;
|
|
|
|
this.element
|
2011-02-13 07:33:18 +01:00
|
|
|
.addClass((time.day <= 4) ? 'day' : 'night')
|
|
|
|
.removeClass((time.day <= 4) ? 'day' : 'night')
|
2011-01-12 01:28:45 +01:00
|
|
|
.text(this.formatTime(time));
|
|
|
|
|
|
|
|
if (this.timeout == null) {
|
|
|
|
var me = this;
|
|
|
|
this.timeout = window.setTimeout(function() {
|
|
|
|
me.timeout = null;
|
|
|
|
me.setTime(getMinecraftTime(me.time.servertime+(1000/60)));
|
2011-01-12 02:03:31 +01:00
|
|
|
}, 700);
|
2011-01-12 01:28:45 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
formatTime: function(time) {
|
|
|
|
var formatDigits = function(n, digits) {
|
|
|
|
var s = n.toString();
|
|
|
|
while (s.length < digits) {
|
|
|
|
s = '0' + s;
|
2010-12-31 13:33:51 +01:00
|
|
|
}
|
2011-01-12 01:28:45 +01:00
|
|
|
return s;
|
2010-12-31 13:33:51 +01:00
|
|
|
}
|
2011-01-12 01:28:45 +01:00
|
|
|
return formatDigits(time.hours, 2) + ':' + formatDigits(time.minutes, 2);
|
2010-12-31 13:33:51 +01:00
|
|
|
}
|
2011-01-12 01:28:45 +01:00
|
|
|
};
|
2010-12-31 13:33:51 +01:00
|
|
|
|
2011-02-13 07:25:28 +01:00
|
|
|
function MinecraftTimeOfDay(element) { this.element = element; }
|
|
|
|
MinecraftTimeOfDay.prototype = {
|
|
|
|
element: null,
|
|
|
|
create: function(element) {
|
|
|
|
if (!element) element = $('<div/>');
|
|
|
|
this.element = element;
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
setTime: function(time) {
|
|
|
|
this.element
|
|
|
|
.removeClass('time1')
|
|
|
|
.removeClass('time2')
|
|
|
|
.removeClass('time3')
|
|
|
|
.removeClass('time4')
|
|
|
|
.removeClass('time5')
|
|
|
|
.removeClass('time6')
|
|
|
|
.removeClass('time7')
|
|
|
|
.removeClass('time8')
|
|
|
|
.addClass('time' + time.day)
|
|
|
|
.html(" ‏ ")
|
|
|
|
.height(60);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function MinecraftCompass(element) { this.element = element; }
|
|
|
|
MinecraftCompass.prototype = {
|
|
|
|
element: null,
|
|
|
|
create: function(element) {
|
|
|
|
if (!element) element = $('<div/>');
|
|
|
|
this.element = element;
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
initialize: function() {
|
|
|
|
this.element.html(" ‏ ");
|
|
|
|
this.element.height(120);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
function DynMap(options) {
|
2011-02-01 15:16:54 +01:00
|
|
|
var me = this;
|
|
|
|
me.options = options;
|
|
|
|
$.getJSON(me.options.updateUrl + 'configuration', function(configuration) {
|
|
|
|
me.configure(configuration);
|
|
|
|
me.initialize();
|
2011-02-01 14:17:08 +01:00
|
|
|
})
|
2010-12-31 13:33:51 +01:00
|
|
|
}
|
2011-01-14 20:08:23 +01:00
|
|
|
DynMap.prototype = {
|
|
|
|
registeredTiles: new Array(),
|
|
|
|
clock: null,
|
|
|
|
markers: new Array(),
|
2011-01-26 00:10:42 +01:00
|
|
|
chatPopups: new Array(),
|
2011-01-14 20:08:23 +01:00
|
|
|
lasttimestamp: '0',
|
|
|
|
followingPlayer: '',
|
2011-02-01 14:17:08 +01:00
|
|
|
configure: function(configuration) {
|
2011-02-01 15:16:54 +01:00
|
|
|
var me = this;
|
|
|
|
$.extend(me.options, configuration);
|
|
|
|
if (!me.options.maps) me.options.maps = {};
|
|
|
|
$.each(me.options.shownmaps, function(index, mapentry) {
|
2011-02-06 15:09:15 +01:00
|
|
|
me.options.maps[mapentry.name] = maptypes[mapentry.type](mapentry);
|
2011-02-01 14:17:08 +01:00
|
|
|
});
|
2011-02-13 01:19:47 +01:00
|
|
|
me.world = me.options.defaultworld;
|
2011-02-01 14:17:08 +01:00
|
|
|
},
|
2011-01-14 20:08:23 +01:00
|
|
|
initialize: function() {
|
|
|
|
var me = this;
|
2010-12-31 13:33:51 +01:00
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
var container = $(me.options.container);
|
|
|
|
|
|
|
|
var mapContainer;
|
|
|
|
(mapContainer = $('<div/>'))
|
|
|
|
.addClass('map')
|
|
|
|
.appendTo(container);
|
|
|
|
|
|
|
|
var map = this.map = new google.maps.Map(mapContainer.get(0), {
|
|
|
|
zoom: 1,
|
|
|
|
center: new google.maps.LatLng(0, 1),
|
|
|
|
navigationControl: true,
|
|
|
|
navigationControlOptions: {
|
|
|
|
style: google.maps.NavigationControlStyle.DEFAULT
|
|
|
|
},
|
|
|
|
scaleControl: false,
|
|
|
|
mapTypeControl: false,
|
|
|
|
streetViewControl: false,
|
2011-01-23 12:00:15 +01:00
|
|
|
backgroundColor: 'none'
|
2011-01-14 20:08:23 +01:00
|
|
|
});
|
2011-01-12 01:45:56 +01:00
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
google.maps.event.addListener(map, 'dragstart', function(mEvent) {
|
|
|
|
me.followPlayer('');
|
|
|
|
});
|
|
|
|
// TODO: Enable hash-links.
|
|
|
|
/*google.maps.event.addListener(map, 'zoom_changed', function() {
|
|
|
|
me.updateLink();
|
|
|
|
});
|
|
|
|
google.maps.event.addListener(map, 'center_changed', function() {
|
|
|
|
me.updateLink();
|
|
|
|
});*/
|
2010-12-31 13:33:51 +01:00
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
// The sidebar
|
|
|
|
var sidebar = me.sidebar = $('<div/>')
|
|
|
|
.addClass('sidebar')
|
|
|
|
.appendTo(container);
|
|
|
|
|
2011-02-13 01:19:47 +01:00
|
|
|
// The world list.
|
|
|
|
var worldlist = me.worldlist = $('<div/>')
|
|
|
|
.addClass('worldlist')
|
|
|
|
.appendTo(sidebar);
|
|
|
|
|
|
|
|
$.each(me.options.shownworlds, function(index, name) {
|
|
|
|
var worldButton;
|
|
|
|
$('<div/>')
|
|
|
|
.addClass('worldrow')
|
|
|
|
.append(worldButton = $('<input/>')
|
|
|
|
.addClass('worldbutton')
|
|
|
|
.addClass('world_' + name)
|
|
|
|
.attr({
|
|
|
|
type: 'radio',
|
|
|
|
name: 'world',
|
|
|
|
value: name
|
|
|
|
})
|
|
|
|
.attr('checked', me.options.defaultworld == name ? 'checked' : null)
|
|
|
|
)
|
|
|
|
.append($('<label/>')
|
|
|
|
.attr('for', 'worldbutton_' + name)
|
|
|
|
.text(name)
|
|
|
|
)
|
|
|
|
.click(function() {
|
|
|
|
$('.worldbutton', worldlist).removeAttr('checked');
|
|
|
|
map.setMapTypeId('none');
|
|
|
|
me.world = name;
|
|
|
|
// Another workaround for GMaps not being able to reload tiles.
|
|
|
|
window.setTimeout(function() {
|
|
|
|
map.setMapTypeId(me.options.defaultmap);
|
|
|
|
}, 1);
|
|
|
|
worldButton.attr('checked', 'checked');
|
|
|
|
})
|
|
|
|
.data('world', name)
|
|
|
|
.appendTo(worldlist);
|
|
|
|
});
|
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
// The map list.
|
|
|
|
var maplist = me.maplist = $('<div/>')
|
|
|
|
.addClass('maplist')
|
|
|
|
.appendTo(sidebar);
|
2011-02-13 01:19:47 +01:00
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
$.each(me.options.maps, function(name, mapType){
|
|
|
|
mapType.dynmap = me;
|
|
|
|
map.mapTypes.set(name, mapType);
|
2011-01-12 01:45:56 +01:00
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
var mapButton;
|
|
|
|
$('<div/>')
|
2011-01-12 01:45:56 +01:00
|
|
|
.addClass('maprow')
|
|
|
|
.append(mapButton = $('<input/>')
|
2011-02-13 01:19:47 +01:00
|
|
|
.addClass('mapbutton')
|
2011-01-12 01:45:56 +01:00
|
|
|
.addClass('maptype_' + name)
|
|
|
|
.attr({
|
|
|
|
type: 'radio',
|
|
|
|
name: 'map',
|
2011-02-13 01:19:47 +01:00
|
|
|
value: name
|
2011-01-12 01:45:56 +01:00
|
|
|
})
|
2011-02-01 14:17:08 +01:00
|
|
|
.attr('checked', me.options.defaultmap == name ? 'checked' : null)
|
2011-01-12 01:45:56 +01:00
|
|
|
)
|
|
|
|
.append($('<label/>')
|
|
|
|
.attr('for', 'maptypebutton_' + name)
|
|
|
|
.text(name)
|
|
|
|
)
|
|
|
|
.click(function() {
|
2011-01-14 20:08:23 +01:00
|
|
|
$('.mapbutton', maplist).removeAttr('checked');
|
2011-01-12 01:45:56 +01:00
|
|
|
map.setMapTypeId(name);
|
|
|
|
mapButton.attr('checked', 'checked');
|
|
|
|
})
|
2011-01-14 20:08:23 +01:00
|
|
|
.data('maptype', mapType)
|
|
|
|
.appendTo(maplist);
|
|
|
|
});
|
2011-02-01 14:17:08 +01:00
|
|
|
map.setMapTypeId(me.options.defaultmap);
|
2011-01-14 20:08:23 +01:00
|
|
|
|
|
|
|
// The Player List
|
|
|
|
var playerlist = me.playerlist = $('<div/>')
|
|
|
|
.addClass('playerlist')
|
|
|
|
.appendTo(sidebar);
|
|
|
|
|
|
|
|
// The Clock
|
|
|
|
var clock = me.clock = new MinecraftClock(
|
|
|
|
$('<div/>')
|
|
|
|
.addClass('clock')
|
|
|
|
.appendTo(sidebar)
|
|
|
|
);
|
|
|
|
|
2011-02-13 07:25:28 +01:00
|
|
|
// The TimeOfDay
|
|
|
|
var timeofday = me.timeofday = new MinecraftTimeOfDay(
|
|
|
|
$('<div/>')
|
|
|
|
.addClass('timeofday')
|
|
|
|
.appendTo(sidebar)
|
|
|
|
);
|
|
|
|
|
|
|
|
// The Compass
|
|
|
|
var compass = me.compass = new MinecraftCompass(
|
|
|
|
$('<div/>')
|
|
|
|
.addClass('compass')
|
|
|
|
.appendTo(sidebar)
|
|
|
|
);
|
|
|
|
compass.initialize();
|
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
// TODO: Enable hash-links.
|
|
|
|
/*
|
|
|
|
var link;
|
|
|
|
var linkbox = me.linkbox = $('<div/>')
|
|
|
|
.addClass('linkbox')
|
|
|
|
.append(link=$('<input type="text" />'))
|
|
|
|
.data('link', link)
|
|
|
|
.appendTo(container);*/
|
|
|
|
|
|
|
|
var alertbox = me.alertbox = $('<div/>')
|
|
|
|
.addClass('alertbox')
|
|
|
|
.appendTo(container);
|
|
|
|
|
2011-02-01 15:16:54 +01:00
|
|
|
setTimeout(function() { me.update(); }, me.options.updaterate);
|
2011-01-14 20:08:23 +01:00
|
|
|
},
|
|
|
|
update: function() {
|
|
|
|
var me = this;
|
2011-01-26 00:10:42 +01:00
|
|
|
|
|
|
|
// TODO: is there a better place for this?
|
|
|
|
this.cleanPopups();
|
|
|
|
|
2011-02-13 01:19:47 +01:00
|
|
|
$.getJSON(me.options.updateUrl + "world/" + me.world + "/" + me.lasttimestamp, function(update) {
|
2011-01-14 20:08:23 +01:00
|
|
|
me.alertbox.hide();
|
2011-02-06 03:00:51 +01:00
|
|
|
|
|
|
|
me.lasttimestamp = update.timestamp;
|
|
|
|
me.clock.setTime(getMinecraftTime(update.servertime));
|
2011-02-13 07:25:28 +01:00
|
|
|
me.timeofday.setTime(me.clock.time);
|
2010-12-31 13:33:51 +01:00
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
var typeVisibleMap = {};
|
|
|
|
var newmarkers = {};
|
|
|
|
|
2011-02-06 03:00:51 +01:00
|
|
|
$.each(update.players, function(index, player) {
|
|
|
|
var mi = {
|
|
|
|
id: 'player_' + player.name,
|
|
|
|
text: player.name,
|
|
|
|
type: 'player',
|
|
|
|
position: me.map.getProjection().fromWorldToLatLng(parseFloat(player.x), parseFloat(player.y), parseFloat(player.z)),
|
|
|
|
visible: true
|
|
|
|
};
|
2010-12-31 13:33:51 +01:00
|
|
|
|
2011-02-06 03:00:51 +01:00
|
|
|
me.updateMarker(mi);
|
|
|
|
newmarkers[mi.id] = mi;
|
|
|
|
});
|
|
|
|
|
|
|
|
$.each(update.updates, function(index, update) {
|
|
|
|
swtch(update.type, {
|
2011-01-14 20:08:23 +01:00
|
|
|
tile: function() {
|
2011-02-06 03:00:51 +01:00
|
|
|
me.onTileUpdated(update.name);
|
|
|
|
},
|
|
|
|
chat: function() {
|
2011-02-01 15:16:54 +01:00
|
|
|
if (!me.options.showchatballoons)
|
|
|
|
return;
|
2011-02-06 03:00:51 +01:00
|
|
|
me.onPlayerChat(update.playerName, update.message);
|
2011-01-25 23:03:27 +01:00
|
|
|
}
|
2011-02-06 03:00:51 +01:00
|
|
|
}, function(type) {
|
|
|
|
console.log('Unknown type ', value, '!');
|
2011-01-14 20:08:23 +01:00
|
|
|
});
|
2011-02-06 03:00:51 +01:00
|
|
|
});
|
2011-01-14 20:08:23 +01:00
|
|
|
|
|
|
|
for(var m in me.markers) {
|
|
|
|
var marker = me.markers[m];
|
|
|
|
if(!(m in newmarkers)) {
|
|
|
|
marker.remove(null);
|
|
|
|
if (marker.playerRow) {
|
|
|
|
marker.playerRow.remove();
|
|
|
|
}
|
|
|
|
delete me.markers[m];
|
|
|
|
}
|
|
|
|
}
|
2011-02-01 15:16:54 +01:00
|
|
|
setTimeout(function() { me.update(); }, me.options.updaterate);
|
2011-02-06 03:00:51 +01:00
|
|
|
}, function(request, statusText, ex) {
|
2011-01-14 20:08:23 +01:00
|
|
|
me.alertbox
|
|
|
|
.text('Could not update map')
|
|
|
|
.show();
|
2011-02-01 15:16:54 +01:00
|
|
|
setTimeout(function() { me.update(); }, me.options.updaterate);
|
2011-01-14 20:08:23 +01:00
|
|
|
}
|
2011-02-06 03:00:51 +01:00
|
|
|
);
|
2011-01-14 20:08:23 +01:00
|
|
|
},
|
2011-01-26 00:10:42 +01:00
|
|
|
cleanPopups: function() {
|
|
|
|
var POPUP_LIFE = 8000;
|
|
|
|
var d = new Date();
|
|
|
|
var now = d.getTime();
|
|
|
|
for (var popupIndex in this.chatPopups)
|
|
|
|
{
|
|
|
|
var popup = this.chatPopups[popupIndex];
|
|
|
|
if (now - popup.popupTime > POPUP_LIFE)
|
|
|
|
{
|
|
|
|
popup.infoWindow.close();
|
|
|
|
popup.infoWindow = null;
|
2011-01-26 01:05:00 +01:00
|
|
|
delete this.chatPopups[popupIndex];
|
2011-01-26 00:10:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2011-01-25 23:03:27 +01:00
|
|
|
onPlayerChat: function(playerName, message) {
|
|
|
|
var me = this;
|
|
|
|
var markers = me.markers;
|
2011-01-26 00:10:42 +01:00
|
|
|
var chatPopups = this.chatPopups;
|
2011-01-25 23:03:27 +01:00
|
|
|
var map = me.map;
|
|
|
|
var mid = "player_" + playerName;
|
|
|
|
var playerMarker = markers[mid];
|
|
|
|
if (playerMarker)
|
|
|
|
{
|
2011-01-26 00:10:42 +01:00
|
|
|
var popup = chatPopups[playerName];
|
2011-01-26 01:05:00 +01:00
|
|
|
if (!popup)
|
|
|
|
popup = { lines: [ message ] };
|
2011-01-26 00:10:42 +01:00
|
|
|
else
|
|
|
|
popup.lines[popup.lines.length] = message;
|
2011-01-26 01:05:00 +01:00
|
|
|
|
2011-01-26 00:10:42 +01:00
|
|
|
var MAX_LINES = 5;
|
|
|
|
if (popup.lines.length > MAX_LINES)
|
|
|
|
{
|
|
|
|
popup.lines = popup.lines.slice(1);
|
|
|
|
}
|
|
|
|
htmlMessage = '<div id="content"><b>' + playerName + "</b><br/><br/>"
|
|
|
|
for (var line in popup.lines)
|
|
|
|
{
|
|
|
|
htmlMessage = htmlMessage + popup.lines[line] + "<br/>";
|
|
|
|
}
|
|
|
|
htmlMessage = htmlMessage + "</div>"
|
|
|
|
var now = new Date();
|
|
|
|
popup.popupTime = now.getTime();
|
2011-01-26 01:05:00 +01:00
|
|
|
if (!popup.infoWindow) {
|
|
|
|
popup.infoWindow = new google.maps.InfoWindow({
|
2011-02-05 19:51:06 +01:00
|
|
|
disableAutoPan: me.options.focuschatballoons || false,
|
2011-01-26 01:05:00 +01:00
|
|
|
content: htmlMessage
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
popup.infoWindow.setContent(htmlMessage);
|
|
|
|
}
|
2011-01-26 00:10:42 +01:00
|
|
|
popup.infoWindow.open(map, playerMarker);
|
|
|
|
this.chatPopups[playerName] = popup;
|
2011-01-25 23:03:27 +01:00
|
|
|
}
|
|
|
|
},
|
2011-01-14 20:08:23 +01:00
|
|
|
onTileUpdated: function(tileName) {
|
|
|
|
var me = this;
|
|
|
|
var tile = this.registeredTiles[tileName];
|
|
|
|
|
|
|
|
if (tile) {
|
|
|
|
tile.lastseen = this.lasttimestamp;
|
|
|
|
tile.mapType.onTileUpdated(tile.tileElement, tileName);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updateMarker: function(mi) {
|
|
|
|
var me = this;
|
|
|
|
var markers = me.markers;
|
|
|
|
var map = me.map;
|
|
|
|
|
|
|
|
if(mi.id in markers) {
|
|
|
|
var m = markers[mi.id];
|
|
|
|
m.toggle(mi.visible);
|
|
|
|
m.setPosition(mi.position);
|
|
|
|
} else {
|
|
|
|
var contentfun = function(div,mi) {
|
|
|
|
$(div)
|
|
|
|
.addClass('Marker')
|
|
|
|
.addClass(mi.type + 'Marker')
|
|
|
|
.append($('<img/>').attr({src: mi.type + '.png'}))
|
|
|
|
.append($('<span/>').text(mi.text));
|
|
|
|
};
|
|
|
|
if (mi.type == 'player') {
|
|
|
|
contentfun = function(div, mi) {
|
2011-01-15 02:11:31 +01:00
|
|
|
var playerImage;
|
2011-01-14 20:08:23 +01:00
|
|
|
$(div)
|
|
|
|
.addClass('Marker')
|
|
|
|
.addClass('playerMarker')
|
2011-01-15 02:11:31 +01:00
|
|
|
.append(playerImage = $('<img/>')
|
|
|
|
.attr({ src: 'player.png' }))
|
2011-01-14 20:08:23 +01:00
|
|
|
.append($('<span/>')
|
|
|
|
.addClass('playerName')
|
2011-01-15 02:11:31 +01:00
|
|
|
.text(mi.text))
|
2011-02-01 15:16:54 +01:00
|
|
|
if (me.options.showplayerfacesonmap) {
|
|
|
|
getMinecraftHead(mi.text, 32, function(head) {
|
|
|
|
$(head)
|
|
|
|
.addClass('playerIcon')
|
|
|
|
.prependTo(div);
|
|
|
|
playerImage.remove();
|
|
|
|
});
|
|
|
|
}
|
2011-01-14 20:08:23 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
var marker = new CustomMarker(mi.position, map, contentfun, mi);
|
|
|
|
marker.markerType = mi.type;
|
|
|
|
|
|
|
|
markers[mi.id] = marker;
|
|
|
|
|
|
|
|
if (mi.type == 'player') {
|
|
|
|
marker.playerRow = $('<div/>')
|
|
|
|
.attr({ id: 'playerrow_' + mi.text })
|
|
|
|
.addClass('playerrow')
|
|
|
|
.append(marker.followButton = $('<input/>')
|
|
|
|
.attr({ type: 'checkbox',
|
|
|
|
name: 'followPlayer',
|
|
|
|
checked: false,
|
|
|
|
value: mi.text
|
|
|
|
})
|
|
|
|
.addClass('followButton')
|
|
|
|
.click(function(e) {
|
|
|
|
me.followPlayer(mi.id != me.followingPlayer ? mi.id : '');
|
|
|
|
}))
|
|
|
|
.append(marker.playerIconContainer = $('<span/>'))
|
|
|
|
.append($('<a/>')
|
|
|
|
.text(mi.text)
|
|
|
|
.attr({ href: '#' })
|
|
|
|
.click(function(e) { map.panTo(markers[mi.id].getPosition()); })
|
|
|
|
);
|
|
|
|
|
2011-02-01 15:16:54 +01:00
|
|
|
if (me.options.showplayerfacesinmenu) {
|
|
|
|
getMinecraftHead(mi.text, 16, function(head) {
|
|
|
|
marker.playerRow.icon = $(head)
|
|
|
|
.addClass('playerIcon')
|
|
|
|
.appendTo(marker.playerIconContainer);
|
|
|
|
});
|
|
|
|
}
|
2011-01-14 20:08:23 +01:00
|
|
|
|
|
|
|
me.playerlist.append(marker.playerRow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mi.id == me.followingPlayer) {
|
|
|
|
map.panTo(markers[mi.id].getPosition());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
followPlayer: function(name) {
|
|
|
|
var me = this;
|
|
|
|
$('.followButton', me.playerlist).removeAttr('checked');
|
|
|
|
|
|
|
|
var m = me.markers[name];
|
|
|
|
if(m) {
|
|
|
|
$(m.followButton).attr('checked', 'checked');
|
|
|
|
me.map.panTo(m.getPosition());
|
|
|
|
}
|
|
|
|
this.followingPlayer = name;
|
|
|
|
},
|
|
|
|
getTileUrl: function(tileName, always) {
|
|
|
|
var me = this;
|
|
|
|
var tile = me.registeredTiles[tileName];
|
|
|
|
|
|
|
|
if(tile) {
|
2011-02-13 22:42:08 +01:00
|
|
|
return me.options.tileUrl + me.world + '/' + tileName + '?' + tile.lastseen;
|
2011-01-14 20:08:23 +01:00
|
|
|
} else {
|
2011-02-13 22:42:08 +01:00
|
|
|
return me.options.tileUrl + me.world + '/' + tileName + '?0';
|
2011-01-14 20:08:23 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
registerTile: function(mapType, tileName, tile) {
|
|
|
|
this.registeredTiles[tileName] = {
|
|
|
|
tileElement: tile,
|
|
|
|
mapType: mapType,
|
|
|
|
lastseen: '0'
|
|
|
|
};
|
|
|
|
},
|
|
|
|
unregisterTile: function(mapType, tileName) {
|
2011-01-15 00:01:44 +01:00
|
|
|
delete this.registeredTiles[tileName];
|
2011-01-14 20:08:23 +01:00
|
|
|
},
|
|
|
|
// TODO: Enable hash-links.
|
|
|
|
/* updateLink: function() {
|
|
|
|
var me = this;
|
|
|
|
var url = location.href.match(/^[^#]+/);
|
|
|
|
|
|
|
|
var a=url
|
|
|
|
+ "#lat=" + me.map.getCenter().lat().toFixed(6)
|
|
|
|
+ "&lng=" + me.map.getCenter().lng().toFixed(6)
|
|
|
|
+ "&zoom=" + me.map.getZoom();
|
|
|
|
me.linkbox.data('link').val(a);
|
|
|
|
}*/
|
|
|
|
}
|