This repository has been archived by the owner on Jan 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwme_junctionangle.user.js
2439 lines (2203 loc) · 89.2 KB
/
wme_junctionangle.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 Junction Angle Info (development version)
// @namespace https://github.com/milkboy/WME-ja
// @description Show the angle between two selected (and connected) segments
// @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
// @updateURL https://github.com/milkboy/WME-ja/raw/development/wme_junctionangle.user.js
// @version 1.15-dev
// @grant none
// @copyright 2019 Michael Wikberg <[email protected]>
// @license CC-BY-NC-SA
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAA6pSURBVFhHrZkJcBNnlscbgjEZmHAYsHVZUrek7pbUuo9W674l65Z8WzbGxoAxhzNgcweMDeY0GLDHwYBhGCABTEwIOSaTZBIyye6mcjBJFTs7O5Xazc4ks7NbU7vJzjKVrc0+RVqwhWEC5NW/VFKr3//79fe+fv3JRrp2bjs00NfW3gqqSldojCqFVk4q8LK4z+a2kEosVRVIVnrL60KMU602SfnaohIaQR0zb/72428eNr7+n6/r14bBh2+ahaJCDMOcWk9ndOuFFdeQlrbF4USZ0aqlNDJKS8YrovXNNSa7PlEVSTdVK3REMGIDcbEiuU5c3hDhmgvA6PV3X8p5P2x89ecv6XIRWCX94bFVP//l+l9lhYikpTB8MOauW1y1pqN13ab26oZkrCLo9JuBZj77CYfH0LysJt1UXtdcqXALwOJHu5bkXB8tRl85C26Mj3xm5eU7QLWN5TB8RV0MXpPVYbVRNuOJqVoT5fAx9c1V3bs2Ny2pYSxqX9AWSvlYpqkc87RPP/tNzvKRo6Y9AEzratrvAD25rrW+sYKQCUQ4F17Ti8pXrlmytLUhFHVX1kTLIq7mltrautSuPTsa1qQgubEznjP7PuKtv3sVPGkPfgeomD1bSqHA1La6OVUZikFJYx54raiOdGxYtXvf9i1b1h3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UW4AAAAASUVORK5CYII=
// ==/UserScript==
/**
* Copyright 2019 Michael Wikberg <[email protected]>
* WME Junction Angle Info extension is licensed under a Creative Commons
* Attribution-NonCommercial-ShareAlike 3.0 Unported License.
*
* Contributions by:
* 2014 Paweł Pyrczak "tkr85" <[email protected]>
* 2014 "AlanOfTheBerg" <[email protected]>
* 2014 "berestovskyy" <?>
* 2015 "FZ69617" <?>
* 2015 "wlodek76" <?>
* 2016 Sergey Kuznetsov "WazeRus" <[email protected]> (Russian translation)
* 2016 "MajkiiTelini" <?> Czech translation
*/
/*jshint eqnull:true, nonew:true, nomen:true, curly:true, latedef:false, unused:strict, noarg:true, loopfunc:true */
/*jshint trailing:true, forin:true, noempty:true, maxparams:7, maxerr:100, eqeqeq:true, strict:true, undef:true */
/*jshint bitwise:true, newcap:true, immed:true, onevar:true, browser:true, nonbsp:true, freeze:true */
/*global I18n, console, $*/
function run_ja() {
"use strict";
/*
* First some variable and enumeration definitions
*/
var ja_version = "1.15-devel";
var ja_debug = 1; //0: no output, 1: basic info, 2: debug 3: verbose debug, 4: insane debug
var ja_last_restart = 0, ja_roundabout_points = [], ja_options = {}, ja_mapLayer;
var ja_TURN_ANGLE = 45.04; //Turn vs. keep angle specified in Wiki.
var ja_U_TURN_ANGLE = 168.24; //U-Turn angle based on map experiments.
var ja_GRAY_ZONE = 0.5; //Gray zone angle intended to prevent from irregularities observed on map.
var ja_OVERLAPPING_ANGLE = 0.666; //Experimentally measured overlapping angle.
var ja_routing_type = {
BC: "junction_none",
KEEP: "junction_keep",
KEEP_LEFT: "junction_keep_left",
KEEP_RIGHT: "junction_keep_right",
TURN: "junction_turn",
EXIT: "junction_exit",
EXIT_LEFT: "junction_exit_left",
EXIT_RIGHT: "junction_exit_right",
U_TURN: "junction_u_turn",
PROBLEM: "junction_problem",
NO_TURN: "junction_no_turn",
NO_U_TURN: "junction_no_u_turn",
ROUNDABOUT: "junction_roundabout",
ROUNDABOUT_EXIT: "junction_roundabout_exit"
};
var ja_road_type = {
//Streets
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
};
var ja_vehicle_types = {
TRUCK: 1,
PUBLIC: 2,
TAXI: 4,
BUS: 8,
HOV2: 16,
HOV3: 32,
RV: 64,
TOWING: 128,
MOTORBIKE: 256,
PRIVATE: 512,
HAZ: 1024
};
var ja_settings = {
defaultOn: { elementType: "checkbox", elementId: "_jaCbShowLayer", defaultValue: true },
angleMode: { elementType: "select", elementId: "_jaSelAngleMode", defaultValue: "aDeparture", options: ["aAbsolute", "aDeparture"]},
angleDisplay: { elementType: "select", elementId: "_jaSelAngleDisplay", defaultValue: "displayFancy", options: ["displayFancy", "displaySimple"]},
angleDisplayArrows: { elementType: "select", elementId: "_jaSelAngleDisplayArrows", defaultValue: "<>", options: ["<>", "⇦⇨", "⇐⇒", "←→", "⇐⇒⇖⇗", "←→↖↗"]},
guess: { elementType: "checkbox", elementId: "_jaCbGuessRouting", defaultValue: true },
noInstructionColor: { elementType: "color", elementId: "_jaTbNoInstructionColor", defaultValue: "#ffffff", group: "guess"},
keepInstructionColor: { elementType: "color", elementId: "_jaTbKeepInstructionColor", defaultValue: "#cbff84", group: "guess"},
exitInstructionColor: { elementType: "color", elementId: "_jaTbExitInstructionColor", defaultValue: "#6cb5ff", group: "guess"},
turnInstructionColor: { elementType: "color", elementId: "_jaTbTurnInstructionColor", defaultValue: "#4cc600", group: "guess"},
uTurnInstructionColor: { elementType: "color", elementId: "_jaTbUTurnInstructionColor", defaultValue: "#b66cff", group: "guess"},
noTurnColor: { elementType: "color", elementId: "_jaTbNoTurnColor", defaultValue: "#a0a0a0", group: "guess"},
problemColor: { elementType: "color", elementId: "_jaTbProblemColor", defaultValue: "#feed40", group: "guess"},
roundaboutOverlayDisplay: { elementType: "select", elementId: "_jaSelRoundaboutOverlayDisplay", defaultValue: "rOverNever", options: ["rOverNever","rOverSelected","rOverAlways"]},
roundaboutOverlayColor: { elementType: "color", elementId: "_jaTbRoundaboutOverlayColor", defaultValue: "#aa0000", group: "roundaboutOverlayDisplay"},
roundaboutColor: { elementType: "color", elementId: "_jaTbRoundaboutColor", defaultValue: "#ff8000", group: "roundaboutOverlayDisplay"},
decimals: { elementType: "number", elementId: "_jaTbDecimals", defaultValue: 0, min: 0, max: 2},
pointSize: { elementType: "number", elementId: "_jaTbPointSize", defaultValue: 12, min: 6, max: 20}
};
var ja_arrow = {
get: function(at) {
var arrows = ja_getOption("angleDisplayArrows");
return arrows[at % arrows.length];
},
left: function() { return this.get(0); },
right: function() { return this.get(1); },
left_up: function() { return this.get(2); },
right_up: function() { return this.get(3); }
};
function getWaze() {
if(window.wrappedJSObject) {
return window.wrappedJSOnject.W;
}
return window.W;
}
/*
* Main logic functions
*/
function junctionangle_init() {
var i, ja_select_option, navTabs, tabContent;
var ja_settings_dom = document.createElement("div");
var ja_settings_dom_panel = document.createElement("div");
var ja_settings_dom_content = document.createElement("div");
var ja_settings_header = document.createElement('h4');
var style = document.createElement('style');
var form = document.createElement('form');
var section = document.createElement('div');
var ja_reset_button = document.createElement('button');
var userTabs = document.getElementById('user-info');
var ja_info = document.createElement('ul');
var ja_version_elem = document.createElement('li');
var jatab = document.createElement('li');
//Listen for selected nodes change event
getWaze().selectionManager.events.register("selectionchanged", null, ja_calculate);
//Temporary workaround. Beta editor changed the event listener logic, but live is still using the old version
//if-else should be removed once not needed anymore
if("events" in getWaze().model.segments) {
//Live
getWaze().model.segments.events.on({
"objectschanged": ja_calculate,
"objectsremoved": ja_calculate
});
getWaze().model.nodes.events.on({
"objectschanged": ja_calculate,
"objectsremoved": ja_calculate
});
} else if("_events" in getWaze().model.segments) {
//Beta editor
getWaze().model.segments.on({
"objectschanged": ja_calculate,
"objectsremoved": ja_calculate
});
getWaze().model.nodes.on({
"objectschanged": ja_calculate,
"objectsremoved": ja_calculate
});
}
//Recalculate on zoom end also
getWaze().map.events.register("zoomend", null, ja_calculate);
ja_load();
ja_loadTranslations();
/**
* Add JAI tab configuration options
*/
ja_settings_dom_panel.className = "side-panel-section";
ja_settings_dom_content.className = "tab-content";
ja_settings_header.appendChild(document.createTextNode(ja_getMessage("settingsTitle")));
ja_settings_dom_content.appendChild(ja_settings_header);
style.appendChild(document.createTextNode(function () {/*
#jaOptions > *:first-child {
margin-top: 1em;
}
#jaOptions * {
vertical-align: middle;
}
#jaOptions label {
display: inline;
}
#jaOptions input, select {
display: inline;
margin-right: 7px;
box-sizing: border-box;
border: 1px solid #cccccc;
border-radius: 5px;
padding: 3px;
}
#jaOptions input[type="number"] {
width: 4em;
padding: 6px;
}
#jaOptions input[type="color"] {
width: 15%;
height: 2em;
padding: 4px;
}
@supports (-webkit-appearance:none) {
#jaOptions input[type="color"] {
padding: 0px 2px 0px 2px;
}
}
#jaOptions .disabled {
position: relative;
}
#jaOptions .disabled:after {
content: " ";
z-index: 10;
display: block;
position: absolute;
height: 100%;
top: 0;
left: 0;
right: 0;
background: rgba(255, 255, 255, 0.666);
}
*/}.toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1]));
section.className = "form-group";
form.className = "attributes-form side-panel-section";
section.id = "jaOptions";
ja_log("---------- Creating settings HTML ----------", 2);
Object.getOwnPropertyNames(ja_settings).forEach(function (a) {
var setting = ja_settings[a];
var ja_controls_container = document.createElement('div');
var ja_input = document.createElement('input');
var ja_label = document.createElement('label');
ja_controls_container.className = "controls-container";
ja_input.type = setting.elementType;
switch (setting.elementType) {
case 'color':
ja_input.id = setting.elementId;
ja_controls_container.appendChild(ja_input);
break;
case 'number':
ja_input.id = setting.elementId;
ja_input.setAttribute("min", setting.min);
ja_input.setAttribute("max", setting.max);
ja_controls_container.appendChild(ja_input);
break;
/*
case 'text':
ja_input.id = setting.elementId;
ja_input.size = (setting.max ? setting.max : 8);
ja_input.maxlength = (setting.max ? setting.max : 7);
ja_controls_container.appendChild(ja_input);
break;
*/
case 'checkbox':
ja_input.id = setting.elementId;
ja_controls_container.appendChild(ja_input);
break;
case 'select':
ja_input = document.createElement('select'); //Override <input> with <select>
ja_input.id = setting.elementId;
for(i = 0; i < setting.options.length; i++) {
ja_select_option = document.createElement('option');
ja_select_option.value = setting.options[i];
ja_select_option.appendChild(document.createTextNode(ja_getMessage(setting.options[i])));
ja_input.appendChild(ja_select_option);
}
ja_controls_container.appendChild(ja_input);
break;
default:
ja_log("Unknown setting type " + setting.elementType, 2);
}
ja_input.onchange = function() { ja_onchange(this); };
ja_label.setAttribute("for", setting.elementId);
ja_label.appendChild(document.createTextNode(ja_getMessage(a)));
ja_controls_container.appendChild(ja_label);
section.appendChild(ja_controls_container);
});
section.appendChild(document.createElement('br'));
ja_reset_button.type = "button";
ja_reset_button.className = "btn btn-default";
ja_reset_button.addEventListener("click", ja_reset, true);
ja_reset_button.appendChild(document.createTextNode(ja_getMessage("resetToDefault")));
section.appendChild(document.createElement('div'));
section.appendChild(ja_reset_button);
form.appendChild(section);
ja_settings_dom_content.appendChild(form);
navTabs = userTabs.getElementsByClassName('nav-tabs')[0];
tabContent = userTabs.getElementsByClassName('tab-content')[0];
ja_settings_dom.id = "sidepanel-ja";
ja_settings_dom.className = "tab-pane";
ja_settings_dom_content.style.paddingTop = "0";
ja_settings_dom.appendChild(style);
ja_settings_dom_panel.appendChild(ja_settings_dom_content);
ja_settings_dom.appendChild(ja_settings_dom_panel);
//Add some version info etc
ja_info.className = "list-unstyled -side-panel-section";
ja_info.style.fontSize = "11px";
ja_version_elem.appendChild(document.createTextNode(ja_getMessage("name") + ": v" + ja_version));
ja_info.appendChild(ja_version_elem);
//Add some useful links
ja_info.appendChild(ja_helpLink(
'https://wiki.waze.com/wiki/Roundabouts/USA#Understanding_navigation_instructions', 'roundaboutnav')
);
ja_info.appendChild(ja_helpLink('https://github.com/milkboy/WME-ja/issues', 'ghissues'));
ja_settings_dom.appendChild(ja_info);
tabContent.appendChild(ja_settings_dom);
jatab.innerHTML = '<!--suppress HtmlUnknownAnchorTarget --><a href="#sidepanel-ja" data-toggle="tab">JAI</a>';
if(navTabs != null) { navTabs.appendChild(jatab); }
//Add support for translations. Default (and fallback) is "en".
//Note, don't make typos in "acceleratorName", as it has to match the layer name (with whitespace removed)
// to actually work. Took me a while to figure that out...
I18n.translations[window.I18n.locale].layers.name.junction_angles = ja_getMessage("name");
/**
* Initialize JAI OpenLayers vector layer
*/
if (getWaze().map.getLayersBy("uniqueName","junction_angles").length === 0) {
// Create a vector layer and give it your style map.
ja_mapLayer = new window.OpenLayers.Layer.Vector(ja_getMessage("name"), {
displayInLayerSwitcher: true,
uniqueName: "junction_angles",
shortcutKey: "S+j",
accelerator: "toggle" + ja_getMessage("name").replace(/\s+/g,''),
className: "junction-angles",
styleMap: new window.OpenLayers.StyleMap(ja_style())
});
//Set visibility according to user preference
ja_mapLayer.setVisibility(ja_getOption("defaultOn"));
getWaze().map.addLayer(ja_mapLayer);
ja_log("version " + ja_version + " loaded.", 0);
ja_log(getWaze().map, 3);
ja_log(getWaze().model, 3);
ja_log(getWaze().loginManager, 3);
ja_log(getWaze().selectionManager, 3);
ja_log(ja_mapLayer, 3);
ja_log(window.OpenLayers, 3);
} else {
ja_log("Oh, nice.. We already had a layer?", 3);
}
ja_apply();
ja_calculate();
}
/**
*
* @param node Junction node
* @param s_in_a "In" segment id
* @param s_out_a "Out" segment id
* @param angles array of segment absolute angles [0] angle, [1] segment id, 2[?]
* @returns {string}
*/
function ja_guess_routing_instruction(node, s_in_a, s_out_a, angles) {
var s_n = {}, s_in = null, s_out = {}, street_n = {}, street_in = null, angle;
var s_in_id = s_in_a;
var s_out_id = s_out_a;
ja_log("Guessing routing instructions from " + s_in_a + " via node " + node.attributes.id + " to " + s_out_a,2);
ja_log(node, 4);
ja_log(s_in_a, 4);
ja_log(s_out_a, 4);
ja_log(angles, 3);
s_in_a = window.$.grep(angles, function(element){
return element[1] === s_in_a;
});
s_out_a = window.$.grep(angles, function(element){
return element[1] === s_out_a;
});
node.attributes.segIDs.forEach(function(element) {
if (element === s_in_id) {
s_in = node.model.segments.getObjectById(element);
street_in = ja_get_streets(element);
//Set empty name for streets if not defined
if(typeof street_in.primary === 'undefined') { street_in.primary = {}; }
if(typeof street_in.primary.name === 'undefined') {
street_in.primary.name = "";
}
} else {
if(element === s_out_id) {
//store for later use
s_out[element] = node.model.segments.getObjectById(element);
//Set empty name for streets if not defined
if(typeof s_out[element].primary === 'undefined') {
s_out[element].primary = { name: "" };
}
}
s_n[element] = node.model.segments.getObjectById(element);
street_n[element] = ja_get_streets(element);
if(typeof street_n[element].primary === 'undefined') {
street_n[element].primary = { name: ""};
}
}
});
ja_log(s_n, 3);
ja_log(street_n,3);
ja_log(s_in,3);
ja_log(street_in,2);
if (s_in === null || street_in === null) {
//Should never happen, but adding to make code validation happy
return ja_routing_type.PROBLEM;
}
angle = ja_angle_diff(s_in_a[0], (s_out_a[0]), false);
ja_log("turn angle is: " + angle, 2);
//Check turn possibility first
if(!ja_is_turn_allowed(s_in, node, s_out[s_out_id])) {
ja_log("Turn is disallowed!", 2);
return ja_routing_type.NO_TURN;
}
//Roundabout - no true instruction guessing here!
if (s_in.attributes.junctionID) {
if (s_out[s_out_id].attributes.junctionID) {
ja_log("Roundabout continuation - no instruction", 2);
return ja_routing_type.BC;
} else {
ja_log("Roundabout exit - no instruction", 2);
//exit just to visually distinguish from roundabout continuation
return ja_routing_type.ROUNDABOUT_EXIT;
}
} else if (s_out[s_out_id].attributes.junctionID) {
ja_log("Roundabout entry - no instruction", 2);
//no instruction since it's normally the only continuation - true instruction can be computed for
//entry-exit selection only
return ja_routing_type.BC;
}
//Check for U-turn, which is emitted even if there is only one s-out
if (Math.abs(angle) > ja_U_TURN_ANGLE + ja_GRAY_ZONE) {
ja_log("Angle is >= 170 - U-Turn", 2);
return ja_routing_type.U_TURN;
} else if (Math.abs(angle) > ja_U_TURN_ANGLE - ja_GRAY_ZONE) {
ja_log("Angle is in gray zone 169-171", 2);
return ja_routing_type.PROBLEM;
}
//No other possible turns
if(node.attributes.segIDs.length <= 2) {
ja_log("Only one possible turn - no instruction", 2);
return ja_routing_type.BC;
} //No instruction
/*
*
* Here be dragons!
*
*/
if(Math.abs(angle) < ja_TURN_ANGLE - ja_GRAY_ZONE) {
ja_log("Turn is <= 44", 2);
/*
* Filter out disallowed and non-"BC eligible" turns.
*/
ja_log("Original angles and street_n:", 2);
ja_log(angles, 2);
ja_log(street_n, 2);
ja_log(s_n, 2);
angles = angles.filter(function (a) {
ja_log("Filtering angle: " + ja_angle_diff(s_in_a, a[0], false), 2);
if(s_out_id === a[1] ||
(typeof s_n[a[1]] !== 'undefined' &&
ja_is_turn_allowed(s_in, node, s_n[a[1]]) &&
Math.abs(ja_angle_diff(s_in_a, a[0], false)) < ja_TURN_ANGLE //Any angle above 45.04 is not eligible
)) {
ja_log(true, 4);
return true;
} else {
ja_log(false, 4);
if(street_n[a[1]]) {
delete s_n[a[1]];
delete street_n[a[1]];
}
return false;
}
});
ja_log("Filtered angles and street_n:", 2);
ja_log(angles, 2);
ja_log(street_n, 2);
ja_log(s_n, 2);
if(angles.length <= 1) {
ja_log("Only one allowed turn left", 2);
return ja_routing_type.BC;
} //No instruction
/*
* Apply simplified BC logic
*/
var bc_matches = {}, bc_prio = 0, bc_count = 0;
var bc_collect = function(a, prio) {
ja_log("Potential BC = " + prio, 2);
ja_log(a, 2);
if (prio > bc_prio) { //highest priority wins now
bc_matches = {};
bc_prio = prio;
bc_count = 0;
}
if (prio === bc_prio) {
bc_matches[a[1]] = a;
bc_count++;
}
ja_log("BC candidates:", 2);
ja_log(bc_matches, 2);
};
//Check each eligible turn against routing rules
for(var k=0; k< angles.length; k++) {
var a = angles[k];
ja_log("Checking angle " + k, 2);
ja_log(a, 2);
var tmp_angle = ja_angle_diff(s_in_a[0], a[0], false);
ja_log(tmp_angle, 2);
var tmp_s_out = {};
tmp_s_out[a[1]] = s_n[a[1]];
var tmp_street_out = {};
tmp_street_out[a[1]] = street_n[a[1]];
var name_match = ja_primary_name_match(street_in, tmp_street_out) ||
ja_alt_name_match(street_in, tmp_street_out) ||
ja_cross_name_match(street_in, tmp_street_out);
if(name_match && ja_segment_type_match(s_in, tmp_s_out)) {
ja_log("BC name and type match", 2);
bc_collect(a, 3);
} else if(name_match) {
ja_log("BC name match", 2);
bc_collect(a, 2);
} else if(ja_segment_type_match(s_in, tmp_s_out)) {
ja_log("BC type match", 2);
bc_collect(a, 1);
}
//Else: Non-BC
}
//If s-out is the only BC, that's it.
if (bc_matches[s_out_id] !== undefined && bc_count === 1) {
ja_log("\"straight\": no instruction", 2);
return ja_routing_type.BC;
}
ja_log("BC logic did not apply; using old default rules instead.", 2);
//FZ69617: Sort angles in left most first order
ja_log("Unsorted angles", 4);
ja_log(angles, 4);
angles.sort(function(a, b) { return ja_angle_dist(a[0], s_in_a[0][0]) - ja_angle_dist(b[0], s_in_a[0][0]); });
ja_log("Sorted angles", 4);
ja_log(angles, 4);
//wlodek76: FIXING KEEP LEFT/RIGHT regarding to left most segment
//WIKI WAZE: When there are more than two segments less than 45.04°, only the left most segment will be
// KEEP LEFT, all the rest will be KEEP RIGHT
//FZ69617: Wiki seems to be wrong here - experiments shows that "more than two" must be read as "at least two"
//FZ69617: Wiki also does not mention differences between RHT and LHT countries for this consideration,
// but map experiments seem to prove that we have to use reverse logic for LHT countries.
if (!s_in.model.isLeftHand) { //RHT
if (angles[0][1] === s_out_id) { //s-out is left most segment
//wlodek76: KEEP LEFT/RIGHT overlapping case
//WIKI WAZE: If the left most segment is overlapping another segment, it will also be KEEP RIGHT.
if (!ja_overlapping_angles(angles[0][0], angles[1][0])) {
ja_log("Left most <45 segment: keep left", 2);
return ja_routing_type.KEEP_LEFT;
}
}
} else { //LHT
//FZ69617: KEEP RIGHT/LEFT logic for right most segment
//MISSING IN WIKI: When there are at least two segments less than 45.04°, only the right most segment will
// be KEEP RIGHT, all the rest will be KEEP LEFT
if (angles[angles.length - 1][1] === s_out_id) { //s-out is right most segment
//FZ69617: KEEP RIGHT/LEFT overlapping case
//MISSING IN WIKI: If the right most segment is overlapping another segment, it will also be KEEP LEFT.
if (!ja_overlapping_angles(angles[angles.length - 1][0], angles[angles.length - 2][0])) {
ja_log("Right most <45 segment: keep right", 2);
return ja_routing_type.KEEP_RIGHT;
}
}
}
//FZ69617: Two overlapping segments logic
//WAZE WIKI: If the only two segments less than 45.04° overlap each other, neither will get an instruction.
//...
//wlodek76: Three overlapping segments logic
//MISSING IN WIKI: If the ONLY THREE segments less than 45.04° overlap each other, neither will get an instruction.
//...
//FZ69617: Two or more overlapping segments logic
//MISSING IN WIKI: If there are two or more segments less than 45.04° and all these segmentes overlap each other,
// neither will get an instruction.
var overlap_i = 1;
while(overlap_i < angles.length &&
ja_overlapping_angles(angles[0][0], angles[overlap_i][0])) {
++overlap_i;
}
if(overlap_i > 1 && overlap_i === angles.length) {
ja_log("Two or more overlapping segments only: no instruction", 2);
return ja_routing_type.BC;
}
//Primary to non-primary
if(ja_is_primary_road(s_in) && !ja_is_primary_road(s_out[s_out_id])) {
ja_log("Primary to non-primary = exit", 2);
return s_in.model.isLeftHand ? ja_routing_type.EXIT_LEFT : ja_routing_type.EXIT_RIGHT;
}
//Ramp to non-primary or non-ramp
if(ja_is_ramp(s_in) && !ja_is_primary_road(s_out[s_out_id]) && !ja_is_ramp(s_out[s_out_id]) ) {
ja_log("Ramp to non-primary and non-ramp = exit", 2);
return s_in.model.isLeftHand ? ja_routing_type.EXIT_LEFT : ja_routing_type.EXIT_RIGHT;
}
ja_log("DEFAULT: keep", 2);
return s_in.model.isLeftHand ? ja_routing_type.KEEP_LEFT : ja_routing_type.KEEP_RIGHT;
} else if (Math.abs(angle) < ja_TURN_ANGLE + ja_GRAY_ZONE) {
ja_log("Angle is in gray zone 44-46", 2);
return ja_routing_type.PROBLEM;
} else {
ja_log("Normal turn", 2);
return ja_routing_type.TURN; //Normal turn (left|right)
}
}
function ja_calculate_real() {
var ja_start_time = Date.now();
var ja_nodes = [];
var restart = false;
ja_log("Actually calculating now", 2);
ja_roundabout_points = [];
ja_log(getWaze().map, 3);
if (typeof ja_mapLayer === 'undefined') {
return;
}
//clear old info
ja_mapLayer.destroyFeatures();
if (ja_getOption("roundaboutOverlayDisplay") === "rOverAlways") {
ja_draw_roundabout_overlay();
}
//try to show all angles for all selected segments
if (!getWaze().selectionManager.hasSelectedFeatures()) { return; }
ja_log("Checking junctions for " + getWaze().selectionManager.getSelectedFeatures().length + " segments", 2);
getWaze().selectionManager.getSelectedFeatures().forEach(function(element) {
ja_log(element, 3);
switch (element.model.type) {
case "node":
ja_nodes.push(element.model.attributes.id);
break;
case "segment":
//segments selected?
if (element.model.attributes.fromNodeID != null &&
ja_nodes.indexOf(element.model.attributes.fromNodeID) === -1) {
ja_nodes.push(element.model.attributes.fromNodeID);
}
if (element.model.attributes.toNodeID != null &&
ja_nodes.indexOf(element.model.attributes.toNodeID) === -1) {
ja_nodes.push(element.model.attributes.toNodeID);
}
break;
case "venue":
break;
default:
ja_log("Found unknown item type: " + element.model.type, 2);
break;
}
ja_log(ja_nodes, 2);
});
//Figure out if we have a selected roundabout and do some magic
var ja_selected_roundabouts = {};
ja_nodes.forEach(function(node) {
ja_log(getWaze().model.nodes.getObjectById(node), 3);
var tmp_s = null, tmp_n = null, tmp_junctionID = null;
if(getWaze().model.nodes.getObjectById(node) == null ||
typeof getWaze().model.nodes.getObjectById(node).attributes.segIDs === 'undefined') {
return;
}
getWaze().model.nodes.getObjectById(node).attributes.segIDs.forEach(function(segment) {
ja_log(segment, 3);
if(getWaze().model.segments.getObjectById(segment).attributes.junctionID) {
ja_log("Roundabout detected: " + getWaze().model.segments.getObjectById(segment).attributes.junctionID, 3);
tmp_junctionID = getWaze().model.segments.getObjectById(segment).attributes.junctionID;
} else {
tmp_s = segment;
tmp_n = node;
}
ja_log("tmp_s: " + (tmp_s === null ? 'null' : tmp_s), 3);
});
ja_log("final tmp_s: " + (tmp_s === null ? 'null' : tmp_s), 3);
if(tmp_junctionID === null) { return; }
if (ja_selected_roundabouts.hasOwnProperty(tmp_junctionID)) {
ja_selected_roundabouts[tmp_junctionID].out_s = tmp_s;
ja_selected_roundabouts[tmp_junctionID].out_n = node;
} else {
ja_selected_roundabouts[tmp_junctionID] = {
'in_s': tmp_s,
'in_n': tmp_n,
'out_s': null,
'out_n': null,
'p': getWaze().model.junctions.get(tmp_junctionID).geometry
};
}
});
//Do some fancy painting for the roundabouts...
for(var tmp_roundabout in ja_selected_roundabouts) {
if (ja_selected_roundabouts.hasOwnProperty(tmp_roundabout)) {
ja_log(tmp_roundabout, 3);
ja_log(ja_selected_roundabouts[tmp_roundabout], 3);
//New roundabouts don't have coordinates yet..
if(typeof ja_selected_roundabouts[tmp_roundabout].p === 'undefined' ||
ja_selected_roundabouts[tmp_roundabout].out_n === null
) {
continue;
}
//Draw circle overlay for this roundabout
if(ja_getOption("roundaboutOverlayDisplay") === "rOverSelected") {
ja_draw_roundabout_overlay(tmp_roundabout);
}
//Transform LonLat to actual layer projection
var tmp_roundabout_center = ja_coordinates_to_point(ja_selected_roundabouts[tmp_roundabout].p.coordinates);
var angle = ja_angle_between_points(
getWaze().model.nodes.getObjectById(ja_selected_roundabouts[tmp_roundabout].in_n).geometry,
tmp_roundabout_center,
getWaze().model.nodes.getObjectById(ja_selected_roundabouts[tmp_roundabout].out_n).geometry
);
ja_mapLayer.addFeatures([
new window.OpenLayers.Feature.Vector(
tmp_roundabout_center,
{
angle: ja_round(angle) + '°',
ja_type: ja_is_roundabout_normal(
tmp_roundabout,
ja_selected_roundabouts[tmp_roundabout].in_n) ? ja_routing_type.TURN : ja_routing_type.ROUNDABOUT
}
)
]);
}
}
var ja_label_distance;
/*
* Define a base distance to markers, depending on the zoom level
*/
switch (getWaze().map.zoom) {
case 10:
ja_label_distance = 2.8;
break;
case 9:
ja_label_distance = 4;
break;
case 8:
ja_label_distance = 8;
break;
case 7:
ja_label_distance = 15;
break;
case 6:
ja_label_distance = 25;
break;
case 5:
ja_label_distance = 40;
break;
case 4:
ja_label_distance = 80;
break;
case 3:
ja_label_distance = 150;
break;
case 2:
ja_label_distance = 300;
break;
case 1:
ja_label_distance = 400;
break;
default:
ja_log("Unsupported zoom level: " + getWaze().map.zoom + "!", 2);
}
ja_label_distance *= (1 + (0.2 * parseInt(ja_getOption("decimals"))));
ja_log("zoom: " + getWaze().map.zoom + " -> distance: " + ja_label_distance, 2);
/**
* Collect double-turn (inc. U-turn) segments info
*/
var doubleTurns = {
data: {}, //Structure: map<s_id, map<s_out_id, list<{s_in_id, angle, turn_type}>>>
collect: function (s_id, s_in_id, s_out_id, angle, turn_type) {
ja_log("Collecting double-turn path from " + s_in_id + " to " + s_out_id +
" via " + s_id + " with angle " + angle + " type: " + turn_type, 2);
var info = this.data[s_id];
if (info === undefined) {
info = this.data[s_id] = {};
}
var list = info[s_out_id];
if (list === undefined) {
list = info[s_out_id] = [];
}
list.push({ s_in_id: s_in_id, angle: angle, turn_type: turn_type });
},
forEachItem: function (s_id, s_out_id, fn) {
var info = this.data[s_id];
if (info !== undefined) {
var list = info[s_out_id];
if (list !== undefined) {
list.forEach(function(item, i) {
fn(item, i);
});
}
}
}
};
//Loop through all 15m or less long segments and collect double-turn disallowed ones
if (ja_getOption("angleMode") === "aDeparture" && ja_nodes.length > 1) {
getWaze().selectionManager.getSelectedFeatures().forEach(function (selectedSegment) {
var segmentId = selectedSegment.model.attributes.id;
var segment = getWaze().model.segments.objects[segmentId];
ja_log("Checking " + segmentId + " for double turns ...", 2);
var len = ja_segment_length(segment);
ja_log("Segment " + segmentId + " length: " + len, 2);
if (Math.round(len) <= 15) {
var fromNode = getWaze().model.nodes.getObjectById(segment.attributes.fromNodeID);
var toNode = getWaze().model.nodes.getObjectById(segment.attributes.toNodeID);
var a_from = ja_getAngle(segment.attributes.fromNodeID, segment);
var a_to = ja_getAngle(segment.attributes.toNodeID, segment);
fromNode.attributes.segIDs.forEach(function (fromSegmentId) {
if (fromSegmentId === segmentId) { return; }
var fromSegment = getWaze().model.segments.objects[fromSegmentId];
var from_a = ja_getAngle(segment.attributes.fromNodeID, fromSegment);
var from_angle = ja_angle_diff(from_a, a_from, false);
ja_log("Segment from " + fromSegmentId + " angle: " + from_a + ", turn angle: " + from_angle, 2);
toNode.attributes.segIDs.forEach(function (toSegmentId) {
if (toSegmentId === segmentId) {return; }
var toSegment = getWaze().model.segments.objects[toSegmentId];
var to_a = ja_getAngle(segment.attributes.toNodeID, toSegment);
var to_angle = ja_angle_diff(to_a, a_to, false);
ja_log("Segment to " + toSegmentId + " angle: " + to_a + ", turn angle: " + to_angle, 2);
var angle = Math.abs(to_angle - from_angle);
ja_log("Angle from " + fromSegmentId + " to " + toSegmentId + " is: " + angle, 2);
//Determine whether a turn is disallowed
if (angle >= 175 - ja_GRAY_ZONE && angle <= 185 + ja_GRAY_ZONE) {
var turn_type = (angle >= 175 + ja_GRAY_ZONE && angle <= 185 - ja_GRAY_ZONE) ?
ja_routing_type.NO_U_TURN : ja_routing_type.PROBLEM;
if (ja_is_turn_allowed(fromSegment, fromNode, segment) &&
ja_is_turn_allowed(segment, toNode, toSegment)) {
doubleTurns.collect(segmentId, fromSegmentId, toSegmentId, angle, turn_type);
}
if (ja_is_turn_allowed(toSegment, toNode, segment) &&
ja_is_turn_allowed(segment, fromNode, fromSegment)) {
doubleTurns.collect(segmentId, toSegmentId, fromSegmentId, angle, turn_type);
}
}
});
});
}
});
}
ja_log("Collected double-turn segments:", 2);
ja_log(doubleTurns.data, 2);
//Start looping through selected nodes
for (var i = 0; i < ja_nodes.length; i++) {
var node = getWaze().model.nodes.getObjectById(ja_nodes[i]);
var angles = [];
var ja_selected_segments_count = 0;
var ja_selected_angles = [];
var a;
if (node == null || !node.hasOwnProperty('attributes')) {
//Oh oh.. should not happen? We want to use a node that does not exist
ja_log("Oh oh.. should not happen?",2);
ja_log(node, 2);
ja_log(ja_nodes[i], 2);
ja_log(getWaze().model, 3);
ja_log(getWaze().model.nodes, 3);
continue;
}
//check connected segments
var ja_current_node_segments = node.attributes.segIDs;
ja_log(node, 2);
//ignore of we have less than 2 segments
if (ja_current_node_segments.length <= 1) {
ja_log("Found only " + ja_current_node_segments.length + " connected segments at " + ja_nodes[i] +
", not calculating anything...", 2);
continue;
}
ja_log("Calculating angles for " + ja_current_node_segments.length + " segments", 2);
ja_log(ja_current_node_segments, 3);
ja_current_node_segments.forEach(function (nodeSegment, j) {
var s = getWaze().model.segments.objects[nodeSegment];
if(typeof s === 'undefined') {
//Meh. Something went wrong, and we lost track of the segment. This needs a proper fix, but for now
// it should be sufficient to just restart the calculation
ja_log("Failed to read segment data from model. Restarting calculations.", 1);
if(ja_last_restart === 0) {
ja_last_restart = new Date().getTime();
setTimeout(function(){ja_calculate();}, 500);
}
restart = true;
}
a = ja_getAngle(ja_nodes[i], s);
ja_log("Segment " + nodeSegment + " angle is " + a, 2);
angles[j] = [a, nodeSegment, s == null ? false : s.isSelected()];
if (s == null ? false : s.isSelected()) {
ja_selected_segments_count++;
}
});
if(restart) { return; }
//make sure we have the selected angles in correct order
ja_log(ja_current_node_segments, 3);
getWaze().selectionManager.getSelectedFeatures().forEach(function (selectedSegment) {
var selectedSegmentId = selectedSegment.model.attributes.id;
ja_log("Checking if " + selectedSegmentId + " is in current node", 3);
if(ja_current_node_segments.indexOf(selectedSegmentId) >= 0) {
ja_log("It is!", 4);
//find the angle