"use strict"; //if (!console) console = { log: function() {} }; var componentconstructors = {}; var maptypes = {}; var map = null; // Leaflet assumes top-level 'map'... componentconstructors['testcomponent'] = function(dynmap, configuration) { console.log('initialize'); $(dynmap).bind('worldchanged', function() { console.log('worldchanged'); }); $(dynmap).bind('mapchanging', function() { console.log('mapchanging'); }); $(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 DynMap(options) { var me = this; if(me.checkForSavedURL()) return; me.options = options; $.getJSON(me.formatUrl("configuration", { timestamp: me.lasttimestamp }), function(configuration) { if(configuration.error == 'login-required') { me.saveURL(); window.location = 'login.html'; } else if(configuration.error) { alert(configuration.error); } else { me.configure(configuration); me.initialize(); } }, function(status, statusMessage) { alert('Could not retrieve configuration: ' + statusMessage); }); } DynMap.prototype = { components: [], worlds: {}, registeredTiles: [], players: {}, lasttimestamp: new Date().getTime(), /* Pseudorandom - prevent cached '?0' */ reqid: 0, servertime: 0, serverday: false, inittime: new Date().getTime(), followingPlayer: '', initfollow: null, missedupdates: 0, maxcount: -1, currentcount: 0, sidebar: null, sidebarPanel: null, playerlist: null, playerfield: null, layercontrol: undefined, sidebarSections: [], nogui: false, nocompass: false, formatUrl: function(name, options) { var url = this.options.url[name]; $.each(options, function(n,v) { url = url.replace("{" + n + "}", encodeURIComponent(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); if(me.options.defaultmap && me.options.defaultmap == mapentry.name) world.defaultmap = map; world.defaultmap = world.defaultmap || map; }); me.defaultworld = me.defaultworld || world; }); var urlarg = me.getParameterByName('worldname'); if(urlarg == "") urlarg = me.options.defaultworld || ""; if(urlarg != "") { me.defaultworld = me.worlds[urlarg] || me.defaultworld; } urlarg = me.getParameterByName('mapname'); if(urlarg != "") { me.defaultworld.defaultmap = me.defaultworld.maps[urlarg] || me.defaultworld.defaultmap; } urlarg = me.getIntParameterByName('x'); if(urlarg != null) me.defaultworld.center.x = urlarg; urlarg = me.getIntParameterByName('y'); if(urlarg != null) me.defaultworld.center.y = urlarg; urlarg = me.getIntParameterByName('z'); if(urlarg != null) me.defaultworld.center.z = urlarg; urlarg = me.getParameterByName('nogui'); if(urlarg != "") { me.nogui = (urlarg == 'true'); } urlarg = me.getParameterByName('nocompass'); if(urlarg != "") { me.nocompass = (urlarg == 'true'); } }, initialize: function() { var me = this; // Get a handle to the DOM element which acts as the overall container and apply a class of // "dynmap" to it. var container = $(me.options.container); container.addClass('dynmap'); // Create a new container within the main container which actually holds the map. It needs a // class of "map". var mapContainer; (mapContainer = $('
')) .addClass('map') .appendTo(container); // Set the title if the options specify one. if(me.options.title) document.title = me.options.title; // Try to set the default zoom level based on the URL parameter. var urlzoom = me.getIntParameterByName('zoom'); if(urlzoom != null) me.options.defaultzoom = urlzoom; // Decide whether or not the layer control will be visible based on the URL parameter or // or fallback to the options var showlayerctl = me.getParameterByName('showlayercontrol'); if(showlayerctl != "") me.options.showlayercontrol = showlayerctl; // If we still don't have a default zoom level, force it to be 1 if(typeof me.options.defaultzoom == 'undefined') me.options.defaultzoom = 1; // Decide whether we should be following a given player or not based solely on URL parameter. var initfollowplayer = me.getParameterByName('playername'); if(initfollowplayer != "") me.initfollow = initfollowplayer; // Derive the state of the sidebar based on the URL parameter. var sidebaropen = me.getParameterByName('sidebaropened'); if(sidebaropen == 'false' || sidebaropen == 'true' || sidebaropen == 'pinned') me.options.sidebaropened = sidebaropen; var map = this.map = new L.Map(mapContainer.get(0), { zoom: me.options.defaultzoom, center: new L.LatLng(0, 0), zoomAnimation: true, zoomControl: !me.nogui, attributionControl: false, crs: L.CRS.Simple, worldCopyJump: false }); window.map = map; // Placate Leaflet need for top-level 'map'.... map.on('zoomend', function() { $(me).trigger('zoomchanged'); }); /*google.maps.event.addListener(map, 'dragstart', function(mEvent) { me.followPlayer(null); });*/ // Sidebar var panel; var sidebar; var pinbutton; var nopanel = (me.getParameterByName('nopanel') == 'true') || me.nogui; var pincls = 'pinned'; if(me.options.sidebaropened == 'false') pincls = ''; sidebar = me.sidebar = $('
') .addClass('sidebar ' + pincls); panel = me.sidebarPanel = $('
') .addClass('panel') .appendTo(sidebar); if(me.options.sidebaropened != 'true') { // false or pinned // Pin button. pinbutton = $('
') .addClass('pin') .click(function() { sidebar.toggleClass('pinned'); }) .appendTo(panel); } if(!nopanel) sidebar.appendTo(container); var worldsSection = SidebarUtils.createListSection(me.options['msg-maptypes']); me.worldlist = worldsSection.content.addClass('worldlist'); worldsSection.section.appendTo(panel); me.sidebarSections.push(worldsSection); var maplists = {}; var worldsadded = {}; $.each(me.worlds, function(index, world) { var maplist; world.element = $('
  • ') .addClass('world subsection') .text(world.title) .append(maplist = $('