-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathWME-LaneTools.user.js
3512 lines (3205 loc) · 148 KB
/
WME-LaneTools.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 WME LaneTools
// @namespace https://github.com/SkiDooGuy/WME-LaneTools
// @version 2025.01.21.02
// @description Adds highlights and tools to WME to supplement the lanes feature
// @author SkiDooGuy, Click Saver by HBiede, Heuristics by kndcajun, assistance by jm6087
// @updateURL https://github.com/SkiDooGuy/WME-LaneTools/raw/master/WME-LaneTools.user.js
// @downloadURL https://github.com/SkiDooGuy/WME-LaneTools/raw/master/WME-LaneTools.user.js
// @match https://www.waze.com/editor*
// @match https://www.waze.com/*/editor*
// @match https://beta.waze.com/editor*
// @match https://beta.waze.com/*/editor*
// @exclude https://www.waze.com/user/editor*
// @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
// @grant GM_xmlhttpRequest
// @connect raw.githubusercontent.com
// @contributionURL https://github.com/WazeDev/Thank-The-Authors
// ==/UserScript==
/* global W */
/* global WazeWrap */
/* global $ */
/* global OpenLayers */
/* global _ */
/* global require */
let sdkVersion = "";
unsafeWindow.SDK_INITIALIZED.then(() => {
let sdk = unsafeWindow.getWmeSdk({
scriptId: "wme-lane-tools",
scriptName: "WME LaneTools",
});
sdkVersion = sdk.getSDKVersion()
});
const LANETOOLS_VERSION = `${GM_info.script.version}`;
const GF_LINK = 'https://github.com/SkiDooGuy/WME-LaneTools/blob/master/WME-LaneTools.user.js';
const DOWNLOAD_URL = 'https://raw.githubusercontent.com/SkiDooGuy/WME-LaneTools/master/WME-LaneTools.user.js';
const FORUM_LINK = 'https://www.waze.com/discuss/t/script-wme-lanetools/53136';
const LI_UPDATE_NOTES = `FIXED: Better error/red highlight check in JB.<br>FIXED: Forum Link<br>
KNOWN ISSUE: Some tab UI enhancements may not work as expected.`;
const LANETOOLS_DEBUG_LEVEL = 1;
const configArray = {};
const RBSArray = { failed: false };
const IsBeta = location.href.indexOf("beta.waze.com") !== -1;
const env = IsBeta ? "beta" : "production";
const TRANSLATIONS = {
// Default english values
default: {
enabled: 'Enabled',
disabled: 'Disabled',
toggleShortcut: 'Toggle Shortcut',
UIEnhance: 'Tab UI Enhancements',
autoWidth: 'Auto-open road width',
autoOpen: 'Auto-open lanes tab',
autoExpand: 'Auto-expand lane editor',
autoFocus: 'Auto-focus lane input',
reOrient: 'Re-orient lane icons',
enClick: 'Enable ClickSaver',
clickStraight: 'All straight lanes',
clickTurn: 'Turn lanes',
mapHighlight: 'Map Highlights',
laneLabel: 'Lane labels',
nodeHigh: 'Node highlights',
LAOHigh: 'Lane angle overrides',
CSOHigh: 'Continue straight overrides',
heuristics: 'Lane heuristics candidates',
posHeur: 'Positive heuristics candidate',
negHeur: 'Negative heuristics candidate',
highColor: 'Highlight Colors',
colTooltip: 'Click to toggle color inputs',
selAllTooltip: 'Click on turn name to toggle all lane associations',
fwdCol: 'Fwd (A>B)',
revCol: 'Rev (B>A)',
labelCol: 'Labels',
errorCol: 'Lane errors',
laneNodeCol: 'Nodes with lanes',
nodeTIOCol: 'Nodes with TIOs',
LAOCol: 'Segs with TIOs',
viewCSCol: 'View only CS',
hearCSCol: 'View and hear CS',
heurPosCol: 'Lane heuristics likely',
heurNegCol: 'Lane heuristics - not qualified',
advTools: 'Advanced Tools',
quickTog: 'Quick toggle all lanes',
showRBS: 'Use RBS heuristics',
delFwd: 'Delete FWD Lanes',
delRev: 'Delete Rev Lanes',
delOpp: 'This segment is one-way but has lanes set in the opposite direction. Click here to delete them',
csIcons: 'Highlight CS Icons',
highlightOverride: 'Only highlight if segment layer active',
addTIO: 'Include TIO in lanes tab',
labelTIO: 'TIO',
defaultTIO: 'Waze Selected',
noneTIO: 'None',
tlTIO: 'Turn Left',
trTIO: 'Turn Right',
klTIO: 'Keep Left',
krTIO: 'Keep Right',
conTIO: 'Continue',
elTIO: 'Exit Left',
erTIO: 'Exit Right',
uturnTIO: 'U-Turn',
enIcons: 'Display lane icons on map',
IconsRotate: 'Rotate map icons with segment direction'
}
};
const Direction = {
REVERSE: -1,
ANY: 0,
FORWARD: 1
};
const LT_ROAD_TYPE = {
// Streets
NARROW_STREET: 22,
STREET: 1,
PRIMARY_STREET: 2,
// Highways
RAMP: 4,
FREEWAY: 3,
MAJOR_HIGHWAY: 6,
MINOR_HIGHWAY: 7,
// Other drivable
DIRT_ROAD: 8,
FERRY: 14,
PRIVATE_ROAD: 17,
PARKING_LOT_ROAD: 20,
// Non-drivable
WALKING_TRAIL: 5,
PEDESTRIAN_BOARDWALK: 10,
STAIRWAY: 16,
RAILROAD: 18,
RUNWAY: 19
};
const DisplayLevels = {
MIN_ZOOM_ALL: 14,
MIN_ZOOM_NONFREEWAY: 17
};
const HeuristicsCandidate = {
ERROR: -2,
FAIL: -1,
NONE: 0,
PASS: 1
};
let MAX_LEN_HEUR; // Maximum length of segment where lane heuristics applied (Specified in Wiki).
let MAX_PERP_DIF; // Updated 2020-09, based on experiments
let MAX_PERP_DIF_ALT; // New 2020-09, based on experiments
let MAX_PERP_TO_CONSIDER; // Don't even consider perp angles outside of this tolerance
let MAX_STRAIGHT_TO_CONSIDER; // Don't even consider straight angles inside of this tolerance
let MAX_STRAIGHT_DIF; // IN TESTING; updated 2020-09
let lt_scanArea_recursive = 0;
let LtSettings = {};
let strings = {};
let _turnInfo = [];
let _turnData = {};
let laneCount;
let LTHighlightLayer;
let LTNamesLayer;
let LTLaneGraphics;
let _pickleColor;
let seaPickle;
let UpdateObj;
let MultiAction;
let SetTurn;
let shortcutsDisabled = false;
let isRBS = false;
let allowCpyPst = false;
let langLocality = 'default';
console.log('LaneTools: initializing...');
function laneToolsBootstrap(tries = 0) {
if (W && W.map && W.model && W.loginManager.user && $ && WazeWrap.Ready) {
initLaneTools();
} else if (tries < 500) {
setTimeout(() => {
laneToolsBootstrap(tries + 1);
}, 200);
} else {
console.error('LaneTools: Failed to load');
}
}
function initLaneTools() {
startScriptUpdateMonitor();
seaPickle = W.loginManager.user;
UpdateObj = require('Waze/Action/UpdateObject');
MultiAction = require('Waze/Action/MultiAction');
SetTurn = require('Waze/Model/Graph/Actions/SetTurn');
const ltCss = [
'.lt-wrapper {position:relative;width:100%;font-size:12px;font-family:"Rubik", "Boing-light", sans-serif;user-select:none;}',
'.lt-section-wrapper {display:block;width:100%;padding:4px;}',
'.lt-section-wrapper.border {border-bottom:1px solid grey;margin-bottom:5px;}',
'.lt-option-container {padding:3px;}',
'.lt-option-container.color {text-decoration:none;}',
'input[type="checkbox"].lt-checkbox {position:relative;top:3px;vertical-align:top;margin:0;}',
'input[type="text"].lt-color-input {position:relative;width:70px;padding:3px;border:2px solid black;border-radius:6px;}',
'input[type="text"].lt-color-input:focus {outline-width:0;}',
'label.lt-label {position:relative;max-width:90%;font-weight:normal;padding-left:5px}',
'.lt-Toolbar-Container {display:none;position:absolute;background-color:orange;border-radius:6px;border:1.5px solid;box-size:border-box;z-index:1050;}',
'.lt-Toolbar-Wrapper {position:relative;padding:3px;}',
'.lt-toolbar-button-container {display:inline-block;padding:5px;}',
'.lt-toolbar-button {position:relative;display:block;width:60px;height:25px;border-radius:6px;font-size:12px;}',
'.lt-add-Width {display:inline-block;width:15px;height:15px;border:1px solid black;border-radius:8px;margin:0 3px 0 3px;line-height: 1.5;text-align:center;font-size:10px;}',
'.lt-add-Width:hover {border:1px solid #26bae8;background-color:#26bae8;cursor:pointer;}',
'.lt-add-lanes {display:inline-block;width:15px;height:15px;border:1px solid black;border-radius:8px;margin:0 3px 0 3px;line-height: 1.5;text-align:center;font-size:10px;}',
'.lt-add-lanes:hover {border:1px solid #26bae8;background-color:#26bae8;cursor:pointer;}',
'.lt-chkAll-lns {display:inline-block;width:20px;height:20px;text-decoration:underline;font-weight:bold;font-size:10px;padding-left:3px;cursor:pointer;}',
'.lt-tio-select {max-width:80%;color:rgb(32, 33, 36);background-color:rgb(242, 243, 244);border:0px;border-radius:6px;padding:0 16px 0 10px;cursor:pointer;}',
'#lt-color-title {display:block;width:100%;padding:5px 0 5px 0;font-weight:bold;text-decoration:underline;cursor:pointer;}'
].join(' ');
const $ltTab = $('<div>');
$ltTab.html = ([
`<div class='lt-wrapper' id='lt-tab-wrapper'>
<div class='lt-section-wrapper' id='lt-tab-body'>
<div class='lt-section-wrapper border' style='border-bottom:2px double grey;'>
<a href=${FORUM_LINK} style='font-weight:bold;font-size:12px;text-decoration:underline;' target='_blank'>LaneTools - v${LANETOOLS_VERSION}</a>
<div>
<div style='display:inline-block;'><span class='lt-trans-tglshcut'></span>:<span id='lt-EnableShortcut' style='padding-left:10px;'></span></div>
<div class='lt-option-container' style='float:right;'>
<input type=checkbox class='lt-checkbox' id='lt-ScriptEnabled' />
<label class='lt-label' for='lt-ScriptEnabled'><span class='lt-trans-enabled'></span></label>
</div>
</div>
</div>
<div class='lt-section-wrapper' id='lt-LaneTabFeatures'>
<div class='lt-section-wrapper border'>
<span style='font-weight:bold;'><span id='lt-trans-uiEnhance'></span></span>
<div class='lt-option-container' style='float:right;'>
<input type=checkbox class='lt-checkbox' id='lt-UIEnable' />
<label class='lt-label' for='lt-UIEnable'><span class='lt-trans-enabled'></span></label>
</div>
</div>
<div id='lt-UI-wrapper'>
<div class='lt-option-container' style='margin-bottom:5px;'>
<div style='display:inline-block;'><span class='lt-trans-tglshcut'></span>:<span id='lt-UIEnhanceShortcut' style='padding-left:10px;'></span></div>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-AutoOpenWidth' />
<label class='lt-label' for='lt-AutoOpenWidth'><span id='lt-trans-autoWidth'></span></label>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-AutoLanesTab' />
<label class='lt-label' for='lt-AutoLanesTab'><span id='lt-trans-autoTab'></span></label>
</div>
<div class='lt-option-container' style='display:none;'>
<input type=checkbox class='lt-checkbox' id='lt-AutoExpandLanes' />
<label class='lt-label' for='lt-AutoExpandLanes'><span title="Feature disabled as of Aug 27, 2022 to prevent flickering issue" id='lt-trans-autoExpand'></span></label>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-AutoFocusLanes' />
<label class='lt-label' for='lt-AutoFocusLanes'><span id='lt-trans-autoFocus'></span></label>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-highlightCSIcons' />
<label class='lt-label' for='lt-highlightCSIcons'><span id='lt-trans-csIcons'></span></label>
</div>
<div class='lt-option-container' style='display:none;'>
<input type=checkbox class='lt-checkbox' id='lt-ReverseLanesIcon' />
<label class='lt-label' for='lt-ReverseLanesIcon'><span title="Feature disabled as of July 21, 2023 because lanes displayed wrong" id='lt-trans-orient'></span></label>
</div>
<div class='lt-option-container' style='display:none;'>
<input type=checkbox class='lt-checkbox' id='lt-AddTIO' />
<label class='lt-label' for='lt-AddTIO'><span id='lt-trans-AddTIO'></span></label>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-ClickSaveEnable' />
<label class='lt-label' for='lt-ClickSaveEnable'><span id='lt-trans-enClick'></span></label>
</div>
<div class='lt-option-container clk-svr' style='padding-left:10%;'>
<input type=checkbox class='lt-checkbox' id='lt-ClickSaveStraight' />
<label class='lt-label' for='lt-ClickSaveStraight'><span id='lt-trans-straClick'></span></label>
</div>
<div class='lt-option-container clk-svr' style='padding-left:10%;'>
<input type=checkbox class='lt-checkbox' id='lt-ClickSaveTurns' />
<label class='lt-label' for='lt-ClickSaveTurns'><span id='lt-trans-turnClick'></span></label>
</div>
</div>
</div>
<div class='lt-section-wrapper'>
<div class='lt-section-wrapper border'>
<span style='font-weight:bold;'><span id='lt-trans-mapHigh'></span></span>
<div class='lt-option-container' style='float:right;'>
<input type=checkbox class='lt-checkbox' id='lt-HighlightsEnable' />
<label class='lt-label' for='lt-HighlightsEnable'><span class='lt-trans-enabled'></span></label>
</div>
</div>
<div id='lt-highlights-wrapper'>
<div class='lt-option-container' style='margin-bottom:5px;'>
<div style='display:inline-block;'><span class='lt-trans-tglshcut'></span>:<span id='lt-HighlightShortcut' style='padding-left:10px;'></span></div>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-IconsEnable' />
<label class='lt-label' for='lt-IconsEnable'><span id='lt-trans-enIcons'></span></label>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-IconsRotate' />
<label class='lt-label' for='lt-IconsRotate'><span id='lt-trans-IconsRotate'></span></label>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-LabelsEnable' />
<label class='lt-label' for='lt-LabelsEnable'><span id='lt-trans-lnLabel'></span></label>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-NodesEnable' />
<label class='lt-label' for='lt-NodesEnable'><span id='lt-trans-nodeHigh'></span></label>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-LIOEnable' />
<label class='lt-label' for='lt-LIOEnable'><span id='lt-trans-laOver'></span></label>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-CSEnable' />
<label class='lt-label' for='lt-CSEnable'><span id='lt-trans-csOver'></span></label>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-highlightOverride' />
<label class='lt-label' for='lt-highlightOverride'><span id='lt-trans-highOver'></span></label>
</div>
</div>
</div>
<div class='lt-section-wrapper'>
<div class='lt-section-wrapper border'>
<span style='font-weight:bold;'><span id='lt-trans-heurCan'></span></span>
<div class='lt-option-container' style='float:right;'>
<input type=checkbox class='lt-checkbox' id='lt-LaneHeuristicsChecks' />
<label class='lt-label' for='lt-LaneHeuristicsChecks'><span class='lt-trans-enabled'></span></label>
</div>
</div>
<div id='lt-heur-wrapper'>
<div class='lt-option-container' style='margin-bottom:5px;'>
<div style='display:inline-block;'><span class='lt-trans-tglshcut'></span>:<span id='lt-LaneHeurChecksShortcut' style='padding-left:10px;'></span></div>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-LaneHeurPosHighlight' />
<label class='lt-label' for='lt-LaneHeurPosHighlight'><span id='lt-trans-heurPos'></span></label>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-LaneHeurNegHighlight' />
<label class='lt-label' for='lt-LaneHeurNegHighlight'><span id='lt-trans-heurNeg'></span></label>
</div>
</div>
</div>
<div class='lt-section-wrapper'>
<div class='lt-section-wrapper'>
<span id='lt-color-title' data-original-title='${TRANSLATIONS[langLocality].colTooltip}'><span id='lt-trans-highCol'></span>:</span>
<div id='lt-color-inputs' style='display:none;'>
<div class='lt-option-container color'>
<input type=color class='lt-color-input' id='lt-ABColor' />
<label class='lt-label' for='lt-ABColor' id='lt-ABColorLabel'><span id='lt-trans-fwdCol'></span></label>
</div>
<div class='lt-option-container color'>
<input type=color class='lt-color-input' id='lt-BAColor' />
<label class='lt-label' for='lt-BAColor' id='lt-BAColorLabel'><span id='lt-trans-revCol'></span></label>
</div>
<div class='lt-option-container color'>
<input type=color class='lt-color-input' id='lt-LabelColor' />
<label class='lt-label' for='lt-LabelColor' id='lt-LabelColorLabel'><span id='lt-trans-labelCol'></span></label>
</div>
<div class='lt-option-container color'>
<input type=color class='lt-color-input' id='lt-ErrorColor' />
<label class='lt-label' for='lt-ErrorColor' id='lt-ErrorColorLabel'><span id='lt-trans-errorCol'></span></label>
</div>
<div class='lt-option-container color'>
<input type=color class='lt-color-input' id='lt-NodeColor' />
<label class='lt-label' for='lt-NodeColor' id='lt-NodeColorLabel'><span id='lt-trans-nodeCol'></span></label>
</div>
<div class='lt-option-container color'>
<input type=color class='lt-color-input' id='lt-TIOColor' />
<label class='lt-label' for='lt-TIOColor' id='lt-TIOColorLabel'><span id='lt-trans-tioCol'></span></label>
</div>
<div class='lt-option-container color'>
<input type=color class='lt-color-input' id='lt-LIOColor' />
<label class='lt-label' for='lt-TIOColor' id='lt-LIOColorLabel'><span id='lt-trans-laoCol'></span></label>
</div>
<div class='lt-option-container color'>
<input type=color class='lt-color-input' id='lt-CS1Color' />
<label class='lt-label' for='lt-CS1Color' id='lt-CS1ColorLabel'><span id='lt-trans-viewCol'></span></label>
</div>
<div class='lt-option-container color'>
<input type=color class='lt-color-input' id='lt-CS2Color' />
<label class='lt-label' for='lt-CS2Color' id='lt-CS2ColorLabel'><span id='lt-trans-hearCol'></span></label>
</div>
<div class='lt-option-container color'>
<input type=color class='lt-color-input' id='lt-HeurColor' />
<label class='lt-label' for='lt-HeurColor' id='lt-HeurColorLabel'><span id='lt-trans-posCol'></span></label>
</div>
<div class='lt-option-container color'>
<input type=color class='lt-color-input' id='lt-HeurFailColor' />
<label class='lt-label' for='lt-HeurFailColor' id='lt-HeurFailColorLabel'><span id='lt-trans-negCol'></span></label>
</div>
</div>
</div>
</div>
<div class='lt-section-wrapper' id='lt-adv-tools' style='display:none;'>
<div class='lt-section-wrapper border'>
<span style='font-weight:bold;'><span id='lt-trans-advTools'>></span></span>
</div>
<div class='lt-option-container'>
<input type=checkbox class='lt-checkbox' id='lt-SelAllEnable' />
<label class='lt-label' for='lt-SelAllEnable' ><span id='lt-trans-quickTog'></span></label>
</div>
<div class='lt-option-container' id='lt-serverSelectContainer' style='display:none;'>
<input type=checkbox class='lt-checkbox' id='lt-serverSelect' />
<label class='lt-label' for='lt-serverSelect'><span id='lt-trans-heurRBS'></span></label>
</div>
<div class='lt-option-container' id='lt-cpy-pst' style='display:none;'>
<input type=checkbox class='lt-checkbox' id='lt-CopyEnable' />
<label class='lt-label' for='lt-CopyEnable'>Copy/Paste Lanes</label>
<span style='font-weight: bold;'>(**Caution** - double check results, feature still in Dev)</span>
</div>
<div id='lt-sheet-link' style='display:none;'>
<a href='https://docs.google.com/spreadsheets/d/1_3sF09sMOid_us37j5CQqJZlBGGr1vI_3Rrmp5K-KCQ/edit?usp=sharing' target='_blank'>LT Config Sheet</a>
</div>
</div>
</div>
</div>`
].join(' '));
const $ltButtons = $('<div>');
$ltButtons.html([
`<div class='lt-Toolbar-Container' id="lt-toolbar-container">
<div class='lt-Toolbar-Wrapper'>
<div class='lt-toolbar-button-container'>
<button type='button' class='lt-toolbar-button' id='copyA-button'>Copy A</button>
</div>
<div class='lt-toolbar-button-container'>
<button type='button' class='lt-toolbar-button' id='copyB-button'>Copy B</button>
</div>
<div class='lt-toolbar-button-container'>
<button type='button' class='lt-toolbar-button' id='pasteA-button'>Paste A</button>
</div>
<div class='lt-toolbar-button-container'>
<button type='button' class='lt-toolbar-button' id='pasteB-button'>Paste B</button>
</div>
</div>
</div>`
].join(' '));
_pickleColor = seaPickle.attributes.rank;
let proceedReady = _pickleColor >= 0;
if (proceedReady) {
WazeWrap.Interface.Tab('LT', $ltTab.html, setupOptions, 'LT');
$(`<style type="text/css">${ltCss}</style>`).appendTo('head');
$('#map').append($ltButtons.html());
WazeWrap.Interface.ShowScriptUpdate(GM_info.script.name, GM_info.script.version, LI_UPDATE_NOTES, GF_LINK, FORUM_LINK);
console.log('LaneTools: loaded');
} else {
console.error('LaneTools: loading error....');
}
}
function startScriptUpdateMonitor() {
let updateMonitor;
try {
updateMonitor = new WazeWrap.Alerts.ScriptUpdateMonitor(GM_info.script.name, GM_info.script.version, DOWNLOAD_URL, GM_xmlhttpRequest, DOWNLOAD_URL);
updateMonitor.start();
} catch (ex) {
// Report, but don't stop if ScriptUpdateMonitor fails.
console.error('WME LaneTools:', ex);
}
}
async function setupOptions() {
function setOptionStatus() {
// Set check boxes based on last use
setChecked('lt-ScriptEnabled', LtSettings.ScriptEnabled);
setChecked('lt-UIEnable', LtSettings.UIEnable);
setChecked('lt-AutoOpenWidth', LtSettings.AutoOpenWidth);
setChecked('lt-AutoExpandLanes', LtSettings.AutoExpandLanes);
setChecked('lt-AutoLanesTab', LtSettings.AutoLanesTab);
setChecked('lt-HighlightsEnable', LtSettings.HighlightsEnable);
setChecked('lt-LabelsEnable', LtSettings.LabelsEnable);
setChecked('lt-NodesEnable', LtSettings.NodesEnable);
setChecked('lt-LIOEnable', LtSettings.LIOEnable);
setChecked('lt-CSEnable', LtSettings.CSEnable);
setChecked('lt-highlightOverride', LtSettings.highlightOverride);
setChecked('lt-CopyEnable', LtSettings.CopyEnable);
setChecked('lt-SelAllEnable', LtSettings.SelAllEnable);
setChecked('lt-serverSelect', LtSettings.serverSelect);
setChecked('lt-AutoFocusLanes', LtSettings.AutoFocusLanes);
setChecked('lt-ReverseLanesIcon', LtSettings.ReverseLanesIcon);
setChecked('lt-ClickSaveEnable', LtSettings.ClickSaveEnable);
setChecked('lt-ClickSaveStraight', LtSettings.ClickSaveStraight);
setChecked('lt-ClickSaveTurns', LtSettings.ClickSaveTurns);
setChecked('lt-LaneHeurPosHighlight', LtSettings.LaneHeurPosHighlight);
setChecked('lt-LaneHeurNegHighlight', LtSettings.LaneHeurNegHighlight);
setChecked('lt-LaneHeuristicsChecks', LtSettings.LaneHeuristicsChecks);
setChecked('lt-highlightCSIcons', LtSettings.highlightCSIcons);
setChecked('lt-AddTIO', LtSettings.AddTIO);
setChecked('lt-IconsEnable', LtSettings.IconsEnable);
setChecked('lt-IconsRotate', LtSettings.IconsRotate);
setValue('lt-ABColor', LtSettings.ABColor);
setValue('lt-BAColor', LtSettings.BAColor);
setValue('lt-LabelColor', LtSettings.LabelColor);
setValue('lt-ErrorColor', LtSettings.ErrorColor);
setValue('lt-NodeColor', LtSettings.NodeColor);
setValue('lt-TIOColor', LtSettings.TIOColor);
setValue('lt-LIOColor', LtSettings.LIOColor);
setValue('lt-CS1Color', LtSettings.CS1Color);
setValue('lt-CS2Color', LtSettings.CS2Color);
setValue('lt-HeurColor', LtSettings.HeurColor);
setValue('lt-HeurFailColor', LtSettings.HeurFailColor);
if (!getId('lt-ClickSaveEnable').checked) {
$('.lt-option-container.clk-svr').hide();
}
if (!getId('lt-UIEnable').checked) {
$('#lt-UI-wrapper').hide();
}
if (!getId('lt-HighlightsEnable').checked) {
$('#lt-highlights-wrapper').hide();
}
if (!getId('lt-LaneHeuristicsChecks').checked) {
$('#lt-heur-wrapper').hide();
}
function setChecked(checkboxId, checked) {
$(`#${checkboxId}`).prop('checked', checked);
}
function setValue(inputId, color) {
const inputElem = $(`#${inputId}`);
inputElem.attr('value', color);
inputElem.css('border', `2px solid ${color}`);
}
}
await loadSettings();
await loadSpreadsheet();
initLaneGuidanceClickSaver();
// Layer for highlights
LTHighlightLayer = new OpenLayers.Layer.Vector('LTHighlightLayer', { uniqueName: '_LTHighlightLayer' });
W.map.addLayer(LTHighlightLayer);
LTHighlightLayer.setVisibility(true);
// Layer for future use of lane association icons...
LTLaneGraphics = new OpenLayers.Layer.Vector('LTLaneGraphics', { uniqueName: 'LTLaneGraphics' });
W.map.addLayer(LTLaneGraphics);
LTLaneGraphics.setVisibility(true);
// Layer for lane text
const namesStyle = new OpenLayers.Style({
fontFamily: 'Open Sans, Alef, helvetica, sans-serif, monospace',
labelOutlineColor: 'black',
fontColor: '${labelColor}',
fontSize: '16',
labelXOffset: 15,
labelYOffset: -15,
labelOutlineWidth: '3',
label: '${labelText}',
angle: '',
labelAlign: 'cm',
'stroke-width': '0'
});
LTNamesLayer = new OpenLayers.Layer.Vector('LTNamesLayer', {
uniqueName: 'LTNamesLayer',
styleMap: new OpenLayers.StyleMap(namesStyle)
});
W.map.addLayer(LTNamesLayer);
LTNamesLayer.setVisibility(true);
// Add event listers
WazeWrap.Events.register('moveend', null, scanArea);
WazeWrap.Events.register('moveend', null, displayLaneGraphics);
WazeWrap.Events.register('zoomend', null, scanArea);
WazeWrap.Events.register('zoomend', null, displayLaneGraphics);
WazeWrap.Events.register('afteraction', null, scanArea);
WazeWrap.Events.register('afteraction', null, lanesTabSetup);
WazeWrap.Events.register('afteraction', null, displayLaneGraphics);
WazeWrap.Events.register('afterundoaction', null, scanArea);
WazeWrap.Events.register('afterundoaction', null, lanesTabSetup);
WazeWrap.Events.register('afterundoaction', null, displayLaneGraphics);
WazeWrap.Events.register('afterclearactions', null, scanArea);
WazeWrap.Events.register('selectionchanged', null, scanArea);
WazeWrap.Events.register('selectionchanged', null, lanesTabSetup);
WazeWrap.Events.register('selectionchanged', null, displayLaneGraphics);
WazeWrap.Events.register('changelayer', null, scanArea);
// Add keyboard shortcuts
try {
new WazeWrap.Interface.Shortcut('enableHighlights', 'Toggle lane highlights', 'wmelt', 'Lane Tools', LtSettings.enableHighlights, toggleHighlights, null).add();
new WazeWrap.Interface.Shortcut('enableUIEnhancements', 'Toggle UI enhancements', 'wmelt', 'Lane Tools', LtSettings.enableUIEnhancements, toggleUIEnhancements, null).add();
new WazeWrap.Interface.Shortcut('enableHeuristics', 'Toggle heuristic highlights', 'wmelt', 'Lane Tools', LtSettings.enableHeuristics, toggleLaneHeuristicsChecks, null).add();
new WazeWrap.Interface.Shortcut('enableScript', 'Toggle script', 'wmelt', 'Lane Tools', LtSettings.enableScript, toggleScript, null).add();
} catch(e) {
console.log(`LT: Error creating shortcuts. This feature will be disabled.`);
$('#lt-EnableShortcut').text(`${TRANSLATIONS.default.disabled}`);
$('#lt-HighlightShortcut').text(`${TRANSLATIONS.default.disabled}`);
$('#lt-UIEnhanceShortcut').text(`${TRANSLATIONS.default.disabled}`);
$('#lt-LaneHeurChecksShortcut').text(`${TRANSLATIONS.default.disabled}`);
shortcutsDisabled = true;
}
// Setup user options now that the settings are loaded
const highlights = $('#lt-HighlightsEnable');
const colorTitle = $('#lt-color-title');
const heurChecks = $('#lt-LaneHeuristicsChecks');
setOptionStatus();
setTimeout(() => {
updateShortcutLabels();
}, 50);
setHeuristics();
setTranslations();
if (_pickleColor > 0) {
let featureList = 'LaneTools: The following special access features are enabled: ';
$('#lt-adv-tools').css('display', 'block');
let quickTog = $('#lt-trans-quickTog');
quickTog.attr('data-original-title', `${strings.selAllTooltip}`);
quickTog.tooltip();
_.each(RBSArray, u => {
if (u[0] === seaPickle.attributes.userName) {
if (u[1] === '1') {
isRBS = true;
}
if (u[2] === '1') {
allowCpyPst = true;
}
}
});
if (isRBS) {
$('#lt-serverSelectContainer').css('display', 'block');
featureList += 'RBS Heuristics';
}
if (allowCpyPst) {
$('#lt-sheet-link').css({
display: 'block',
margin: '2px'
});
let ltSheetLinkAnchor = $('#lt-sheet-link > a');
ltSheetLinkAnchor.css({
padding: '2px',
border: '2px solid black',
'border-radius': '6px',
'text-decoration': 'none'
});
ltSheetLinkAnchor.on("mouseenter",function () {
$(this).css('background-color', 'orange');
}).on("mouseleave", function () {
$(this).css('background-color', '#eeeeee');
});
// $('#lt-cpy-pst').css('display', 'block');
// $('.lt-Toolbar-Container').draggable({ containment: 'parent', zIndex: '100' });
// WazeWrap.Events.register('selectionchanged', null, displayToolbar);
$('.lt-toolbar-button').on("click",function () {
if ($(this)[0].id === 'copyA-button') {
copyLaneInfo('A');
}
if ($(this)[0].id === 'copyB-button') {
copyLaneInfo('B');
}
if ($(this)[0].id === 'pasteA-button') {
pasteLaneInfo('A');
}
if ($(this)[0].id === 'pasteB-button') {
pasteLaneInfo('B');
}
});
featureList = isRBS ? `${featureList}, Copy/Paste` : `${featureList}Copy/Paste`;
}
if (isRBS || allowCpyPst) {
console.log(featureList);
}
} else {
$('#lt-LaneTabFeatures').css('display', 'none');
}
$('.lt-checkbox').on("click",function () {
let settingName = $(this)[0].id.substring(3);
LtSettings[settingName] = this.checked;
saveSettings();
});
$('.lt-color-input').on("change",function () {
let settingName = $(this)[0].id.substring(3);
LtSettings[settingName] = this.value;
saveSettings();
$(`#lt-${settingName}`).css('border', `2px solid ${this.value}`);
removeHighlights();
scanArea();
});
$('#lt-ScriptEnabled').on("click",() => {
if (getId('lt-ScriptEnabled').checked) {
scanArea();
} else {
removeHighlights();
removeLaneGraphics()
}
});
highlights.on("click",() => {
if (getId('lt-HighlightsEnable').checked) {
scanArea();
} else {
removeHighlights();
}
scanArea();
});
$('#lt-LabelsEnable').on("click",() => {
if (getId('lt-LabelsEnable').checked) {
scanArea();
} else {
removeHighlights();
scanArea();
}
});
$('#lt-NodesEnable').on("click",() => {
if (getId('lt-NodesEnable').checked) {
scanArea();
} else {
removeHighlights();
scanArea();
}
});
$('#lt-LIOEnable').on("click",() => {
if (getId('lt-LIOEnable').checked) {
scanArea();
} else {
removeHighlights();
scanArea();
}
});
$('#lt-IconsEnable').on("click",() => {
if (getId('lt-IconsEnable').checked) {
displayLaneGraphics();
} else {
removeLaneGraphics();
}
});
$('#lt-highlightOverride').on("click",() => {
if (getId('lt-highlightOverride').checked) {
scanArea();
} else {
removeHighlights();
scanArea();
}
});
colorTitle.on("click",() => {
$('#lt-color-inputs').toggle();
});
$('#lt-ClickSaveEnable').on("click",() => {
$('.lt-option-container.clk-svr').toggle();
});
$('#lt-UIEnable').on("click",() => {
$('#lt-UI-wrapper').toggle();
removeLaneGraphics()
});
highlights.on("click",() => {
$('#lt-highlights-wrapper').toggle();
});
heurChecks.on("click",() => {
$('#lt-heur-wrapper').toggle();
});
heurChecks.on("click",() => {
if (getId('lt-LaneHeuristicsChecks').checked) {
scanArea();
} else {
removeHighlights();
scanArea();
}
});
$('#lt-LaneHeurPosHighlight').on("click",() => {
if (getId('lt-LaneHeurPosHighlight').checked) {
scanArea();
} else {
removeHighlights();
scanArea();
}
});
$('#lt-LaneHeurNegHighlight').on("click",() => {
if (getId('lt-LaneHeurNegHighlight').checked) {
scanArea();
} else {
removeHighlights();
scanArea();
}
});
$('#lt-serverSelect').on("click",() => {
setHeuristics();
removeHighlights();
scanArea();
});
// Watches for the shortcut dialog to close and updates UI
const el = $.fn.hide;
$.fn.hide = function () {
this.trigger('hide');
return el.apply(this, arguments);
};
$('#keyboard-dialog').on('hide', () => {
checkShortcutsChanged();
});
scanArea();
lanesTabSetup();
displayLaneGraphics();
colorTitle.tooltip();
}
async function loadSettings() {
const localSettings = JSON.parse(localStorage.getItem('LT_Settings'));
const serverSettings = await WazeWrap.Remote.RetrieveSettings('LT_Settings');
if (!serverSettings) {
console.error('LaneTools: Error communicating with WW settings server');
}
const defaultSettings = {
lastSaveAction: 0,
ScriptEnabled: true,
UIEnable: true,
AutoOpenWidth: false,
AutoExpandLanes: false,
AutoLanesTab: false,
HighlightsEnable: true,
LabelsEnable: true,
NodesEnable: true,
ABColor: '#990033',
BAColor: '#0033cc',
LabelColor: '#FFAD08',
ErrorColor: '#F50E0E',
NodeColor: '#66ccff',
TIOColor: '#ff9900',
LIOColor: '#ff9900',
CS1Color: '#04E6F6',
CS2Color: '#8F47FA',
HeurColor: '#00aa00',
HeurFailColor: '#E804F6',
CopyEnable: false,
SelAllEnable: false,
serverSelect: false,
LIOEnable: true,
CSEnable: true,
AutoFocusLanes: true,
ReverseLanesIcon: false,
ClickSaveEnable: true,
ClickSaveStraight: false,
ClickSaveTurns: true,
enableScript: '',
enableHighlights: '',
enableUIEnhancements: '',
enableHeuristics: '',
LaneHeurNegHighlight: false,
LaneHeurPosHighlight: false,
LaneHeuristicsChecks: false,
highlightCSIcons: false,
highlightOverride: true,
AddTIO: false,
IconsEnable: true,
IconsRotate: true
};
LtSettings = $.extend({}, defaultSettings, localSettings);
if (serverSettings && serverSettings.lastSaveAction > LtSettings.lastSaveAction) {
$.extend(LtSettings, serverSettings);
// console.log('LaneTools: server settings used');
} else {
// console.log('LaneTools: local settings used');
}
// If there is no value set in any of the stored settings then use the default
Object.keys(defaultSettings).forEach((funcProp) => {
if (!LtSettings.hasOwnProperty(funcProp)) {
LtSettings[funcProp] = defaultSettings[funcProp];
}
});
}
async function saveSettings() {
const {
ScriptEnabled,
HighlightsEnable,
LabelsEnable,
NodesEnable,
UIEnable,
AutoLanesTab,
AutoOpenWidth,
AutoExpandLanes,
ABColor,
BAColor,
LabelColor,
ErrorColor,
NodeColor,
TIOColor,
LIOColor,
CS1Color,
CS2Color,
CopyEnable,
SelAllEnable,
serverSelect,
LIOEnable,
CSEnable,
AutoFocusLanes,
ReverseLanesIcon,
ClickSaveEnable,
ClickSaveStraight,
ClickSaveTurns,
enableScript,
enableHighlights,
enableUIEnhancements,
enableHeuristics,
HeurColor,
HeurFailColor,
LaneHeurPosHighlight,
LaneHeurNegHighlight,
LaneHeuristicsChecks,
highlightCSIcons,
highlightOverride,
AddTIO,
IconsEnable,
IconsRotate
} = LtSettings;
const localSettings = {
lastSaveAction: Date.now(),
ScriptEnabled,
HighlightsEnable,
LabelsEnable,
NodesEnable,
UIEnable,
AutoOpenWidth,
AutoLanesTab,
AutoExpandLanes,
ABColor,
BAColor,
LabelColor,
ErrorColor,
NodeColor,
TIOColor,
LIOColor,
CS1Color,
CS2Color,
CopyEnable,
SelAllEnable,
serverSelect,
LIOEnable,
CSEnable,
AutoFocusLanes,
ReverseLanesIcon,
ClickSaveEnable,
ClickSaveStraight,
ClickSaveTurns,
enableScript,
enableHighlights,
enableUIEnhancements,
enableHeuristics,
HeurColor,
HeurFailColor,
LaneHeurPosHighlight,
LaneHeurNegHighlight,
LaneHeuristicsChecks,
highlightCSIcons,
highlightOverride,
AddTIO,
IconsEnable,
IconsRotate
};
// Grab keyboard shortcuts and store them for saving
for (const name in W.accelerators.Actions) {
const {shortcut, group} = W.accelerators.Actions[name];
if (group === 'wmelt') {
let TempKeys = '';
if (shortcut) {
if (shortcut.altKey === true) {
TempKeys += 'A';
}
if (shortcut.shiftKey === true) {
TempKeys += 'S';
}
if (shortcut.ctrlKey === true) {
TempKeys += 'C';
}
if (TempKeys !== '') {
TempKeys += '+';
}
if (shortcut.keyCode) {
TempKeys += shortcut.keyCode;
}
} else {
TempKeys = '-1';
}
localSettings[name] = TempKeys;
}
}
// Required for the instant update of changes to the keyboard shortcuts on the UI
LtSettings = localSettings;