-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaflet.main.js
103 lines (83 loc) · 3.19 KB
/
leaflet.main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var CCX_GlobalNodeMap = (function () {
var markerClusters = null;
var myIcon = null;
var mbAttr = null;
var map = null;
function Initialize() {
var self = this;
}
Initialize.load = function (container, callback) {
if (!map) {
map = L.map(container, {
center: [10.0, 5.0],
minZoom: 2,
zoom: 2
});
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: ['a', 'b', 'c']
}).addTo(map);
mbAttr = 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
mbUrl = 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw';
L.tileLayer(mbUrl, { id: 'mapbox.light', attribution: mbAttr }).addTo(map);
//L.tileLayer(mbUrl, {id: 'mapbox.streets', attribution: mbAttr});
myIcon = L.icon({
iconUrl: 'img/pin24.png',
iconRetinaUrl: 'img/pin48.png',
iconSize: [29, 24],
iconAnchor: [9, 21],
popupAnchor: [0, -14]
});
var mapTypeControl = L.Control.extend({
options: {
position: 'topleft'
},
onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-control-fullscreen leaflet-bar leaflet-control');
var mapType = 0;
container.style.backgroundColor = 'white';
container.style.backgroundImage = "url(img/cluster.png)";
container.style.backgroundSize = "30px 30px";
container.style.cursor = "pointer";
container.style.width = '35px';
container.style.height = '35px';
container.onclick = function () {
if (mapType == 0) {
markerClusters.disableClustering();
mapType = 1;
} else {
markerClusters.enableClustering();
mapType = 0;
}
}
return container;
}
});
markerClusters = L.markerClusterGroup();
map.addControl(new mapTypeControl());
map.addControl(new L.Control.Fullscreen());
}
// @TODO
$.getJSON("https://explorer.conceal.network/services/nodes/geodata", function (data) {
$("#nodesNumber").html("(" + data.length + " online)");
if (markerClusters) {
markerClusters.clearLayers();
map.removeLayer(markerClusters);
}
for (var i = 0; i < data.length; ++i) {
if (data[i].geoData) {
var popup = '<b>city:</b> ' + data[i].geoData.city + '<br/>' +
'<b>region:</b> ' + data[i].geoData.region + '<br/>' +
'<b>country:</b> ' + data[i].geoData.country;
var m = L.marker([data[i].geoData.ll[0], data[i].geoData.ll[1]], { icon: myIcon }).bindPopup(popup);
markerClusters.addLayer(m);
}
}
map.addLayer(markerClusters);
callback(true);
});
};
return Initialize;
})();