dynmap/web/js/regions_WorldGuard.js

42 lines
1.4 KiB
JavaScript
Raw Normal View History

regionConstructors['WorldGuard'] = function(dynmap, configuration) {
// Helper function.
function createBoxFromRegion(region, boxCreator) {
function ArrayMax( array ) {
return Math.max.apply( Math, array );
}
function ArrayMin( array ) {
return Math.min.apply( Math, array );
2011-07-21 00:49:52 +02:00
}
if(region.points) {
var i;
var xs = region.points.map(function(p) { return p.x; });
var zs = region.points.map(function(p) { return p.z; });
return boxCreator(ArrayMax(xs), ArrayMin(xs), region['max-y'], region['min-y'], ArrayMax(zs), ArrayMin(zs));
}
if(!region.min || !region.max)
2011-08-10 15:14:48 +02:00
return null;
if(region.max.y <= region.min.y)
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);
}
var regionFile = configuration.filename.substr(0, configuration.filename.lastIndexOf('.'));
regionFile += '_'+configuration.worldName+'.json';
2011-07-21 00:49:52 +02:00
$.getJSON('standalone/'+regionFile, function(data) {
var boxLayers = [];
2011-07-21 00:49:52 +02:00
$.each(data, function(name, region) {
2011-08-10 15:14:48 +02:00
// Only handle cuboids for the moment (therefore skipping 'global')
if (region.type === 'cuboid') {
var boxLayer = createBoxFromRegion(region, configuration.createBoxLayer);
// Skip errorous regions.
if (boxLayer) {
boxLayer.bindPopup(configuration.createPopupContent(name, region));
boxLayers.push(boxLayer);
}
}
});
configuration.result(new L.LayerGroup(boxLayers));
2011-07-21 00:49:52 +02:00
});
2011-07-21 00:49:52 +02:00
};