From d634aede92813ab314a87e90e70bbe68236a4d82 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Wed, 12 Jan 2011 01:45:56 +0100 Subject: [PATCH] Minor cleaups. --- web/index.html | 4 +- web/map.js | 467 +++++++++++++++++++++++-------------------------- 2 files changed, 218 insertions(+), 253 deletions(-) diff --git a/web/index.html b/web/index.html index 81dba0d0..fd05e68f 100644 --- a/web/index.html +++ b/web/index.html @@ -23,9 +23,9 @@
Updating...
- on -
+
+
diff --git a/web/map.js b/web/map.js index eb72a959..5975227a 100644 --- a/web/map.js +++ b/web/map.js @@ -85,270 +85,235 @@ function onTileUpdated(tileName) { } var clock = null; - var markers = new Array(); - var lasttimestamp = '0'; - var followPlayer = ''; +var markers = new Array(); +var lasttimestamp = '0'; +var followingPlayer = ''; - var lst; - var plistbtn; - var lstopen = true; - - 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) { +function updateMarker(mi) { + if(mi.id in markers) { + var m = markers[mi.id]; + if (!mi.visible) { + m.hide(); + return; + } + else { + m.show(); + } + + 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(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 = $('
') - .attr({ id: 'playerrow_' + mi.text }) - .addClass('playerrow') - .append(marker.followButton = $('') - .attr({ type: 'checkbox', - name: 'followPlayer', - checked: false, - value: mi.text - }) - .addClass('followButton') - .click(function(e) { - plfollow(mi.id != followPlayer ? mi.id : ''); - })) - .append(marker.playerIconContainer = $('')) - .append($('') - .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('playerMarker') + .append($('') + .addClass('playerName') + .text(mi.text)); + + getMinecraftHead(mi.text, 32, function(head) { + $(head) .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) { - map.panTo(markers[mi.id].getPosition()); - } - } + markers[mi.id] = marker; - 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 typeCount = {}; - - var rows = res.split('\n'); - var loggedin = new Array(); - var firstRow = rows[0].split(' '); - lasttimestamp = firstRow[0]; - delete rows[0]; - - var servertime = firstRow[1]; - clock.setTime(getMinecraftTime(servertime)); - - for(var line in rows) { - var p = rows[line].split(' '); - - if (p[0] == '') continue; - - ({ tile: function() { - 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); - loggedin[mi.id] = 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]; - } - } - 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); - } - }); - } - - window.onload = function initialize() { - lst = document.getElementById('lst'); - plistbtn = document.getElementById('plistbtn'); + if (mi.type == 'player') { + marker.playerRow = $('
') + .attr({ id: 'playerrow_' + mi.text }) + .addClass('playerrow') + .append(marker.followButton = $('') + .attr({ type: 'checkbox', + name: 'followPlayer', + checked: false, + value: mi.text + }) + .addClass('followButton') + .click(function(e) { + followPlayer(mi.id != followingPlayer ? mi.id : ''); + })) + .append(marker.playerIconContainer = $('')) + .append($('') + .text(mi.text) + .attr({ href: '#' }) + .click(function(e) { map.panTo(markers[mi.id].getPosition()); }) + ); - var mapOptions = { - zoom: 1, - center: new google.maps.LatLng(0, 1), - navigationControl: true, - navigationControlOptions: { - style: google.maps.NavigationControlStyle.DEFAULT - }, - scaleControl: false, - mapTypeControl: false, - streetViewControl: false, - backgroundColor: '#000' - }; - map = new google.maps.Map(document.getElementById("mcmap"), mapOptions); - - google.maps.event.addListener(map, 'dragstart', function(mEvent) { - plfollow(''); + getMinecraftHead(mi.text, 16, function(head) { + marker.playerRow.icon = $(head) + .addClass('playerIcon') + .appendTo(marker.playerIconContainer); }); - google.maps.event.addListener(map, 'zoom_changed', function() { - makeLink(); - }); - google.maps.event.addListener(map, 'center_changed', function() { - makeLink(); - }); - map.dragstart = plfollow(''); - - $.each(config.maps, function(name, mapType){ - map.mapTypes.set(name, mapType); - var mapButton; - $('#maplist').append($('
') - .addClass('maprow') - .append(mapButton = $('') - .addClass('maptype_' + name) - .attr({ - type: 'radio', - name: 'map', - id: 'maptypebutton_' + name - }) - .attr('checked', config.defaultMap == name ? 'checked' : null) + $('#playerlst').append(marker.playerRow); + } + } + + if(mi.id == followingPlayer) { + map.panTo(markers[mi.id].getPosition()); + } +} + +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 typeCount = {}; + + var rows = res.split('\n'); + var loggedin = new Array(); + var firstRow = rows[0].split(' '); + lasttimestamp = firstRow[0]; + delete rows[0]; + + var servertime = firstRow[1]; + clock.setTime(getMinecraftTime(servertime)); + + for(var line in rows) { + var p = rows[line].split(' '); + + if (p[0] == '') continue; + + ({ tile: function() { + 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); + loggedin[mi.id] = 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]; + } + } + 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); + } + }); +} + +window.onload = function initialize() { + var mapOptions = { + zoom: 1, + center: new google.maps.LatLng(0, 1), + navigationControl: true, + navigationControlOptions: { + style: google.maps.NavigationControlStyle.DEFAULT + }, + scaleControl: false, + mapTypeControl: false, + streetViewControl: false, + backgroundColor: '#000' + }; + map = new google.maps.Map(document.getElementById("mcmap"), mapOptions); + + google.maps.event.addListener(map, 'dragstart', function(mEvent) { + followPlayer(''); + }); + google.maps.event.addListener(map, 'zoom_changed', function() { + makeLink(); + }); + google.maps.event.addListener(map, 'center_changed', function() { + makeLink(); + }); + map.dragstart = followPlayer(''); + + $.each(config.maps, function(name, mapType){ + map.mapTypes.set(name, mapType); + + var mapButton; + $('#maplist').append($('
') + .addClass('maprow') + .append(mapButton = $('') + .addClass('maptype_' + name) + .attr({ + type: 'radio', + name: 'map', + id: 'maptypebutton_' + name + }) + .attr('checked', config.defaultMap == name ? 'checked' : null) + ) + .append($('