Minor cleaups.

This commit is contained in:
FrozenCow 2011-01-12 01:45:56 +01:00
parent 27fb8a20f1
commit d634aede92
2 changed files with 218 additions and 253 deletions

View File

@ -23,9 +23,9 @@
<div id="mcmap"></div> <div id="mcmap"></div>
<div id="alert">Updating...</div> <div id="alert">Updating...</div>
<div id="plist"> <div id="plist">
<img id="plistbtn" alt="on" src="list_on.png" onclick="plistopen()" title="Toggle Player List" /> <input type="checkbox" onclick="$('#lst').toggle()" title="Toggle Player List" checked="checked"/>
<div id="maplist"></div>
<div id="lst"> <div id="lst">
<div id="maplist"></div>
<div id="playerlst"></div> <div id="playerlst"></div>
<div id="clock"></div> <div id="clock"></div>
</div> </div>

View File

@ -85,270 +85,235 @@ function onTileUpdated(tileName) {
} }
var clock = null; var clock = null;
var markers = new Array(); var markers = new Array();
var lasttimestamp = '0'; var lasttimestamp = '0';
var followPlayer = ''; var followingPlayer = '';
var lst; function updateMarker(mi) {
var plistbtn; if(mi.id in markers) {
var lstopen = true; var m = markers[mi.id];
if (!mi.visible) {
m.hide();
return;
}
else {
m.show();
}
function updateMarker(mi) { m.setPosition(mi.position);
if(mi.id in markers) { } else {
var m = markers[mi.id]; var contentfun = function(div,mi) {
if (!mi.visible) { $(div)
m.hide(); .addClass('Marker')
return; .addClass(mi.type + 'Marker')
} .append($('<img/>').attr({src: mi.type + '.png'}))
else { .append($('<span/>').text(mi.text));
m.show(); };
} if (mi.type == 'player') {
contentfun = function(div, mi) {
var converted = mi.position;
m.setPosition(mi.position);
} else {
var contentfun = function(div,mi) {
$(div) $(div)
.addClass('Marker') .addClass('Marker')
.addClass(mi.type + 'Marker') .addClass('playerMarker')
.append($('<img/>').attr({src: mi.type + '.png'})) .append($('<span/>')
.append($('<span/>').text(mi.text)); .addClass('playerName')
}; .text(mi.text));
if (mi.type == 'player') {
contentfun = function(div, mi) {
$(div)
.addClass('Marker')
.addClass('playerMarker')
.append($('<span/>')
.addClass('playerName')
.text(mi.text));
getMinecraftHead(mi.text, 32, function(head) { getMinecraftHead(mi.text, 32, function(head) {
$(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 = $('<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) {
plfollow(mi.id != followPlayer ? mi.id : '');
}))
.append(marker.playerIconContainer = $('<span/>'))
.append($('<a/>')
.text(mi.text)
.attr({ href: '#' })
.click(function(e) { map.panTo(markers[mi.id].getPosition()); })
);
getMinecraftHead(mi.text, 16, function(head) {
marker.playerRow.icon = $(head)
.addClass('playerIcon') .addClass('playerIcon')
.appendTo(marker.playerIconContainer); .prependTo(div);
}); });
};
$('#playerlst').append(marker.playerRow);
}
} }
var marker = new CustomMarker(converted, map, contentfun, mi);
marker.markerType = mi.type;
if(mi.id == followPlayer) { markers[mi.id] = marker;
map.panTo(markers[mi.id].getPosition());
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) {
followPlayer(mi.id != followingPlayer ? mi.id : '');
}))
.append(marker.playerIconContainer = $('<span/>'))
.append($('<a/>')
.text(mi.text)
.attr({ href: '#' })
.click(function(e) { map.panTo(markers[mi.id].getPosition()); })
);
getMinecraftHead(mi.text, 16, function(head) {
marker.playerRow.icon = $(head)
.addClass('playerIcon')
.appendTo(marker.playerIconContainer);
});
$('#playerlst').append(marker.playerRow);
} }
} }
function mapUpdate() if(mi.id == followingPlayer) {
{ map.panTo(markers[mi.id].getPosition());
$.ajax({ }
url: config.updateUrl + lasttimestamp, }
success: function(res) {
$('#alert')
.hide();
var typeVisibleMap = {
'warp': document.getElementById('showWarps').checked,
'sign': document.getElementById('showSigns').checked,
'home': document.getElementById('showHomes').checked,
'spawn': document.getElementById('showSpawn').checked
};
var typeCount = {}; function mapUpdate()
{
$.ajax({
url: config.updateUrl + lasttimestamp,
success: function(res) {
$('#alert')
.hide();
var typeVisibleMap = {
'warp': document.getElementById('showWarps').checked,
'sign': document.getElementById('showSigns').checked,
'home': document.getElementById('showHomes').checked,
'spawn': document.getElementById('showSpawn').checked
};
var rows = res.split('\n'); var typeCount = {};
var loggedin = new Array();
var firstRow = rows[0].split(' ');
lasttimestamp = firstRow[0];
delete rows[0];
var servertime = firstRow[1]; var rows = res.split('\n');
clock.setTime(getMinecraftTime(servertime)); var loggedin = new Array();
var firstRow = rows[0].split(' ');
lasttimestamp = firstRow[0];
delete rows[0];
for(var line in rows) { var servertime = firstRow[1];
var p = rows[line].split(' '); clock.setTime(getMinecraftTime(servertime));
if (p[0] == '') continue; for(var line in rows) {
var p = rows[line].split(' ');
({ tile: function() { if (p[0] == '') continue;
onTileUpdated(p[1]);
}
}[p[0]] || function() {
var mi = {
id: p[0] + '_' + p[1],
text: p[1],
type: p[0],
position: map.getProjection().fromWorldToLatLng(p[2], p[3], p[4]),
visible: ((p[0] in typeVisibleMap) ? typeVisibleMap[p[0]] : true)
};
updateMarker(mi); ({ tile: function() {
loggedin[mi.id] = 1; onTileUpdated(p[1]);
if (!mi.type in typeCount) typeCount[mi.type] = 0;
typeCount[mi.type]++;
})();
}
for(var m in markers) {
if(!(m in loggedin)) {
markers[m].remove(null);
if (markers[m].playerRow) {
markers[m].playerRow.remove();
}
delete markers[m];
} }
} }[p[0]] || function() {
setTimeout(mapUpdate, config.updateRate); var mi = {
document.getElementById('warpsDiv').style.display = (typeCount['warps'] == 0)?'none':''; id: p[0] + '_' + p[1],
document.getElementById('signsDiv').style.display = (typeCount['signs'] == 0)?'none':''; text: p[1],
document.getElementById('homesDiv').style.display = (typeCount['homes'] == 0)?'none':''; type: p[0],
document.getElementById('spawnsDiv').style.display = (typeCount['spawns'] == 0)?'none':''; position: map.getProjection().fromWorldToLatLng(p[2], p[3], p[4]),
}, visible: ((p[0] in typeVisibleMap) ? typeVisibleMap[p[0]] : true)
error: function(request, statusText, ex) { };
$('#alert')
.text('Could not update map') updateMarker(mi);
.show(); loggedin[mi.id] = 1;
setTimeout(mapUpdate, config.updateRate); if (!mi.type in typeCount) typeCount[mi.type] = 0;
typeCount[mi.type]++;
})();
} }
});
}
window.onload = function initialize() { for(var m in markers) {
lst = document.getElementById('lst'); if(!(m in loggedin)) {
plistbtn = document.getElementById('plistbtn'); markers[m].remove(null);
if (markers[m].playerRow) {
markers[m].playerRow.remove();
}
delete markers[m];
}
}
setTimeout(mapUpdate, config.updateRate);
document.getElementById('warpsDiv').style.display = (typeCount['warps'] == 0)?'none':'';
document.getElementById('signsDiv').style.display = (typeCount['signs'] == 0)?'none':'';
document.getElementById('homesDiv').style.display = (typeCount['homes'] == 0)?'none':'';
document.getElementById('spawnsDiv').style.display = (typeCount['spawns'] == 0)?'none':'';
},
error: function(request, statusText, ex) {
$('#alert')
.text('Could not update map')
.show();
setTimeout(mapUpdate, config.updateRate);
}
});
}
var mapOptions = { window.onload = function initialize() {
zoom: 1, var mapOptions = {
center: new google.maps.LatLng(0, 1), zoom: 1,
navigationControl: true, center: new google.maps.LatLng(0, 1),
navigationControlOptions: { navigationControl: true,
style: google.maps.NavigationControlStyle.DEFAULT navigationControlOptions: {
}, style: google.maps.NavigationControlStyle.DEFAULT
scaleControl: false, },
mapTypeControl: false, scaleControl: false,
streetViewControl: false, mapTypeControl: false,
backgroundColor: '#000' streetViewControl: false,
}; backgroundColor: '#000'
map = new google.maps.Map(document.getElementById("mcmap"), mapOptions); };
map = new google.maps.Map(document.getElementById("mcmap"), mapOptions);
google.maps.event.addListener(map, 'dragstart', function(mEvent) { google.maps.event.addListener(map, 'dragstart', function(mEvent) {
plfollow(''); followPlayer('');
}); });
google.maps.event.addListener(map, 'zoom_changed', function() { google.maps.event.addListener(map, 'zoom_changed', function() {
makeLink(); makeLink();
}); });
google.maps.event.addListener(map, 'center_changed', function() { google.maps.event.addListener(map, 'center_changed', function() {
makeLink(); makeLink();
}); });
map.dragstart = plfollow(''); map.dragstart = followPlayer('');
$.each(config.maps, function(name, mapType){ $.each(config.maps, function(name, mapType){
map.mapTypes.set(name, mapType); map.mapTypes.set(name, mapType);
var mapButton; var mapButton;
$('#maplist').append($('<div/>') $('#maplist').append($('<div/>')
.addClass('maprow') .addClass('maprow')
.append(mapButton = $('<input/>') .append(mapButton = $('<input/>')
.addClass('maptype_' + name) .addClass('maptype_' + name)
.attr({ .attr({
type: 'radio', type: 'radio',
name: 'map', name: 'map',
id: 'maptypebutton_' + name id: 'maptypebutton_' + name
}) })
.attr('checked', config.defaultMap == name ? 'checked' : null) .attr('checked', config.defaultMap == name ? 'checked' : null)
)
.append($('<label/>')
.attr('for', 'maptypebutton_' + name)
.text(name)
) )
.append($('<label/>') .click(function() {
.attr('for', 'maptypebutton_' + name) $('.mapbutton').removeAttr('checked');
.text(name) map.setMapTypeId(name);
) mapButton.attr('checked', 'checked');
.click(function() { })
$('.mapbutton').removeAttr('checked'); );
map.setMapTypeId(name); });
mapButton.attr('checked', 'checked');
})
);
});
map.setMapTypeId(config.defaultMap); map.setMapTypeId(config.defaultMap);
clock = new MinecraftClock($('#clock')); clock = new MinecraftClock($('#clock'));
setTimeout(mapUpdate, config.updateRate); setTimeout(mapUpdate, config.updateRate);
}
function followPlayer(name) {
$('.followButton').removeAttr('checked');
if(name in markers) {
var m = markers[name];
$(m.followButton).attr('checked', 'checked');
map.panTo(m.getPosition());
} }
followingPlayer = name;
}
function plistopen() { function makeLink() {
if(lstopen) { var a=location.href.substring(0,location.href.lastIndexOf("/")+1)
lstopen = false; + "?lat=" + map.getCenter().lat().toFixed(6)
lst.style.display = 'none'; + "&lng=" + map.getCenter().lng().toFixed(6)
lst.style.visibility = 'hidden'; + "&zoom=" + map.getZoom();
plistbtn.src = 'list_off.png'; document.getElementById("link").innerHTML = a;
} else { }
lstopen = true;
lst.style.display = '';
lst.style.visibility = '';
plistbtn.src = 'list_on.png';
}
}
function plfollow(name) {
$('.followButton').removeAttr('checked');
if(name in markers) {
var m = markers[name];
$(m.followButton).attr('checked', 'checked');
map.panTo(m.getPosition());
}
followPlayer = name;
}
function makeLink() {
var a=location.href.substring(0,location.href.lastIndexOf("/")+1)
+ "?lat=" + map.getCenter().lat().toFixed(6)
+ "&lng=" + map.getCenter().lng().toFixed(6)
+ "&zoom=" + map.getZoom();
document.getElementById("link").innerHTML = a;
}
//remove item (string or number) from an array
function removeItem(originalArray, itemToRemove) {
var j = 0;
while (j < originalArray.length) {
// alert(originalArray[j]);
if (originalArray[j] == itemToRemove) {
originalArray.splice(j, 1);
} else { j++; }
}
// assert('hi');
return originalArray;
}