2011-04-14 02:58:25 +02:00
|
|
|
var regionConstructors = {};
|
|
|
|
|
2011-07-21 00:49:52 +02:00
|
|
|
componentconstructors['regions'] = function(dynmap, configuration) {
|
2011-07-22 00:26:32 +02:00
|
|
|
|
2011-07-21 23:43:22 +02:00
|
|
|
// Compatibility with older configurations.
|
|
|
|
if (configuration.regionstyle) {
|
|
|
|
configuration.regionstyle = $.extend({
|
2011-08-22 17:31:27 +02:00
|
|
|
stroke: (configuration.regionstyle.strokeOpacity > 0.0),
|
|
|
|
color: configuration.regionstyle.strokeColor,
|
|
|
|
opacity: configuration.regionstyle.strokeOpacity,
|
|
|
|
weight: configuration.regionstyle.strokeWeight,
|
|
|
|
fill: (configuration.regionstyle.fillOpacity > 0.0),
|
|
|
|
smoothFactor: 0.0
|
2011-07-21 23:43:22 +02:00
|
|
|
}, configuration.regionstyle);
|
|
|
|
}
|
|
|
|
|
2011-07-22 00:26:32 +02:00
|
|
|
// 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);
|
|
|
|
}
|
2011-08-11 03:47:14 +02:00
|
|
|
|
|
|
|
function create3DOutlineLayer(xarray, maxy, miny, zarray) {
|
|
|
|
var toplist = [];
|
|
|
|
var botlist = [];
|
|
|
|
var i;
|
|
|
|
var polylist = [];
|
|
|
|
for(i = 0; i < xarray.length; i++) {
|
|
|
|
toplist[i] = latlng(xarray[i], maxy, zarray[i]);
|
|
|
|
botlist[i] = latlng(xarray[i], miny, zarray[i]);
|
|
|
|
}
|
|
|
|
for(i = 0; i < xarray.length; i++) {
|
|
|
|
var sidelist = [];
|
|
|
|
sidelist[0] = toplist[i];
|
|
|
|
sidelist[1] = botlist[i];
|
|
|
|
sidelist[2] = botlist[(i+1)%xarray.length];
|
|
|
|
sidelist[3] = toplist[(i+1)%xarray.length];
|
|
|
|
polylist[i] = new L.Polygon(sidelist, configuration.regionstyle);
|
|
|
|
}
|
|
|
|
polylist[xarray.length] = new L.Polygon(botlist, configuration.regionstyle);
|
|
|
|
polylist[xarray.length+1] = new L.Polygon(toplist, configuration.regionstyle);
|
|
|
|
|
|
|
|
return new L.FeatureGroup(polylist);
|
|
|
|
}
|
|
|
|
|
|
|
|
function create2DOutlineLayer(xarray, maxy, miny, zarray) {
|
|
|
|
var llist = [];
|
|
|
|
var i;
|
|
|
|
for(i = 0; i < xarray.length; i++) {
|
|
|
|
llist[i] = latlng(xarray[i], 64, zarray[i]);
|
|
|
|
}
|
|
|
|
return new L.Polygon(llist, configuration.regionstyle);
|
|
|
|
}
|
2011-07-22 00:26:32 +02:00
|
|
|
|
|
|
|
function createPopupContent(name, region) {
|
2011-07-29 17:14:58 +02:00
|
|
|
function join(a) {
|
|
|
|
if (a instanceof Array) {
|
|
|
|
return a.join(', ');
|
|
|
|
} else if (typeof a === 'string') {
|
|
|
|
return a;
|
2011-08-21 22:57:21 +02:00
|
|
|
} else {
|
|
|
|
return "";
|
2011-07-29 17:14:58 +02:00
|
|
|
}
|
|
|
|
}
|
2011-07-28 05:42:55 +02:00
|
|
|
var members = region.members || {};
|
2011-08-21 22:57:21 +02:00
|
|
|
var popup = this.infowindow || '<div class="infowindow"><span style="font-size:120%;">%regionname%</span><br /> Owner <span style="font-weight:bold;">%playerowners%</span><br />Flags<br /><span style="font-weight:bold;">%flags%</span></div>';
|
|
|
|
popup = popup.replace('%regionname%', name);
|
|
|
|
popup = popup.replace('%playerowners%', join(region.owners.players));
|
|
|
|
popup = popup.replace('%groupowners%', join(region.owners.groups));
|
2011-08-22 08:17:28 +02:00
|
|
|
popup = popup.replace('%playermanagers%', join(region.associates || ""));
|
2011-08-21 22:57:21 +02:00
|
|
|
popup = popup.replace('%playermembers%', join(members.players));
|
|
|
|
popup = popup.replace('%groupmembers%', join(members.groups));
|
2011-08-22 08:17:28 +02:00
|
|
|
popup = popup.replace('%parent%', region.parent || "");
|
|
|
|
popup = popup.replace('%priority%', region.priority || "");
|
2011-08-21 22:57:21 +02:00
|
|
|
var regionflags = "";
|
|
|
|
$.each(region.flags, function(name, value) {
|
|
|
|
regionflags = regionflags + "<span>" + name + ": " + value + "</span><br>";
|
|
|
|
});
|
|
|
|
popup = popup.replace('%flags%', regionflags);
|
2011-07-22 00:26:32 +02:00
|
|
|
return $('<div/>').addClass('regioninfo')
|
2011-08-21 22:57:21 +02:00
|
|
|
.append(popup)[0];
|
2011-07-22 00:26:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
loadcss('css/regions.css');
|
|
|
|
var regionType = configuration.name;
|
2011-07-21 00:49:52 +02:00
|
|
|
loadjs('js/regions_' + regionType + '.js', function() {
|
2011-07-22 00:26:32 +02:00
|
|
|
var activeLayer = undefined;
|
2011-07-21 00:49:52 +02:00
|
|
|
function undraw() {
|
2011-07-22 00:26:32 +02:00
|
|
|
if (activeLayer) {
|
|
|
|
dynmap.map.removeLayer(activeLayer);
|
|
|
|
activeLayer = undefined;
|
2011-07-21 00:49:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function redraw() {
|
|
|
|
undraw();
|
|
|
|
var worldName = dynmap.world && dynmap.world.name;
|
|
|
|
if (worldName) {
|
2011-07-22 00:26:32 +02:00
|
|
|
regionConstructors[regionType](dynmap, $.extend({}, configuration, {
|
|
|
|
component: self,
|
|
|
|
worldName: worldName,
|
|
|
|
createPopupContent: createPopupContent,
|
|
|
|
createBoxLayer: configuration.use3dregions ? create3DBoxLayer : create2DBoxLayer,
|
2011-08-11 03:47:14 +02:00
|
|
|
createOutlineLayer: configuration.use3dregions ? create3DOutlineLayer : create2DOutlineLayer,
|
2011-07-22 00:26:32 +02:00
|
|
|
result: function(regionsLayer) {
|
|
|
|
activeLayer = regionsLayer;
|
|
|
|
dynmap.map.addLayer(activeLayer);
|
|
|
|
}
|
|
|
|
}));
|
2011-07-21 00:49:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$(dynmap).bind('mapchanged', redraw);
|
|
|
|
$(dynmap).bind('mapchanging', undraw);
|
|
|
|
redraw();
|
2011-04-14 02:58:25 +02:00
|
|
|
});
|
2011-07-21 00:49:52 +02:00
|
|
|
}
|