-
Notifications
You must be signed in to change notification settings - Fork 2
/
old_version.html
457 lines (407 loc) · 18.1 KB
/
old_version.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
<!DOCTYPE html>
<html>
<head>
<title>QONQR zone map</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="shortcut icon" href="https://qonqr.com/Images/favicon.ico/android-icon-192x192.png" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" />
<script src="https://rawcdn.githack.com/robertleeplummerjr/Leaflet.glify/466c3696d9f67b7833089c15317ae9b6d7e5a30f/dist/glify-browser.js"></script>
<script src="https://unpkg.com/leaflet-providers@1.3.0/leaflet-providers.js"></script>
<script src="https://unpkg.com/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.3.7/papaparse.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.3.2/spin.min.js"></script>
<script src="https://unpkg.com/leaflet-spin@1.1.0/leaflet.spin.min.js"></script>
<script src="https://unpkg.com/leaflet-search@2.9.8/dist/leaflet-search.src.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet-search@2.9.8/src/leaflet-search.css" />
<script src="https://nuclearsecrecy.github.io/Leaflet.greatCircle/Leaflet.greatCircle.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-164777450-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'UA-164777450-1');
</script>
<style>
body,
html,
#map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.legend {
color: white;
padding: 10px;
background-color: rgba(0, 0, 0, 0.8);
border-radius: 5px;
}
.uncaptured {
color: orange;
}
.legion {
color: red;
}
.swarm {
color: green;
}
.faceless {
color: purple;
}
.uncapturedBG {
background-color: orange;
}
.legionBG {
background-color: red;
}
.swarmBG {
background-color: green;
}
.facelessBG {
background-color: purple;
}
.link {
text-decoration: underline;
cursor: pointer;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
const zoneControlState = {
0: "uncaptured",
1: "legion",
2: "swarm",
3: "faceless"
}
const colours = {
0: { r: 1, g: 0.647, b: 0 },
1: { r: 1, g: 0, b: 0 },
2: { r: 0, g: 1, b: 0 },
3: { r: 0.5, g: 0, b: 0.5 }
}
var map = L.map('map', {
center: [15, 30],
zoom: 3,
maxBounds: [[-90, -360], [90, 360]],
worldCopyJump: true
});
var search = L.control.search({
sourceData: function(text, callback) {
callback(window.data);
},
propertyName: "Description",
propertyLoc: ["Latitude", "Longitude"],
marker: L.circleMarker([0,0], {color: "DeepSkyBlue", fillOpacity: 0})
});
map.addControl(search);
map.locate({
setView: true,
maxZoom: 5
}).on("locationfound", function (e) {
L.circle([e.latitude, e.longitude], { color: "cyan", radius: e.accuracy }).bindTooltip("You").addTo(map);
var range_km = 1609.34;
if (new Date().getUTCDay() == 1) { // Monday
var week = Math.floor(new Date().getUTCDate() / 7);
if (week == 1) {
range_km = 4828.032;
} else if (week == 2) {
range_km = 9656.064;
} else if (week >= 3) {
range_km = 20116.8;
}
}
L.greatCircle([e.latitude, e.longitude], { color: "cyan", fillOpacity: 0, weight: .5, radius: range_km * 1000, interactive: false }).addTo(map);
});
var baseMaps = {
"OSM": L.tileLayer.provider("OpenStreetMap.Mapnik"),
"OSM Grayscale": L.tileLayer.provider("OpenStreetMap.BlackAndWhite"),
"CartoDB Positron": L.tileLayer.provider('CartoDB.Positron'),
"CartoDB Dark Matter": L.tileLayer.provider("CartoDB.DarkMatter").addTo(map),
"ESRI WorldImagery": L.tileLayer.provider("Esri.WorldImagery"),
"Google Hybrid": L.tileLayer('http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}', {
maxZoom: 20,
subdomains: ['mt0', 'mt1', 'mt2', 'mt3']
}),
"Wikimedia": L.tileLayer.provider("Wikimedia")
}
var uncaptured = L.layerGroup().addTo(map);
var legion = L.layerGroup().addTo(map);
var swarm = L.layerGroup().addTo(map);
var faceless = L.layerGroup().addTo(map);
map.createPane('labels');
map.getPane('labels').style.zIndex = 625;
map.getPane('labels').style.pointerEvents = 'none';
var labels = L.tileLayer.provider("Stamen.TonerLabels", {
pane: "labels",
interactive: false,
opacity: .8,
});
map.createPane('whitelabels');
map.getPane('whitelabels').style.zIndex = 625;
map.getPane('whitelabels').style.pointerEvents = 'none';
map.getPane('whitelabels').style.filter = 'invert(100%)';
var whitelabels = L.tileLayer.provider("Stamen.TonerLabels", {
pane: "whitelabels",
interactive: false,
opacity: .8,
});
var overlays = {
"Uncaptured": uncaptured,
"Legion": legion,
"Swarm": swarm,
"Faceless": faceless,
"City labels": labels,
"City labels (white)": whitelabels,
}
L.control.layers(baseMaps, overlays).addTo(map);
var layers = Object.keys(overlays);
window.teamfilter = [0, 1, 2, 3];
map.on("overlayadd", function (e) {
if (!window.data) return;
layers.push(e.name);
var indices = layers.map(e => Object.keys(overlays).indexOf(e));
window.teamfilter = indices;
updateURL();
createPointsLayer();
}).on("overlayremove", function (e) {
if (!window.data) return;
layers.splice(layers.indexOf(e.name), 1);
var indices = layers.map(e => Object.keys(overlays).indexOf(e));
window.teamfilter = indices;
updateURL();
createPointsLayer();
});
function clamp(num) {
var min = 10;
var max = 50;
return num <= min ? min : num >= max ? max : num;
}
function formatDelta(delta) {
if (!delta) {
return "";
} else if (delta >= 0) {
delta = "+" + delta.toLocaleString();
}
return " (" + delta.toLocaleString() + ")";
}
function buildDescString(d) {
var className = zoneControlState[d.ZoneControlState]
var desc = "<b class='" + className + "'>" + d.Description + "</b>" +
"<br>Zone ID: " + d.ZoneId +
"<br>Captured: " + d.DateCapturedUtc.slice(0, 19) +
"<br>Last updated: " + d.LastUpdateDateUtc.slice(0, 19) +
"<div class='legion'>Legion: " + d.LegionCount.toLocaleString() + formatDelta(d.LegionDelta) +
"</div><div class='swarm'>Swarm: " + d.SwarmCount.toLocaleString() + formatDelta(d.SwarmDelta) +
"</div><div class='faceless'>Faceless: " + d.FacelessCount.toLocaleString() + formatDelta(d.FacelessDelta) + "</div>";
return desc;
}
function createPointsLayer() {
console.log(window.data.length);
if (window.countfilter == "contested") {
var data = window.data.filter(function(e) {
if (e.ZoneControlState == 0) return false; // Uncaptured zones are by definition uncontested
// A Legion held zone, where the total bot count is equal to the legion bot count, is uncontested
if (e.ZoneControlState == 1 && e.TotalCount == e.LegionCount) return false;
if (e.ZoneControlState == 2 && e.TotalCount == e.SwarmCount) return false;
if (e.ZoneControlState == 3 && e.TotalCount == e.FacelessCount) return false;
return new Date(e.LastUpdateDateUtc.replace(" ", "T") + "Z") > window.timefilter && window.teamfilter.includes(e.ZoneControlState)
});
console.log(data);
} else if (window.countfilter == "colocated") {
var data = window.data.filter(e => e.colocated &&
new Date(e.LastUpdateDateUtc.replace(" ", "T") + "Z") > window.timefilter &&
window.teamfilter.includes(e.ZoneControlState)
)
} else {
var data = window.data.filter(e => e.TotalCount >= window.countfilter &&
new Date(e.LastUpdateDateUtc.replace(" ", "T") + "Z") > window.timefilter &&
window.teamfilter.includes(e.ZoneControlState)
)
}
console.log(data.length);
var points = data.map(e => [e.Latitude, e.Longitude]);
if (window.pointsLayer) window.pointsLayer.remove()
window.pointsLayer = L.glify.points({
map: map,
size: function (i, e) {
return clamp(data[i].TotalCount / 1E6);
},
color: function (i, e) {
return colours[data[i].ZoneControlState]
},
click: function (e, feature) {
var i = points.indexOf(feature);
L.popup()
.setLatLng(e.latlng)
.setContent(buildDescString(data[i]))
.openOn(map);
},
data: points,
opacity: 1,
//fragmentShaderSource: L.glify.shader.fragment.simpleCircle
});
updateStats(data);
}
function updateStats(data) {
var totalLegion = 0, totalSwarm = 0, totalFaceless = 0;
for (var d of data) {
totalLegion += d.LegionCount;
totalSwarm += d.SwarmCount;
totalFaceless += d.FacelessCount;
}
$("#stats").html("<div class='legion'>Total Legion bots:" + totalLegion.toLocaleString() +
"</div><div class='swarm'>Total Swarm bots: " + totalSwarm.toLocaleString() +
"</div><div class='faceless'>Total Faceless bots: " + totalFaceless.toLocaleString() +
"</div><div>Total zones: " + data.length.toLocaleString() + "</div><div id='top10'>Top 10 zones:</div>");
var sorted_data = data.filter(e => e.TotalDelta != undefined).sort((a, b) => a.TotalDelta < b.TotalDelta ? 1 : -1);
var top10 = sorted_data.slice(0, 10);
for (var i in top10) {
var d = top10[i];
var className = zoneControlState[d.ZoneControlState];
var country = countries[d.CountryId].Description;
var region = regions[d.RegionId].description;
$("#top10").append("<div onclick='map.flyTo([" + d.Latitude + "," + d.Longitude + "], 12)' class='link " +
className + "'>" + d.Description + ", " + region + ", " + country + "</div>")
}
}
var baseUrl = "https://raw.githubusercontent.com/neon-ninja/QONQR_zonedata/master/data/";
map.spin(true, { color: "white" });
Papa.parse(baseUrl + "Countries.csv", {
download: true,
header: true,
dynamicTyping: true,
complete: function (countries) {
window.countries = {}
for (var i in countries.data) {
var c = countries.data[i];
window.countries[c.countryid] = c;
}
Papa.parse(baseUrl + "Regions.csv", {
download: true,
header: true,
dynamicTyping: true,
complete: function (regions) {
window.regions = {}
for (var i in regions.data) {
var r = regions.data[i];
window.regions[r.regionid] = r;
}
Papa.parse(baseUrl + "monthly_unique_zones.csv", {
download: true,
header: true,
dynamicTyping: true,
skipEmptyLines: true,
complete: function (csv) {
window.data = csv.data;
var pointLookup = {}
for (var d of window.data) {
var p = [d.Latitude, d.Longitude]
if (!pointLookup[p]) {
pointLookup[p] = [d];
} else {
d.Longitude += .001 * pointLookup[p].length;
pointLookup[p].push(d);
for (var zone of pointLookup[p]) {
zone.colocated = true;
}
}
}
createPointsLayer();
map.spin(false);
}
});
}
});
}
});
var legend = L.control({ position: 'bottomright' });
function statsToggle() {
$("#stats").toggle();
}
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
div.innerHTML += `Shows zones with activity <select id="filtertime">
<option>since 2021-01-01</option>
<option value="month">in the past month</option>
<option value="week">in the past week</option>
<option value="day" selected>in the past day</option>
</select><br>
<select id='filter'>
<option value=0>Show all zones</option>
<option value=5000>Show zones > 5K</option>
<option value=10000>Show zones > 10K</option>
<option value=100000>Show zones > 100K</option>
<option value=1000000>Show zones > 1M</option>
<option value=10000000>Show zones > 10M</option>
<option value=100000000>Show zones > 100M</option>
<option value=contested>Show contested zones</option>
<option value=colocated>Show colocated zones</option>
</select><br>
<a id='statsButton' class='link' onclick='statsToggle()'>Show/hide stats</a><div id='stats' style='display:none'></div>
<a href='https://github.com/neon-ninja/QONQR'>GitHub</a>`;
L.DomEvent.disableClickPropagation(div);
return div;
};
legend.addTo(map);
window.countfilter = 0;
window.timefilterName = "day";
window.timefilter = getTimeFromName(window.timefilterName);
var urlParams = new URLSearchParams(window.location.search);
if (urlParams.get("filter")) {
window.countfilter = urlParams.get("filter");
$("#filter").val(window.countfilter);
}
if (urlParams.get("timefilter")) {
window.timefilterName = urlParams.get("timefilter");
window.timefilter = getTimeFromName(window.timefilterName);
$("#filtertime").val(window.timefilterName);
}
if (urlParams.get("teamfilter")) {
layers = urlParams.get("teamfilter").split(",")
window.teamfilter = layers.map(e => Object.keys(overlays).indexOf(e));
for (var l of Object.keys(overlays)) {
if (layers.includes(l)) {
overlays[l].addTo(map);
} else {
overlays[l].removeFrom(map);
}
}
console.log(window.teamfilter)
}
function updateURL() {
urlParams.set("filter", window.countfilter);
urlParams.set("timefilter", window.timefilterName);
urlParams.set("teamfilter", layers);
var newRelativePathQuery = window.location.pathname + '?' + urlParams.toString();
history.pushState(null, '', newRelativePathQuery);
}
$("#filter").change(function () {
window.countfilter = this.value;
createPointsLayer();
updateURL();
})
function getTimeFromName(name) {
var date = new Date();
var timefilter = new Date(0);
if (name == "month") {
timefilter = Date.UTC(date.getUTCFullYear(), date.getUTCMonth() - 1, date.getUTCDate());
} else if (name == "week") {
timefilter = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() - 7);
} else if (name == "day") {
timefilter = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() - 1);
}
return timefilter;
}
$("#filtertime").change(function () {
window.timefilterName = this.value;
window.timefilter = getTimeFromName(window.timefilterName);
createPointsLayer();
updateURL();
})
</script>
</body>
</html>