source: binary-improvements/webserver/js/leaflet.layer.landclaims.js@ 300

Last change on this file since 300 was 256, checked in by alloc, 9 years ago

Mod 6-8-12

File size: 2.4 KB
Line 
1function GetLandClaimsLayer (map, mapinfo) {
2 var landClaimsGroup = L.layerGroup();
3 var landClaimsClusterGroup = L.markerClusterGroup({
4 disableClusteringAtZoom: mapinfo.maxzoom,
5 singleMarkerMode: true,
6 maxClusterRadius: 50
7 });
8 var landClaimsRectGroup = L.layerGroup();
9 landClaimsGroup.addLayer(landClaimsClusterGroup);
10 landClaimsGroup.addLayer(landClaimsRectGroup);
11 var maxZoomForCluster = -1;
12
13
14 var setLandClaims = function(data) {
15 landClaimsClusterGroup.clearLayers();
16 landClaimsRectGroup.clearLayers();
17
18 var claimPower = Math.floor(Math.log(data.claimsize) / Math.LN2);
19 var maxClusterZoomUnlimited = mapinfo.maxzoom - (claimPower - 3);
20 var maxClusterZoomLimitedMax = Math.min(maxClusterZoomUnlimited, mapinfo.maxzoom+1);
21 maxZoomForCluster = Math.max(maxClusterZoomLimitedMax, 0);
22
23 checkClaimClustering({target: map});
24
25 var sizeHalf = Math.floor(data.claimsize / 2);
26
27 $.each( data.claimowners, function( key, val ) {
28 var steamid = val.steamid;
29 var active = val.claimactive;
30 var color = active ? "#55ff55" : "#ff0000";
31 if (val.playername) {
32 var name = val.playername;
33 } else {
34 var name = "<unknown>"
35 }
36
37 $.each( val.claims, function( key, val ) {
38 var pos = L.latLng(val.x, val.z);
39 var bounds = L.latLngBounds(L.latLng(val.x - sizeHalf, val.z - sizeHalf), L.latLng(val.x + sizeHalf, val.z + sizeHalf));
40 var r = L.rectangle(bounds, {color: color, weight: 1, opacity: 0.8, fillOpacity: 0.15});
41 var m = L.marker(pos, { clickable: false, keyboard: false, zIndexOffset:-1000, iconSize: [0,0], icon: L.divIcon({className: 'invisIcon', iconSize:[0,0]}) });
42 r.bindPopup("Owner: " + name + " ("+steamid+")<br/>Position: " + val.x + " " + val.y + " " + val.z);
43 landClaimsRectGroup.addLayer(r);
44 landClaimsClusterGroup.addLayer(m);
45 });
46 });
47 }
48
49 var updateClaimsEvent = function() {
50 $.getJSON( "../api/getlandclaims")
51 .done(setLandClaims)
52 .fail(function(jqxhr, textStatus, error) {
53 console.log("Error fetching land claim list");
54 })
55 }
56
57
58 var checkClaimClustering = function(e) {
59 if (e.target._zoom >= maxZoomForCluster) {
60 landClaimsGroup.removeLayer(landClaimsClusterGroup);
61 } else {
62 landClaimsGroup.addLayer(landClaimsClusterGroup);
63 }
64 };
65
66 map.on('zoomend', checkClaimClustering);
67
68 map.on('overlayadd', function(e) {
69 if (e.layer == landClaimsGroup) {
70 updateClaimsEvent();
71 }
72 });
73
74 return landClaimsGroup;
75}
76
Note: See TracBrowser for help on using the repository browser.