mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-01 06:33:38 +01:00
Reworked Residence to work with Leaflet (and new regions-structure).
This commit is contained in:
parent
fd542d2b33
commit
0fb56c95bb
@ -1,5 +1,46 @@
|
|||||||
var regionConstructors = {};
|
var regionConstructors = {};
|
||||||
|
|
||||||
|
function createPolygonSurfaces(latlng, maxx, minx, maxy, miny, maxz, minz) {
|
||||||
|
return [
|
||||||
|
new L.Polygon([
|
||||||
|
latlng(minx,miny,minz),
|
||||||
|
latlng(maxx,miny,minz),
|
||||||
|
latlng(maxx,miny,maxz),
|
||||||
|
latlng(minx,miny,maxz)
|
||||||
|
], {}),
|
||||||
|
new L.Polygon([
|
||||||
|
latlng(minx,maxy,minz),
|
||||||
|
latlng(maxx,maxy,minz),
|
||||||
|
latlng(maxx,maxy,maxz),
|
||||||
|
latlng(minx,maxy,maxz)
|
||||||
|
], {}),
|
||||||
|
new L.Polygon([
|
||||||
|
latlng(minx,miny,minz),
|
||||||
|
latlng(minx,maxy,minz),
|
||||||
|
latlng(maxx,maxy,minz),
|
||||||
|
latlng(maxx,miny,minz)
|
||||||
|
], {}),
|
||||||
|
new L.Polygon([
|
||||||
|
latlng(maxx,miny,minz),
|
||||||
|
latlng(maxx,maxy,minz),
|
||||||
|
latlng(maxx,maxy,maxz),
|
||||||
|
latlng(maxx,miny,maxz)
|
||||||
|
], {}),
|
||||||
|
new L.Polygon([
|
||||||
|
latlng(minx,miny,maxz),
|
||||||
|
latlng(minx,maxy,maxz),
|
||||||
|
latlng(maxx,maxy,maxz),
|
||||||
|
latlng(maxx,miny,maxz)
|
||||||
|
], {}),
|
||||||
|
new L.Polygon([
|
||||||
|
latlng(minx,miny,minz),
|
||||||
|
latlng(minx,maxy,minz),
|
||||||
|
latlng(minx,maxy,maxz),
|
||||||
|
latlng(minx,miny,maxz)
|
||||||
|
], {})
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
componentconstructors['regions'] = function(dynmap, configuration) {
|
componentconstructors['regions'] = function(dynmap, configuration) {
|
||||||
regionCfg = configuration;
|
regionCfg = configuration;
|
||||||
var regionType = regionCfg.name;
|
var regionType = regionCfg.name;
|
||||||
|
@ -1,137 +1,31 @@
|
|||||||
regionConstructors['polygon'] = function(map, resname, region)
|
function createPolygonsFromResidence(latlng, name, residence) {
|
||||||
{
|
return createPolygonSurfaces(residence.X1, residence.X2, residence.Y1, residence.Y2, residence.Z1, residence.Z2);
|
||||||
$.each(region.Areas, function(aname, area) {
|
|
||||||
var name = resname + '_' + aname;
|
|
||||||
if(regionCfg.use3dregions)
|
|
||||||
{
|
|
||||||
regionPolygons[name+'_bottom'] = new google.maps.Polygon($.extend(regionCfg.regionstyle, {
|
|
||||||
paths: [
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,area.Y1,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,area.Y1,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,area.Y1,area.Z2),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,area.Y1,area.Z2)
|
|
||||||
],
|
|
||||||
map: map
|
|
||||||
}));
|
|
||||||
google.maps.event.addListener(regionPolygons[name+'_bottom'] , 'click', function(event) {
|
|
||||||
regionInfo(event, resname, region);
|
|
||||||
});
|
|
||||||
|
|
||||||
regionPolygons[name+'_top'] = new google.maps.Polygon($.extend(regionCfg.regionstyle, {
|
|
||||||
paths: [
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,area.Y2,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,area.Y2,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,area.Y2,area.Z2),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,area.Y2,area.Z2)
|
|
||||||
],
|
|
||||||
map: map
|
|
||||||
}));
|
|
||||||
google.maps.event.addListener(regionPolygons[name+'_top'] , 'click', function(event) {
|
|
||||||
regionInfo(event, resname, region);
|
|
||||||
});
|
|
||||||
|
|
||||||
regionPolygons[name+'_east'] = new google.maps.Polygon($.extend(regionCfg.regionstyle, {
|
|
||||||
paths: [
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,area.Y1,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,area.Y2,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,area.Y2,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,area.Y1,area.Z1)
|
|
||||||
],
|
|
||||||
map: map
|
|
||||||
}));
|
|
||||||
google.maps.event.addListener(regionPolygons[name+'_east'] , 'click', function(event) {
|
|
||||||
regionInfo(event, resname, region);
|
|
||||||
});
|
|
||||||
|
|
||||||
regionPolygons[name+'_south'] = new google.maps.Polygon($.extend(regionCfg.regionstyle, {
|
|
||||||
paths: [
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,area.Y1,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,area.Y2,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,area.Y2,area.Z2),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,area.Y1,area.Z2)
|
|
||||||
],
|
|
||||||
map: map
|
|
||||||
}));
|
|
||||||
google.maps.event.addListener(regionPolygons[name+'_south'] , 'click', function(event) {
|
|
||||||
regionInfo(event, resname, region);
|
|
||||||
});
|
|
||||||
|
|
||||||
regionPolygons[name+'_west'] = new google.maps.Polygon($.extend(regionCfg.regionstyle, {
|
|
||||||
paths: [
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,area.Y1,area.Z2),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,area.Y2,area.Z2),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,area.Y2,area.Z2),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,area.Y1,area.Z2)
|
|
||||||
],
|
|
||||||
map: map
|
|
||||||
}));
|
|
||||||
google.maps.event.addListener(regionPolygons[name+'_west'] , 'click', function(event) {
|
|
||||||
regionInfo(event, resname, region);
|
|
||||||
});
|
|
||||||
|
|
||||||
regionPolygons[name+'_north'] = new google.maps.Polygon($.extend(regionCfg.regionstyle, {
|
|
||||||
paths: [
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,area.Y1,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,area.Y2,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,area.Y2,area.Z2),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,area.Y1,area.Z2)
|
|
||||||
],
|
|
||||||
map: map
|
|
||||||
}));
|
|
||||||
google.maps.event.addListener(regionPolygons[name+'_west'] , 'click', function(event) {
|
|
||||||
regionInfo(event, resname, region);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
middleY = area.Y2;
|
|
||||||
regionPolygons[name+'_bottom'] = new google.maps.Polygon($.extend(regionCfg.regionstyle, {
|
|
||||||
paths: [
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,middleY,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,middleY,area.Z1),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X2,middleY,area.Z2),
|
|
||||||
map.getProjection().fromWorldToLatLng(area.X1,middleY,area.Z2)
|
|
||||||
],
|
|
||||||
map: map
|
|
||||||
}));
|
|
||||||
google.maps.event.addListener(regionPolygons[name+'_bottom'] , 'click', function(event) {
|
|
||||||
regionInfo(event, resname, region);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
regionConstructors['info'] = function(event, name, region)
|
function createPopupContent(name, region) {
|
||||||
{
|
return $('<div/>')
|
||||||
var flags = "";
|
.append($('<span/>').addClass('regionname').text(name))
|
||||||
$.each(region.Permissions.AreaFlags, function(flag, status)
|
.append(region.owners.players && $('<span/>').addClass('playerowners').text(region.permissions.owner))
|
||||||
{
|
[0];
|
||||||
flags += flag+': '+status+'<br />';
|
};
|
||||||
});
|
|
||||||
var replace = ['%regionname%','%playerowners%','%flags%','%groupowners%', '%playermembers%', '%groupmembers%','%parent%', '%priority%'];
|
|
||||||
var by = [name,region.Permissions.Owner, flags, '', '', '', '', ''];
|
|
||||||
|
|
||||||
var contentString = arrayReplace(replace, by, regionCfg.infowindow)
|
regionConstructors['Residence'] = function(dynmap, worldName, result) {
|
||||||
|
var latlng = function(x, y, z) {
|
||||||
|
return dynmap.getProjection().fromLocationToLatLng(new Location(undefined, x,y,z));
|
||||||
|
};
|
||||||
|
|
||||||
regionInfoWindow.setContent(contentString);
|
$.getJSON('standalone/res_' + worldName + '.json', function(data) {
|
||||||
regionInfoWindow.setPosition(event.latLng);
|
var regionLayers = {};
|
||||||
|
$.each(data, function(name, residence) {
|
||||||
|
if(map === residence.Permissions.World) {
|
||||||
|
var polygons = createPolygonsFromResidence(latlng, name, residence);
|
||||||
|
var regionLayer = new L.FeatureGroup(polygons);
|
||||||
|
|
||||||
regionInfoWindow.open(dynmap.map);
|
regionLayer.bindPopup(createPopupContent(name, region));
|
||||||
}
|
|
||||||
regionConstructors['update'] = function(map)
|
regionLayers[name] = regionLayer;
|
||||||
{
|
}
|
||||||
if(regionInfoWindow)
|
|
||||||
regionInfoWindow.close();
|
|
||||||
$.each(regionPolygons, function(index, region)
|
|
||||||
{
|
|
||||||
region.setMap(null);
|
|
||||||
});
|
|
||||||
regionPolygons = {};
|
|
||||||
$.getJSON("standalone/res_" + map + ".json", function(data)
|
|
||||||
{
|
|
||||||
$.each(data, function(name, residence)
|
|
||||||
{
|
|
||||||
if(map == residence.Permissions.World)
|
|
||||||
makeRegionPolygonCube(dynmap.map, name, residence);
|
|
||||||
});
|
});
|
||||||
|
result(regionLayers);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
@ -1,53 +1,11 @@
|
|||||||
Array.max = function( array ){
|
Array.max = function( array ) {
|
||||||
return Math.max.apply( Math, array );
|
return Math.max.apply( Math, array );
|
||||||
};
|
};
|
||||||
Array.min = function( array ){
|
Array.min = function( array ) {
|
||||||
return Math.min.apply( Math, array );
|
return Math.min.apply( Math, array );
|
||||||
};
|
};
|
||||||
|
|
||||||
function createPolygonSurfaces(latlng, maxx, minx, maxy, miny, maxz, minz) {
|
function createPolygonsFromWorldGuardRegion(latlng, name, region) {
|
||||||
return [
|
|
||||||
new L.Polygon([
|
|
||||||
latlng(minx,miny,minz),
|
|
||||||
latlng(maxx,miny,minz),
|
|
||||||
latlng(maxx,miny,maxz),
|
|
||||||
latlng(minx,miny,maxz)
|
|
||||||
], {}),
|
|
||||||
new L.Polygon([
|
|
||||||
latlng(minx,maxy,minz),
|
|
||||||
latlng(maxx,maxy,minz),
|
|
||||||
latlng(maxx,maxy,maxz),
|
|
||||||
latlng(minx,maxy,maxz)
|
|
||||||
], {}),
|
|
||||||
new L.Polygon([
|
|
||||||
latlng(minx,miny,minz),
|
|
||||||
latlng(minx,maxy,minz),
|
|
||||||
latlng(maxx,maxy,minz),
|
|
||||||
latlng(maxx,miny,minz)
|
|
||||||
], {}),
|
|
||||||
new L.Polygon([
|
|
||||||
latlng(maxx,miny,minz),
|
|
||||||
latlng(maxx,maxy,minz),
|
|
||||||
latlng(maxx,maxy,maxz),
|
|
||||||
latlng(maxx,miny,maxz)
|
|
||||||
], {}),
|
|
||||||
new L.Polygon([
|
|
||||||
latlng(minx,miny,maxz),
|
|
||||||
latlng(minx,maxy,maxz),
|
|
||||||
latlng(maxx,maxy,maxz),
|
|
||||||
latlng(maxx,miny,maxz)
|
|
||||||
], {}),
|
|
||||||
new L.Polygon([
|
|
||||||
latlng(minx,miny,minz),
|
|
||||||
latlng(minx,maxy,minz),
|
|
||||||
latlng(minx,maxy,maxz),
|
|
||||||
latlng(minx,miny,maxz)
|
|
||||||
], {})
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
function createPolygonsFromWorldGuardRegion(latlng, name, region)
|
|
||||||
{
|
|
||||||
if(region.points) {
|
if(region.points) {
|
||||||
var i;
|
var i;
|
||||||
var xs = region.points.map(function(p) { return p.x; });
|
var xs = region.points.map(function(p) { return p.x; });
|
||||||
|
Loading…
Reference in New Issue
Block a user