"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; 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: new Date().getUTCMilliseconds(), /* Pseudorandom - prevent cached '?0' */ servertime: 0, serverday: false, inittime: new Date().getTime(), followingPlayer: '', missedupdates: 0, layercontrol: undefined, 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); 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 != "") { 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; }, initialize: function() { var me = this; var container = $(me.options.container); container.addClass('dynmap'); var mapContainer; (mapContainer = $('
')) .addClass('map') .appendTo(container); var urlzoom = me.getIntParameterByName('zoom'); if(urlzoom != null) me.options.defaultzoom = urlzoom; if(typeof me.options.defaultzoom == 'undefined') me.options.defaultzoom = 1; var map = this.map = new L.Map(mapContainer.get(0), { zoom: me.options.defaultzoom, center: new L.LatLng(0, 0), zoomAnimation: true, attributionControl: false, crs: L.Util.extend({}, L.CRS, { code: 'simple', projection: { project: function(latlng) { return new L.Point(latlng.lat, latlng.lng); }, unproject: function(point, unbounded) { return new L.LatLng(point.x, point.y, true); } }, transformation: new L.Transformation(1, 0, 1, 0) }), scale: function(zoom) { return (1 << zoom); } }); window.map = map; // Placate Leaflet need for top-level 'map'.... map.zoom_changed = function() { me.maptype.updateTileSize(me.map.zoom); $(me).trigger('zoomchanged'); }; /*google.maps.event.addListener(map, 'dragstart', function(mEvent) { me.followPlayer(null); });*/ me.layercontrol = new DynmapLayerControl(); map.addControl(me.layercontrol); // 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 = $('