var regionConstructors = {}; componentconstructors['regions'] = function(dynmap, configuration) { // Compatibility with older configurations. if (configuration.regionstyle) { configuration.regionstyle = $.extend({ stroke: true, color: configuration.strokeColor, opacity: configuration.strokeOpacity, weight: configuration.strokeWeight, fill: true }, configuration.regionstyle); } // Helper functions latlng = function(x, y, z) { return dynmap.getProjection().fromLocationToLatLng(new Location(undefined, x,y,z)); } function create3DBoxLayer(maxx, minx, maxy, miny, maxz, minz) { return new L.FeatureGroup([ new L.Polygon([ latlng(minx,miny,minz), latlng(maxx,miny,minz), latlng(maxx,miny,maxz), latlng(minx,miny,maxz) ], configuration.regionstyle), new L.Polygon([ latlng(minx,maxy,minz), latlng(maxx,maxy,minz), latlng(maxx,maxy,maxz), latlng(minx,maxy,maxz) ], configuration.regionstyle), new L.Polygon([ latlng(minx,miny,minz), latlng(minx,maxy,minz), latlng(maxx,maxy,minz), latlng(maxx,miny,minz) ], configuration.regionstyle), new L.Polygon([ latlng(maxx,miny,minz), latlng(maxx,maxy,minz), latlng(maxx,maxy,maxz), latlng(maxx,miny,maxz) ], configuration.regionstyle), new L.Polygon([ latlng(minx,miny,maxz), latlng(minx,maxy,maxz), latlng(maxx,maxy,maxz), latlng(maxx,miny,maxz) ], configuration.regionstyle), new L.Polygon([ latlng(minx,miny,minz), latlng(minx,maxy,minz), latlng(minx,maxy,maxz), latlng(minx,miny,maxz) ], configuration.regionstyle) ]); } function create2DBoxLayer(maxx, minx, maxy, miny, maxz, minz) { return new L.Polygon([ latlng(minx,64,minz), latlng(maxx,64,minz), latlng(maxx,64,maxz), latlng(minx,64,maxz) ], configuration.regionstyle); } function createPopupContent(name, region) { return $('
').addClass('regioninfo') .append($('').addClass('regionname').text(name)) .append($('').addClass('owners') .append(region.owners.players && $('').addClass('playerowners').text(region.owners.players.concat())) .append(region.owners.groups && $('').addClass('groupowners').text(region.owners.groups.concat())) ) .append($('').addClass('members') .append(region.members.players && $('').addClass('playermembers').text(region.members.players.concat())) .append(region.members.groups && $('').addClass('groupmembers').text(region.members.groups.concat())) ) .append(region.parent && $('').addClass('regionparent').text(region.parent)) .append(region.flags && function() { var regionflags = $('').addClass('regionflags'); $.each(region.flags, function(name, value) { regionflags.append($('').addClass('regionflag').text(name + ': ' + value)); }); return regionflags; }()) .append($('').addClass('regionpriority').text(region.priority)) [0]; } var self = this; loadcss('css/regions.css'); var regionType = configuration.name; loadjs('js/regions_' + regionType + '.js', function() { var activeLayer = undefined; function undraw() { if (activeLayer) { dynmap.map.removeLayer(activeLayer); activeLayer = undefined; } } function redraw() { undraw(); var worldName = dynmap.world && dynmap.world.name; if (worldName) { regionConstructors[regionType](dynmap, $.extend({}, configuration, { component: self, worldName: worldName, createPopupContent: createPopupContent, createBoxLayer: configuration.use3dregions ? create3DBoxLayer : create2DBoxLayer, result: function(regionsLayer) { activeLayer = regionsLayer; dynmap.map.addLayer(activeLayer); } })); } } $(dynmap).bind('mapchanged', redraw); $(dynmap).bind('mapchanging', undraw); redraw(); }); }