"use strict"; //if (!console) console = { log: function() {} }; var componentconstructors = {}; var maptypes = {}; componentconstructors['testcomponent'] = function(dynmap, configuration) { console.log('initialize'); $(dynmap).bind('worldchanged', function() { console.log('worldchanged'); }); $(dynmap).bind('mapchanged', function() { console.log('mapchanged'); }); $(dynmap).bind('zoomchanged', function() { console.log('zoomchanged'); }); $(dynmap).bind('worldupdating', function() { console.log('worldupdating'); }); $(dynmap).bind('worldupdate', function() { console.log('worldupdate'); }); $(dynmap).bind('worldupdated', function() { console.log('worldupdated'); }); $(dynmap).bind('worldupdatefailed', function() { console.log('worldupdatefailed'); }); $(dynmap).bind('playeradded', function() { console.log('playeradded'); }); $(dynmap).bind('playerremoved', function() { console.log('playerremoved'); }); $(dynmap).bind('playerupdated', function() { console.log('playerupdated'); }); }; function loadjs(url, completed) { var script = document.createElement('script'); script.setAttribute('src', url); script.setAttribute('type', 'text/javascript'); var isloaded = false; script.onload = function() { if (isloaded) { return; } isloaded = true; completed(); }; // Hack for IE, don't know whether this still applies to IE9. script.onreadystatechange = function() { script.onload(); }; (document.head || document.getElementsByTagName('head')[0]).appendChild(script); } function splitArgs(s) { var r = s.split(' '); delete arguments[0]; var obj = {}; var index = 0; $.each(arguments, function(argumentIndex, argument) { if (!argumentIndex) { return; } var value = r[argumentIndex-1]; obj[argument] = value; }); return obj; } function swtch(value, options, defaultOption) { return (options[value] || defaultOption || function(){})(value); } (function( $ ){ $.fn.scrollHeight = function(height) { return this[0].scrollHeight; }; })($); function DynMapType() { } DynMapType.prototype = { onTileUpdated: function(tile, tileName) { var src = this.dynmap.getTileUrl(tileName); tile.attr('src', src); tile.show(); }, updateTileSize: function(zoom) {} }; function Location(world, x, y, z) { this.world = world; this.x = x; this.y = y; this.z = z; } function DynMap(options) { var me = this; me.options = options; $.getJSON(me.options.url.configuration, function(configuration) { me.configure(configuration); me.initialize(); }, function(status, statusMessage) { alert('Could not retrieve configuration: ' + statusMessage); }); } DynMap.prototype = { components: [], worlds: {}, registeredTiles: [], players: {}, lasttimestamp: '0', servertime: 0, serverday: false, followingPlayer: '', formatUrl: function(name, options) { var url = this.options.url[name]; $.each(options, function(n,v) { url = url.replace("{" + n + "}", v); }); return url; }, configure: function(configuration) { var me = this; $.extend(me.options, configuration); $.each(me.options.worlds, function(index, worldentry) { var world = me.worlds[worldentry.name] = $.extend({}, worldentry, { maps: {} }); $.each(worldentry.maps, function(index, mapentry) { var map = $.extend({}, mapentry, { world: world, dynmap: me }); map = world.maps[mapentry.name] = maptypes[mapentry.type](map); world.defaultmap = world.defaultmap || map; }); me.defaultworld = me.defaultworld || world; }); }, initialize: function() { var me = this; var container = $(me.options.container); container.addClass('dynmap'); var mapContainer; (mapContainer = $('
')) .addClass('map') .appendTo(container); var map = this.map = new google.maps.Map(mapContainer.get(0), { zoom: me.options.defaultzoom || 0, center: new google.maps.LatLng(0, 1), navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.DEFAULT }, scaleControl: false, mapTypeControl: false, streetViewControl: false, backgroundColor: 'none' }); map.zoom_changed = function() { me.maptype.updateTileSize(me.map.zoom); $(me).trigger('zoomchanged'); }; google.maps.event.addListener(map, 'dragstart', function(mEvent) { me.followPlayer(null); }); // TODO: Enable hash-links. /* google.maps.event.addListener(map, 'zoom_changed', function() { me.updateLink(); }); google.maps.event.addListener(map, 'center_changed', function() { me.updateLink(); }); */ // Sidebar var panel; var sidebar; var pinbutton; if(!me.options.sidebaropened) { sidebar = me.sidebar = $('
') .addClass('sidebar') .appendTo(container); panel = $('
') .addClass('panel') .appendTo(sidebar); // Pin button. pinbutton = $('
') .addClass('pin') .click(function() { sidebar.toggleClass('pinned'); }) .appendTo(panel); } else { sidebar = me.sidebar = $('
') .addClass('sidebar pinned') .appendTo(container); panel = $('
') .addClass('panel') .appendTo(sidebar); } // Worlds var worldlist; $('
') .append($('').text('Map Types')) .append(me.worldlist = worldlist = $('