This repository has been archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
s2check.user.js
3852 lines (3302 loc) · 113 KB
/
s2check.user.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
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name Pogo Tools
// @id s2check@alfonsoml
// @category Layer
// @namespace https://github.com/AlfonsoML-s/pogo-s2/
// @downloadURL https://gitlab.com/NvlblNm/pogo-s2/raw/master/s2check.user.js
// @updateURL https://gitlab.com/NvlblNm/pogo-s2/raw/master/s2check.user.js
// @homepageURL https://alfonsoml-s.github.io/pogo-s2/
// @version 0.102
// @description Pokemon Go tools over IITC.
// @author Alfonso M.
// @match https://intel.ingress.com/*
// @grant none
// ==/UserScript==
/* eslint-env es6 */
/* eslint no-var: "error" */
/* globals L, map */
/* globals GM_info, $, dialog */
/* globals renderPortalDetails, findPortalGuidByPositionE6, chat */
;(function () { // eslint-disable-line no-extra-semi
/** S2 Geometry functions
S2 extracted from Regions Plugin
https:static.iitc.me/build/release/plugins/regions.user.js
the regional scoreboard is based on a level 6 S2 Cell
- https:docs.google.com/presentation/d/1Hl4KapfAENAOf4gv-pSngKwvS_jwNVHRPZTTDzXXn6Q/view?pli=1#slide=id.i22
at the time of writing there's no actual API for the intel map to retrieve scoreboard data,
but it's still useful to plot the score cells on the intel map
the S2 geometry is based on projecting the earth sphere onto a cube, with some scaling of face coordinates to
keep things close to approximate equal area for adjacent cells
to convert a lat,lng into a cell id:
- convert lat,lng to x,y,z
- convert x,y,z into face,u,v
- u,v scaled to s,t with quadratic formula
- s,t converted to integer i,j offsets
- i,j converted to a position along a Hubbert space-filling curve
- combine face,position to get the cell id
NOTE: compared to the google S2 geometry library, we vary from their code in the following ways
- cell IDs: they combine face and the hilbert curve position into a single 64 bit number. this gives efficient space
and speed. javascript doesn't have appropriate data types, and speed is not cricical, so we use
as [face,[bitpair,bitpair,...]] instead
- i,j: they always use 30 bits, adjusting as needed. we use 0 to (1<<level)-1 instead
(so GetSizeIJ for a cell is always 1)
*/
function wrapper(plugin_info) {
'use strict';
const d2r = Math.PI / 180.0;
const r2d = 180.0 / Math.PI;
const S2 = {};
function LatLngToXYZ(latLng) {
const phi = latLng.lat * d2r;
const theta = latLng.lng * d2r;
const cosphi = Math.cos(phi);
return [Math.cos(theta) * cosphi, Math.sin(theta) * cosphi, Math.sin(phi)];
}
function XYZToLatLng(xyz) {
const lat = Math.atan2(xyz[2], Math.sqrt(xyz[0] * xyz[0] + xyz[1] * xyz[1]));
const lng = Math.atan2(xyz[1], xyz[0]);
return {lat: lat * r2d, lng: lng * r2d};
}
function largestAbsComponent(xyz) {
const temp = [Math.abs(xyz[0]), Math.abs(xyz[1]), Math.abs(xyz[2])];
if (temp[0] > temp[1]) {
if (temp[0] > temp[2]) {
return 0;
}
return 2;
}
if (temp[1] > temp[2]) {
return 1;
}
return 2;
}
function faceXYZToUV(face,xyz) {
let u, v;
switch (face) {
case 0: u = xyz[1] / xyz[0]; v = xyz[2] / xyz[0]; break;
case 1: u = -xyz[0] / xyz[1]; v = xyz[2] / xyz[1]; break;
case 2: u = -xyz[0] / xyz[2]; v = -xyz[1] / xyz[2]; break;
case 3: u = xyz[2] / xyz[0]; v = xyz[1] / xyz[0]; break;
case 4: u = xyz[2] / xyz[1]; v = -xyz[0] / xyz[1]; break;
case 5: u = -xyz[1] / xyz[2]; v = -xyz[0] / xyz[2]; break;
default: throw {error: 'Invalid face'};
}
return [u,v];
}
function XYZToFaceUV(xyz) {
let face = largestAbsComponent(xyz);
if (xyz[face] < 0) {
face += 3;
}
const uv = faceXYZToUV(face, xyz);
return [face, uv];
}
function FaceUVToXYZ(face, uv) {
const u = uv[0];
const v = uv[1];
switch (face) {
case 0: return [1, u, v];
case 1: return [-u, 1, v];
case 2: return [-u,-v, 1];
case 3: return [-1,-v,-u];
case 4: return [v,-1,-u];
case 5: return [v, u,-1];
default: throw {error: 'Invalid face'};
}
}
function STToUV(st) {
const singleSTtoUV = function (st) {
if (st >= 0.5) {
return (1 / 3.0) * (4 * st * st - 1);
}
return (1 / 3.0) * (1 - (4 * (1 - st) * (1 - st)));
};
return [singleSTtoUV(st[0]), singleSTtoUV(st[1])];
}
function UVToST(uv) {
const singleUVtoST = function (uv) {
if (uv >= 0) {
return 0.5 * Math.sqrt (1 + 3 * uv);
}
return 1 - 0.5 * Math.sqrt (1 - 3 * uv);
};
return [singleUVtoST(uv[0]), singleUVtoST(uv[1])];
}
function STToIJ(st,order) {
const maxSize = 1 << order;
const singleSTtoIJ = function (st) {
const ij = Math.floor(st * maxSize);
return Math.max(0, Math.min(maxSize - 1, ij));
};
return [singleSTtoIJ(st[0]), singleSTtoIJ(st[1])];
}
function IJToST(ij,order,offsets) {
const maxSize = 1 << order;
return [
(ij[0] + offsets[0]) / maxSize,
(ij[1] + offsets[1]) / maxSize
];
}
// S2Cell class
S2.S2Cell = function () {};
//static method to construct
S2.S2Cell.FromLatLng = function (latLng, level) {
const xyz = LatLngToXYZ(latLng);
const faceuv = XYZToFaceUV(xyz);
const st = UVToST(faceuv[1]);
const ij = STToIJ(st,level);
return S2.S2Cell.FromFaceIJ(faceuv[0], ij, level);
};
S2.S2Cell.FromFaceIJ = function (face, ij, level) {
const cell = new S2.S2Cell();
cell.face = face;
cell.ij = ij;
cell.level = level;
return cell;
};
S2.S2Cell.prototype.toString = function () {
return 'F' + this.face + 'ij[' + this.ij[0] + ',' + this.ij[1] + ']@' + this.level;
};
S2.S2Cell.prototype.getLatLng = function () {
const st = IJToST(this.ij, this.level, [0.5, 0.5]);
const uv = STToUV(st);
const xyz = FaceUVToXYZ(this.face, uv);
return XYZToLatLng(xyz);
};
S2.S2Cell.prototype.getCornerLatLngs = function () {
const offsets = [
[0.0, 0.0],
[0.0, 1.0],
[1.0, 1.0],
[1.0, 0.0]
];
return offsets.map(offset => {
const st = IJToST(this.ij, this.level, offset);
const uv = STToUV(st);
const xyz = FaceUVToXYZ(this.face, uv);
return XYZToLatLng(xyz);
});
};
S2.S2Cell.prototype.getNeighbors = function (deltas) {
const fromFaceIJWrap = function (face,ij,level) {
const maxSize = 1 << level;
if (ij[0] >= 0 && ij[1] >= 0 && ij[0] < maxSize && ij[1] < maxSize) {
// no wrapping out of bounds
return S2.S2Cell.FromFaceIJ(face,ij,level);
}
// the new i,j are out of range.
// with the assumption that they're only a little past the borders we can just take the points as
// just beyond the cube face, project to XYZ, then re-create FaceUV from the XYZ vector
let st = IJToST(ij,level,[0.5, 0.5]);
let uv = STToUV(st);
let xyz = FaceUVToXYZ(face, uv);
const faceuv = XYZToFaceUV(xyz);
face = faceuv[0];
uv = faceuv[1];
st = UVToST(uv);
ij = STToIJ(st,level);
return S2.S2Cell.FromFaceIJ(face, ij, level);
};
const face = this.face;
const i = this.ij[0];
const j = this.ij[1];
const level = this.level;
if (!deltas) {
deltas = [
{a: -1, b: 0},
{a: 0, b: -1},
{a: 1, b: 0},
{a: 0, b: 1}
];
}
return deltas.map(function (values) {
return fromFaceIJWrap(face, [i + values.a, j + values.b], level);
});
};
/** Our code
* For safety, S2 must be initialized before our code
*/
// based on https://github.com/iatkin/leaflet-svgicon
function initSvgIcon() {
L.DivIcon.SVGIcon = L.DivIcon.extend({
options: {
'className': 'svg-icon',
'iconAnchor': null, //defaults to [iconSize.x/2, iconSize.y] (point tip)
'iconSize': L.point(48, 48)
},
initialize: function (options) {
options = L.Util.setOptions(this, options);
//iconSize needs to be converted to a Point object if it is not passed as one
options.iconSize = L.point(options.iconSize);
if (!options.iconAnchor) {
options.iconAnchor = L.point(Number(options.iconSize.x) / 2, Number(options.iconSize.y));
} else {
options.iconAnchor = L.point(options.iconAnchor);
}
},
// https://github.com/tonekk/Leaflet-Extended-Div-Icon/blob/master/extended.divicon.js#L13
createIcon: function (oldIcon) {
let div = L.DivIcon.prototype.createIcon.call(this, oldIcon);
if (this.options.id) {
div.id = this.options.id;
}
if (this.options.style) {
for (let key in this.options.style) {
div.style[key] = this.options.style[key];
}
}
return div;
}
});
L.divIcon.svgIcon = function (options) {
return new L.DivIcon.SVGIcon(options);
};
L.Marker.SVGMarker = L.Marker.extend({
options: {
'iconFactory': L.divIcon.svgIcon,
'iconOptions': {}
},
initialize: function (latlng, options) {
options = L.Util.setOptions(this, options);
options.icon = options.iconFactory(options.iconOptions);
this._latlng = latlng;
},
onAdd: function (map) {
L.Marker.prototype.onAdd.call(this, map);
}
});
L.marker.svgMarker = function (latlng, options) {
return new L.Marker.SVGMarker(latlng, options);
};
}
/**
* Saves a file to disk with the provided text
* @param {string} text - The text to save
* @param {string} filename - Proposed filename
*/
function saveToFile(text, filename) {
if (typeof text != 'string') {
text = JSON.stringify(text);
}
if (typeof window.saveFile != 'undefined') {
window.saveFile(text, filename, 'application/json');
return;
}
alert('You are using an old version of IITC.\r\nIn the future this plugin will no longer be compatible with it.\r\nPlease, upgrade ASAP to IITC-CE https://iitc.modos189.ru/');
if (typeof window.android !== 'undefined' && window.android.saveFile) {
window.android.saveFile(filename, 'application/json', text);
return;
}
if (isIITCm()) {
promptForCopy(text);
return;
}
const element = document.createElement('a');
// http://stackoverflow.com/questions/13405129/javascript-create-and-save-file
const file = new Blob([text], {type: 'text/plain'});
const objectURL = URL.createObjectURL(file);
element.setAttribute('href', objectURL);
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
setTimeout(function () {
document.body.removeChild(element);
URL.revokeObjectURL(objectURL);
}, 0);
}
/**
* Prompts the user to select a file and then reads its contents and calls the callback function with those contents
* @param {Function} callback - Function that will be called when the file is read.
* Callback signature: function( {string} contents ) {}
*/
function readFromFile(callback) {
if (typeof L.FileListLoader != 'undefined') {
L.FileListLoader.loadFiles({accept: 'application/json'})
.on('load',function (e) {
callback(e.reader.result);
});
return;
}
alert('You are using an old version of IITC.\r\nIn the future this plugin will no longer be compatible with it.\r\nPlease, upgrade ASAP to IITC-CE https://iitc.modos189.ru/');
// special hook from iitcm
if (typeof window.requestFile != 'undefined') {
window.requestFile(function (filename, content) {
callback(content);
});
return;
}
if (isIITCm()) {
promptForPaste(callback);
return;
}
const input = document.createElement('input');
input.type = 'file';
document.body.appendChild(input);
input.addEventListener('change', function () {
const reader = new FileReader();
reader.onload = function () {
callback(reader.result);
};
reader.readAsText(input.files[0]);
document.body.removeChild(input);
}, false);
input.click();
}
function promptForPaste(callback) {
const div = document.createElement('div');
const textarea = document.createElement('textarea');
textarea.style.width = '100%';
textarea.style.minHeight = '8em';
div.appendChild(textarea);
const width = Math.min(screen.availWidth, 360);
const container = dialog({
id: 'promptForPaste',
html: div,
width: width + 'px',
title: 'Paste here the data',
buttons: {
OK: function () {
container.dialog('close');
callback(textarea.value);
}
}
});
}
function promptForCopy(text) {
const div = document.createElement('div');
const textarea = document.createElement('textarea');
textarea.style.width = '100%';
textarea.style.minHeight = '8em';
textarea.value = text;
div.appendChild(textarea);
const width = Math.min(screen.availWidth, 360);
const container = dialog({
id: 'promptForCopy',
html: div,
width: width + 'px',
title: 'Copy this data',
buttons: {
OK: function () {
container.dialog('close');
}
}
});
}
const TIMERS = {};
function createThrottledTimer(name, callback, ms) {
if (TIMERS[name])
clearTimeout(TIMERS[name]);
// throttle if there are several calls to the functions
TIMERS[name] = setTimeout(function () {
delete TIMERS[name];
if (typeof window.requestIdleCallback == 'undefined')
callback();
else
// and even now, wait for iddle
requestIdleCallback(function () {
callback();
}, {timeout: 2000});
}, ms || 100);
}
/**
* Try to identify if the browser is IITCm due to special bugs like file picker not working
*/
function isIITCm() {
const ua = navigator.userAgent;
if (!ua.match(/Android.*Mobile/))
return false;
if (ua.match(/; wb\)/))
return true;
return ua.match(/ Version\//);
}
function is_iOS() {
const ua = navigator.userAgent;
return ua.includes('iPhone') || ua.includes('iPad');
}
let pokestops = {};
let gyms = {};
// Portals that aren't marked as PoGo items
let notpogo = {};
let allPortals = {};
let newPortals = {};
let checkNewPortalsTimer;
let relayoutTimer; // timer for relayout when portal is added
// Portals that the user hasn't classified as Pokestops (2 or more in the same Lvl17 cell)
let skippedPortals = {};
let newPokestops = {};
let notClassifiedPokestops = [];
// Portals that we know, but that have been moved from our stored location.
let movedPortals = [];
// Pogo items that are no longer available.
let missingPortals = {};
// Cells currently detected with extra gyms
let cellsExtraGyms = {};
// Cells that the user has marked to ignore extra gyms
let ignoredCellsExtraGyms = {};
// Cells with missing Gyms
let ignoredCellsMissingGyms = {};
// Leaflet layers
let regionLayer; // parent layer
let stopLayerGroup; // pokestops
let gymLayerGroup; // gyms
let nearbyLayerGroup; // circles to mark the too near limit
let gridLayerGroup; // s2 grid
let cellLayerGroup; // cell shading and borders
let gymCenterLayerGroup; // gym centers
let countLayer; // layer with count of portals in each cell
// Group of items added to the layer
let stopLayers = {};
let gymLayers = {};
let nearbyCircles = {};
// grouping of the portals in the second level of the grid
let cellsPortals = {};
const highlighterTitle = 'PoGo Tools';
const gymCellLevel = 14; // the cell level which is considered when counting POIs to determine # of gyms
const poiCellLevel = 17; // the cell level where there can only be 1 POI translated to pogo
const defaultSettings = {
highlightGymCandidateCells: true,
highlightGymCenter: false,
thisIsPogo: false,
analyzeForMissingData: true,
centerMapOnClick: true,
grids: [
{
level: gymCellLevel,
width: 5,
color: '#004D40',
opacity: 0.5
},
{
level: poiCellLevel,
width: 2,
color: '#388E3C',
opacity: 0.5
}
],
colors: {
cellsExtraGyms: {
color: '#ff0000',
opacity: 0.5
},
cellsMissingGyms: {
color: '#ffa500',
opacity: 0.5
},
cell17Filled: {
color: '#000000',
opacity: 0.6
},
cell14Filled: {
color: '#000000',
opacity: 0.5
},
nearbyCircleBorder: {
color: '#000000',
opacity: 0.6
},
nearbyCircleFill: {
color: '#000000',
opacity: 0.4
},
missingStops1: {
color: '#BF360C',
opacity: 1
},
missingStops2: {
color: '#E64A19',
opacity: 1
},
missingStops3: {
color: '#FF5722',
opacity: 1
}
},
saveDataType: 'Gyms',
saveDataFormat: 'CSV'
};
let settings = defaultSettings;
function saveSettings() {
createThrottledTimer('saveSettings', function () {
localStorage[KEY_SETTINGS] = JSON.stringify(settings);
});
}
function loadSettings() {
const tmp = localStorage[KEY_SETTINGS];
if (!tmp) {
loadOldSettings();
return;
}
try {
settings = JSON.parse(tmp);
} catch (e) { // eslint-disable-line no-empty
}
setThisIsPogo();
}
/**
* Migrate from old key to new one in order to avoid conflict with other plugin that reused this code.
*/
function loadOldSettings() {
const tmp = localStorage['s2check_settings'];
if (!tmp)
return;
try {
settings = JSON.parse(tmp);
} catch (e) { // eslint-disable-line no-empty
}
if (typeof settings.analyzeForMissingData == 'undefined') {
settings.analyzeForMissingData = true;
}
if (typeof settings.promptForMissingData != 'undefined') {
delete settings.promptForMissingData;
}
if (!settings.colors) {
resetColors();
}
if (typeof settings.saveDataType == 'undefined') {
settings.saveDataType = 'Gyms';
}
if (typeof settings.saveDataFormat == 'undefined') {
settings.saveDataFormat = 'CSV';
}
if (typeof settings.centerMapOnClick == 'undefined') {
settings.centerMapOnClick = true;
}
setThisIsPogo();
// migrate key
localStorage.removeItem('s2check_settings');
saveStorage();
}
function resetColors() {
settings.grids[0].color = defaultSettings.grids[0].color;
settings.grids[0].opacity = defaultSettings.grids[0].opacity;
settings.grids[1].color = defaultSettings.grids[1].color;
settings.grids[1].opacity = defaultSettings.grids[1].opacity;
settings.colors = defaultSettings.colors;
}
let originalHighlightPortal;
let originalChatRequestPublic;
let originalChatRequestFaction;
let originalChatRequestAlerts;
let originalRANGE_INDICATOR_COLOR;
let originalHACK_RANGE;
function markPortalsAsNeutral(data) {
const hidePortalOwnershipStyles = window.getMarkerStyleOptions({team: window.TEAM_NONE, level: 0});
data.portal.setStyle(hidePortalOwnershipStyles);
}
function setThisIsPogo() {
document.body.classList[settings.thisIsPogo ? 'add' : 'remove']('thisIsPogo');
// It seems that iOS has some bug in the following code, but I can't debug it.
if (is_iOS())
return;
try {
if (settings.thisIsPogo) {
removeIngressLayers();
if (chat && chat.requestPublic) {
originalChatRequestPublic = chat && chat.requestPublic;
chat.requestPublic = function () {}; // no requests for chat
}
if (chat && chat.requestFaction) {
originalChatRequestFaction = chat && chat.requestFaction;
chat.requestFaction = function () {}; // no requests for chat
}
if (chat && chat.requestAlerts) {
originalChatRequestAlerts = chat && chat.requestAlerts;
chat.requestAlerts = function () {}; // no requests for chat
}
// Hide the link range indicator around the selected portal
originalRANGE_INDICATOR_COLOR = window.RANGE_INDICATOR_COLOR;
window.RANGE_INDICATOR_COLOR = 'transparent';
// Use 80 m. interaction radius
originalHACK_RANGE = window.HACK_RANGE;
window.HACK_RANGE = 80;
if (window._current_highlighter == window._no_highlighter) {
window.changePortalHighlights(highlighterTitle);
}
} else {
restoreIngressLayers();
if (originalChatRequestPublic) {
chat.requestPublic = originalChatRequestPublic;
originalChatRequestPublic = null;
}
if (originalChatRequestFaction) {
chat.requestFaction = originalChatRequestFaction;
originalChatRequestFaction = null;
}
if (originalChatRequestAlerts) {
chat.requestAlerts = originalChatRequestAlerts;
originalChatRequestAlerts = null;
}
if (originalRANGE_INDICATOR_COLOR != null)
window.RANGE_INDICATOR_COLOR = originalRANGE_INDICATOR_COLOR;
if (originalHACK_RANGE != null)
window.HACK_RANGE = originalHACK_RANGE;
if (window._current_highlighter == highlighterTitle) {
window.changePortalHighlights(window._no_highlighter);
}
if (originalHighlightPortal != null) {
window.highlightPortal = originalHighlightPortal;
originalHighlightPortal = null;
window.resetHighlightedPortals();
}
}
} catch (e) {
alert('Error initializing ThisIsPogo');
console.log(e); // eslint-disable-line no-console
}
}
function sortByName(a, b) {
if (!a.name)
return -1;
return a.name.localeCompare(b.name);
}
function isCellOnScreen(mapBounds, cell) {
const corners = cell.getCornerLatLngs();
const cellBounds = L.latLngBounds([corners[0],corners[1]]).extend(corners[2]).extend(corners[3]);
return cellBounds.intersects(mapBounds);
}
// return only the cells that are visible by the map bounds to ignore far away data that might not be complete
function filterWithinScreen(cells) {
const bounds = map.getBounds();
const filtered = {};
Object.keys(cells).forEach(cellId => {
const cellData = cells[cellId];
const cell = cellData.cell;
if (isCellInsideScreen(bounds, cell)) {
filtered[cellId] = cellData;
}
});
return filtered;
}
function isCellInsideScreen(mapBounds, cell) {
const corners = cell.getCornerLatLngs();
const cellBounds = L.latLngBounds([corners[0],corners[1]]).extend(corners[2]).extend(corners[3]);
return mapBounds.contains(cellBounds);
}
/**
* Filter a group of items (gyms/stops) excluding those out of the screen
*/
function filterItemsByMapBounds(items) {
const bounds = map.getBounds();
const filtered = {};
Object.keys(items).forEach(id => {
const item = items[id];
if (isPointOnScreen(bounds, item)) {
filtered[id] = item;
}
});
return filtered;
}
function isPointOnScreen(mapBounds, point) {
if (point._latlng)
return mapBounds.contains(point._latlng);
return mapBounds.contains(L.latLng(point));
}
function groupByCell(level) {
const cells = {};
classifyGroup(cells, gyms, level, (cell, item) => cell.gyms.push(item));
classifyGroup(cells, pokestops, level, (cell, item) => cell.stops.push(item));
classifyGroup(cells, newPortals, level, (cell, item) => cell.notClassified.push(item));
classifyGroup(cells, notpogo, level, (cell, item) => {/* */});
return cells;
}
function classifyGroup(cells, items, level, callback) {
Object.keys(items).forEach(id => {
const item = items[id];
if (!item.cells) {
item.cells = {};
}
let cell;
// Compute the cell only once for each level
if (!item.cells[level]) {
cell = S2.S2Cell.FromLatLng(item, level);
item.cells[level] = cell.toString();
}
const cellId = item.cells[level];
// Add it to the array of gyms of that cell
if (!cells[cellId]) {
if (!cell) {
cell = S2.S2Cell.FromLatLng(item, level);
}
cells[cellId] = {
cell: cell,
gyms: [],
stops: [],
notClassified: [],
portals: {}
};
}
callback(cells[cellId], item);
});
}
/**
* Returns the items that belong to the specified cell
*/
function findCellItems(cellId, level, items) {
return Object.values(items).filter(item => item.cells[level] == cellId);
}
/**
Tries to add the portal photo when exporting from Ingress.com/intel
*/
function findPhotos(items) {
if (!window.portals) {
return items;
}
Object.keys(items).forEach(id => {
const item = items[id];
if (item.image)
return;
const portal = window.portals[id];
if (portal && portal.options && portal.options.data) {
item.image = portal.options.data.image;
}
});
return items;
}
function configureGridLevelSelect(select, i) {
select.value = settings.grids[i].level;
select.addEventListener('change', e => {
settings.grids[i].level = parseInt(select.value, 10);
if (i == 1)
resetGrouping();
saveSettings();
updateMapGrid();
});
}
function resetGrouping() {
cellsPortals = {};
const level = settings.grids[1].level;
if (level < 4)
return;
classifyGroup(cellsPortals, allPortals, level, (cell, item) => cell.portals[item.guid] = true);
}
function groupPortal(item) {
const level = settings.grids[1].level;
if (level < 4)
return;
let cells = cellsPortals;
let cell;
// Compute the cell only once for each level
if (!item.cells[level]) {
cell = S2.S2Cell.FromLatLng(item, level);
item.cells[level] = cell.toString();
}
const cellId = item.cells[level];
// Add it to the array of gyms of that cell
if (!cells[cellId]) {
if (!cell) {
cell = S2.S2Cell.FromLatLng(item, level);
}
cells[cellId] = {
cell: cell,
portals: {}
};
}
cells[cellId].portals[item.guid] = true;
}
function showS2Dialog() {
const selectRow = `
<p>{{level}} level of grid to display: <select>
<option value=0>None</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
<option value=9>9</option>
<option value=10>10</option>
<option value=11>11</option>
<option value=12>12</option>
<option value=13>13</option>
<option value=14>14</option>
<option value=15>15</option>
<option value=16>16</option>
<option value=17>17</option>
<option value=18>18</option>
<option value=19>19</option>
<option value=20>20</option>
</select></p>`;
const html =
selectRow.replace('{{level}}', '1st') +
selectRow.replace('{{level}}', '2nd') +
`<p><input type="checkbox" id="chkHighlightCandidates" /><label for="chkHighlightCandidates">Highlight Cells that might get a Gym</label></p>
<p><input type="checkbox" id="chkHighlightCenters" /><label for="chkHighlightCenters">Put an X in the center of Cells with a Gym<br />(for determining EX-eligibility)</label></p>
<p><input type="checkbox" id="chkThisIsPogo" /><label for="chkThisIsPogo" title='Hide Ingress panes, info and whatever that clutters the map and it is useless for Pokemon Go'>This is PoGo!</label></p>
<p><input type="checkbox" id="chkanalyzeForMissingData" /><label for="chkanalyzeForMissingData" title="Analyze the portal data to show the pane that suggests new Pokestops and Gyms">Analyze portal data</label></p>
<p><input type="checkbox" id="chkcenterMapOnClick" /><label for="chkcenterMapOnClick" title="Center map on portal when clicked in a dialog box.">Center map on click.</label></p>
<p><a id='PogoEditColors'>Colors</a></p>
`;
const container = dialog({
id: 's2Settings',
width: 'auto',
html: html,
title: 'S2 & Pokemon Settings'
});
const div = container[0];
const selects = div.querySelectorAll('select');
for (let i = 0; i < 2; i++) {
configureGridLevelSelect(selects[i], i);
}
const chkHighlight = div.querySelector('#chkHighlightCandidates');