/
leaflet.html
150 lines (121 loc) · 4.63 KB
/
leaflet.html
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html>
<head>
<title>Leaflet</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin=""/>
<style>
body {
padding: 0;
margin: 0;
}
html, body, #mapid {
height: 100%;
width: 100vw;
}
.leaflet-div-icon {
background-color: rgba(0,0,0,0);
border: 0;
}
.leaflet-popup-content {
margin: 0;
}
.source {
margin: 1px 19px 1px 10px;
border-bottom: dashed 1px #888888;
}
.text {
margin: 0 10px;
}
</style>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js" integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw==" crossorigin=""></script>
</head>
<body>
<div id="mapid"></div>
<script>
var firstTime = true;
var mymap = L.map('mapid').fitWorld();
var group1 = L.layerGroup();
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
attribution: '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>',
id: 'mapbox.streets'
}).addTo(mymap);
function makeNodeList(rawNodes) {
group1.clearLayers();
for (var key in rawNodes) {
var ret = addNode(rawNodes[key])
if(ret != null) { // bugfix: remove error message
group1.addLayer(ret);
}
}
group1.addTo(mymap);
}
function addNode(str) {
//TODO: process ssid first
// degrees and minutes to decimal degrees
newLat=parseFloat(str.lat.slice(0,2))+(parseFloat(str.lat.slice(2,7))/60.0);
newLon=parseFloat(str.lon.slice(0,3))+(parseFloat(str.lon.slice(3,8))/60.0);
if(str.lat.slice[7] == "S") {newLat= -Math.abs(newLat);}
if(str.lon.slice[8] == "W") {newLon= -Math.abs(newLon);}
if((newLat == 0) && (newLon == 0)) return;
// choose symbol table
if (str.symb[0] == "\\") {
table="alternate.png";
} else {
table="primary.png";
}
// choose symbol
if (str.symb[1] >= "!" && str.symb[1] <= "0") {
y = 1;
x = 2+(21*(str.symb[1].charCodeAt(0)-"!".charCodeAt(0)));
} else if (str.symb[1] >= "1" && str.symb[1] <= "@") {
y = 22;
x = 2+(21*(str.symb[1].charCodeAt(0)-"1".charCodeAt(0)));
} else if (str.symb[1] >= "A" && str.symb[1] <= "P") {
y = 43;
x = 2+(21*(str.symb[1].charCodeAt(0)-"A".charCodeAt(0)));
} else if (str.symb[1] >= "Q" && str.symb[1] <= "`") {
y = 64;
x = 2+(21*(str.symb[1].charCodeAt(0)-"Q".charCodeAt(0)));
} else if (str.symb[1] >= "a" && str.symb[1] <= "p") {
y = 85;
x = 2+(21*(str.symb[1].charCodeAt(0)-"a".charCodeAt(0)));
} else if (str.symb[1] >= "q" && str.symb[1] <= "~") {
y = 106;
x = 2+(21*(str.symb[1].charCodeAt(0)-"q".charCodeAt(0)));
}
// apply selection
var myIcon = L.divIcon({
html: "<img style=\"position: absolute; border:0; width:19px; height:20px; background:url('"+table+"') -"+x+"px -"+y+"px;\" src=\"blank.png\">",
iconSize: [19, 20],
iconAnchor: [10, 10],
popupAnchor: [0, -10]
});
// take status text if defined
stat = "";
if ("status" in str) {
stat = "<br>Status: <b>"+str["status"]+"</b>";
}
// take message part
msg = "";
if ("message" in str) {
msg = "<br>Message: <b>"+str["message"]+"</b>";
}
// make new node
var node = L.marker([newLat, newLon],{icon: myIcon});
node.bindPopup("<div class='source'>"+str.id+" (from "+str.src+")</div>"+"<div class='text'>"+str.time+stat+msg+"<br><i>"+str.info[1]+"</i><br>("+str.rpt+")</div>");
// if first time here, then zoom to first node
if (firstTime) {
firstTime = false;
mymap.setZoom(9);
mymap.panTo(L.latLng(newLat, newLon));
}
return node;
}
</script>
</body>
</html>