/* generic function for making an XMLHttpRequest
* url: request URL
* func: callback function for success
* type: 'text' by default (callback is called with response text)
* otherwise, callback is called with a parsed XML dom
* fail: callback function for failure
* post: if given, make a POST request instead of GET; post data given
*
* contenttype: if given for a POST, set request content-type header
*/
function makeRequest(url, func, type, fail, post, contenttype)
{
var http_request = false;
type = typeof(type) != 'undefined' ? type : 'text';
fail = typeof(fail) != 'undefined' ? fail : function() { };
if(window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
} else if(window.ActiveXObject) {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
if(type == 'text') {
http_request.onreadystatechange = function() {
if(http_request.readyState == 4) {
if(http_request.status == 200) {
func(http_request.responseText);
} else {
fail(http_request);
}
}
}
} else {
http_request.onreadystatechange = function() {
if(http_request.readyState == 4) {
if(http_request.status == 200) { func(http_request.responseXML); } else {
fail(http_request);
}
}
}
}
if(typeof(post) != 'undefined') {
http_request.open('POST', url, true);
if(typeof(contenttype) != 'undefined')
http_request.setRequestHeader("Content-Type", contenttype);
http_request.send(post);
} else {
http_request.open('GET', url, true);
http_request.send(null);
}
}
var config = {
tileUrl: setup.tileUrl,
updateUrl: setup.updateUrl,
tileWidth: 128,
tileHeight: 128,
updateRate: setup.updateRate,
zoomSize: [ 128, 128, 256, 512 ]
};
function MCMapProjection() {
}
MCMapProjection.prototype.fromLatLngToPoint = function(latLng) {
var x = (latLng.lng() * config.tileWidth)|0;
var y = (latLng.lat() * config.tileHeight)|0;
if(map.zoom == 0) {
x += config.tileWidth / 2;
}
return new google.maps.Point(x, y);
};
MCMapProjection.prototype.fromPointToLatLng = function(point) {
var x = point.x;
if(map.zoom == 0)
x -= config.tileWidth / 2;
var lng = x / config.tileWidth;
var lat = point.y / config.tileHeight;
return new google.maps.LatLng(lat, lng);
};
function fromWorldToLatLng(x, y, z)
{
var dx = +x;
var dy = +y - 127;
var dz = +z;
var px = dx + dz;
var py = dx - dz - dy;
var lng = -px / config.tileWidth / 2 + 0.5;
var lat = py / config.tileHeight / 2;
return new google.maps.LatLng(lat, lng);
}
function mcMapType() {
}
var tileDict = new Array();
var lastSeen = new Array();
function tileUrl(tile, always) {
if(always) {
var now = new Date();
return config.tileUrl + tile + '.png?' + now.getTime();
} else if(tile in lastSeen) {
return config.tileUrl + tile + '.png?' + lastSeen[tile];
} else {
return config.tileUrl + tile + '.png?0';
}
}
function imgSubst(tile) {
if(!(tile in tileDict))
return;
var src = tileUrl(tile);
var t = tileDict[tile];
t.src = src;
t.style.display = '';
t.onerror = function() {
setTimeout(function() {
t.src = tileUrl(tile, 1);
}, 1000);
t.onerror = '';
}
}
var caveMode = false;
function caveSwitch()
{
caveMode = !caveMode;
if(caveMode) {
cavebtn.src = 'cave_on.png';
map.setMapTypeId('cavemap');
} else {
cavebtn.src = 'cave_off.png';
map.setMapTypeId('mcmap');
}
}
mcMapType.prototype.tileSize = new google.maps.Size(config.tileWidth, config.tileHeight);
mcMapType.prototype.minZoom = 0;
mcMapType.prototype.maxZoom = 3;
mcMapType.prototype.getTile = function(coord, zoom, doc) {
var img = doc.createElement('IMG');
img.onerror = function() { img.style.display = 'none'; }
img.style.width = config.zoomSize[zoom] + 'px';
img.style.height = config.zoomSize[zoom] + 'px';
img.style.borderStyle = 'none';
var pfx = caveMode ? "c" : "";
if(zoom > 0) {
var tilename = pfx + "t_" + (- coord.x * config.tileWidth) + '_' + coord.y * config.tileHeight;
} else {
var tilename = pfx + "zt_" + (- coord.x * config.tileWidth * 2) + '_' + coord.y * config.tileHeight * 2;
}
tileDict[tilename] = img;
var url = tileUrl(tilename);
img.src = url;
//img.style.background = 'url(' + url + ')';
//img.innerHTML = '' + tilename + '';
return img;
}
var markers = new Array();
var lasttimestamp = 0;
var followPlayer = '';
var lst;
var plistbtn;
var cavebtn;
var lstopen = true;
var oldplayerlst = '[Connecting]';
var servertime = 0;
function updateMarker(mi) {
if(mi.id in markers) {
var m = markers[mi.id];
if (!mi.visible) {
m.hide();
return;
}
else {
m.show();
}
var converted = mi.position;
m.setPosition(mi.position);
} else {
var contentfun = function(div,mi) {
$(div)
.addClass('Marker')
.addClass(mi.type + 'Marker')
.append($('').attr({src: mi.type + '.png'}))
.append($('').text(mi.text));
};
if (mi.type == 'player') {
contentfun = function(div, mi) {
$(div)
.addClass('Marker')
.addClass('playerMarker')
.append($('')
.addClass('playerName')
.text(mi.text));
getMinecraftHead(mi.text, 32, function(head) {
$(head)
.addClass('playerIcon')
.prependTo(div);
});
};
}
var marker = new CustomMarker(converted, map, contentfun, mi);
marker.markerType = mi.type;
markers[mi.id] = marker;
if (mi.type == 'player') {
marker.playerRow = $('