mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-08-20 11:22:44 +02:00
Merge pull request #399 from mikeprimm/master
Add poly2d region support back to WorldGuard support
This commit is contained in:
commit
7e8e0411d9
|
@ -67,6 +67,38 @@ componentconstructors['regions'] = function(dynmap, configuration) {
|
|||
latlng(minx,64,maxz)
|
||||
], 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 join(a) {
|
||||
|
@ -120,6 +152,7 @@ componentconstructors['regions'] = function(dynmap, configuration) {
|
|||
worldName: worldName,
|
||||
createPopupContent: createPopupContent,
|
||||
createBoxLayer: configuration.use3dregions ? create3DBoxLayer : create2DBoxLayer,
|
||||
createOutlineLayer: configuration.use3dregions ? create3DOutlineLayer : create2DOutlineLayer,
|
||||
result: function(regionsLayer) {
|
||||
activeLayer = regionsLayer;
|
||||
dynmap.map.addLayer(activeLayer);
|
||||
|
|
|
@ -19,6 +19,27 @@ regionConstructors['WorldGuard'] = function(dynmap, configuration) {
|
|||
region.min.y = region.max.y - 1;
|
||||
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('.'));
|
||||
regionFile += '_'+configuration.worldName+'.json';
|
||||
|
@ -35,6 +56,13 @@ regionConstructors['WorldGuard'] = function(dynmap, configuration) {
|
|||
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));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user