Merge pull request #399 from mikeprimm/master

Add poly2d region support back to WorldGuard support
This commit is contained in:
mikeprimm 2011-08-10 18:48:36 -07:00
commit 7e8e0411d9
2 changed files with 61 additions and 0 deletions

View File

@ -68,6 +68,38 @@ componentconstructors['regions'] = function(dynmap, configuration) {
], configuration.regionstyle); ], configuration.regionstyle);
} }
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);
}
function createPopupContent(name, region) { function createPopupContent(name, region) {
function join(a) { function join(a) {
if (a instanceof Array) { if (a instanceof Array) {
@ -120,6 +152,7 @@ componentconstructors['regions'] = function(dynmap, configuration) {
worldName: worldName, worldName: worldName,
createPopupContent: createPopupContent, createPopupContent: createPopupContent,
createBoxLayer: configuration.use3dregions ? create3DBoxLayer : create2DBoxLayer, createBoxLayer: configuration.use3dregions ? create3DBoxLayer : create2DBoxLayer,
createOutlineLayer: configuration.use3dregions ? create3DOutlineLayer : create2DOutlineLayer,
result: function(regionsLayer) { result: function(regionsLayer) {
activeLayer = regionsLayer; activeLayer = regionsLayer;
dynmap.map.addLayer(activeLayer); dynmap.map.addLayer(activeLayer);

View File

@ -20,6 +20,27 @@ regionConstructors['WorldGuard'] = function(dynmap, configuration) {
return boxCreator(region.max.x, region.min.x, region.max.y, region.min.y, region.max.z, region.min.z); return boxCreator(region.max.x, region.min.x, region.max.y, region.min.y, region.max.z, region.min.z);
} }
function createOutlineFromRegion(region, outCreator) {
var xarray = [];
var zarray = [];
if(region.points) {
var i;
for(i = 0; i < region.points.length; i++) {
xarray[i] = region.points[i].x;
zarray[i] = region.points[i].z;
}
}
var ymin = 64;
var ymax = 64;
if(region['max-y'])
ymax = region['max-y'];
if(region['min-y'])
ymin = region['min-y'];
if(ymax < ymin) ymax = ymin;
return outCreator(xarray, ymax, ymin, zarray);
}
var regionFile = configuration.filename.substr(0, configuration.filename.lastIndexOf('.')); var regionFile = configuration.filename.substr(0, configuration.filename.lastIndexOf('.'));
regionFile += '_'+configuration.worldName+'.json'; regionFile += '_'+configuration.worldName+'.json';
$.getJSON('standalone/'+regionFile, function(data) { $.getJSON('standalone/'+regionFile, function(data) {
@ -35,6 +56,13 @@ regionConstructors['WorldGuard'] = function(dynmap, configuration) {
boxLayers.push(boxLayer); boxLayers.push(boxLayer);
} }
} }
else if(region.type === 'poly2d') {
var outLayer = createOutlineFromRegion(region, configuration.createOutlineLayer);
if (outLayer) {
outLayer.bindPopup(configuration.createPopupContent(name, region));
boxLayers.push(outLayer);
}
}
}); });
configuration.result(new L.LayerGroup(boxLayers)); configuration.result(new L.LayerGroup(boxLayers));