-
Notifications
You must be signed in to change notification settings - Fork 0
/
RpiRoadbookGen_v3.html
executable file
·1357 lines (1225 loc) · 60.1 KB
/
RpiRoadbookGen_v3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>RpiRoadbook RB Gen using Mapbox Directions API v0.3</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.6.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.6.1/mapbox-gl.css' rel='stylesheet' />
<link rel="stylesheet" href="font-awesome.min.css">
<link rel="stylesheet" href="w3.css">
<script src="html2pdf.bundle.min.js"></script>
<script src="turf.min.js"></script>
<script src="myAPIKey.js"></script>
<script>
function switch_tablette_A4() {
var x = document.getElementById('directions_instructions');
var y = document.getElementById('directions_instructions_A4');
var x2 = document.getElementById('directions_intersections_instructions');
var y2 = document.getElementById('directions_intersections_instructions_A4');
// var z1 = document.getElementsByClassName('info-box');
//var z2 = document.getElementsByClassName('stats');
var schema_options = document.getElementById('schema_form').elements['schema_options'].value ;
if (schema_options == 'boulefleche') {
if (x.style.display === "none") {
x.style.display = "block";
y.style.display = "none" ;
x2.style.display = "none";
y2.style.display = "none" ;
// z1[0].style.left = '400px';
// z2[0].style.left = '400px';
} else {
x.style.display = "none";
y.style.display = "block" ;
x2.style.display = "none";
y2.style.display = "none" ;
// z1[0].style.left = '800px';
// z2[0].style.left = '800px';
}
}
else {
if (x2.style.display === "none") {
x.style.display = "none";
y.style.display = "none" ;
x2.style.display = "block";
y2.style.display = "none" ;
// z1[0].style.left = '400px';
// z2[0].style.left = '400px';
} else {
x.style.display = "none";
y.style.display = "none" ;
x2.style.display = "none";
y2.style.display = "block" ;
// z1[0].style.left = '800px';
// z2[0].style.left = '800px';
}
}
}
function printPDF() {
var schema_options = document.getElementById('schema_form').elements['schema_options'].value ;
if (schema_options == 'boulefleche') {
var element = document.getElementById('instructions');
} else {
var element = document.getElementById('instructions_fishbone');
}
// Enable all 'modes', with no explicit elements.
html2pdf().set({
pagebreak: { mode: ['avoid-all', 'css', 'legacy'] }
});
var opt = {
margin: 1,
filename: 'MonRoadbook_rb.pdf',
image: { type: 'jpeg', quality: 0.98 },
//html2canvas: { allowTaint:true,foreignObjectRendering:true},
html2canvas: { allowTaint:true},
jsPDF: { unit: 'mm', format: [105,35], orientation: 'landscape'}
};
html2pdf().from(element).set(opt).save();
}
var myDirections = '' ;
function printPDF_A4() {
var schema_options = document.getElementById('schema_form').elements['schema_options'].value ;
if (schema_options == 'boulefleche') {
var element = document.getElementById('instructions_A4');
} else {
var element = document.getElementById('instructions_fishbone_A4');
}
// Enable all 'modes', with no explicit elements.
html2pdf().set({
pagebreak: { mode: ['avoid-all', 'css', 'legacy'] }
});
var opt = {
margin: 1,
filename: 'MonRoadbook_A4.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { allowTaint:true },
jsPDF: { unit: 'mm', format: [210,291], orientation: 'portrait'}
};
html2pdf().from(element).set(opt).save();
}
function savePoints() {
if (localStorage.myPoints != '' ) {
if ( ! confirm('RB déjà existant. Ecraser ?')) {
return ;
} ;
} ;
var features = draw.getAll();
// Keeping only last linestring
removed = features.features.splice(0,features.features.length-1) ;
localStorage.myPoints = JSON.stringify(features) ;
localStorage.myDirections = myDirections ;
}
function restorePoints() {
if (localStorage.myPoints != null) {
var features = JSON.parse(localStorage.myPoints) ;
myDirections = localStorage.myDirections ;
getMatch(myDirections) ;
draw.set(features) ;
} ;
}
var slideIndex = 1;
//showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length} ;
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
</script>
<style>
html,body {
height:100% ;
width:100% ;
}
#rb { max-width: 400px;max-height:80%;overflow-y:auto;overflow-x: auto; }
#directions_instructions {
top: 0; bottom:0; left:0; width:400px; height:100%;
background-color: rgba(255, 255, 255, 0.8);
overflow: auto ;
font-family: sans-serif;
}
#instructions {
position:relative;
font-size:12px;
width:380px;
}
#directions_instructions_A4 {
top: 0; bottom:0; left:0; width:800px; height:100%;
background-color: rgba(255, 255, 255, 0.8);
overflow: auto ;
font-family: sans-serif;
}
#instructions_A4 {
position:relative;
font-size:12px;
width:760px;
}
table {
border: medium solid #6495ed;
border-collapse: collapse;
width: 380px;
}
#instructable_A4 {
border: medium solid #6495ed;
border-collapse: collapse;
width: 760px;
}
th {
font-family: monospace;
border: thin solid #6495ed;
padding: 0px;
background-color: #D0E3FA;
}
tr {
padding: 0px;
max-height: 100px ;
overflow: hidden ;
}
td {
font-family: sans-serif;
border: thin solid #6495ed;
padding: 0px;
text-align: center;
background-color: #ffffff;
height:100px;
max-height: 100px;
overflow:hidden;
}
caption {
font-family: sans-serif;
}
.total_distance_header {
font-size: 10px;
text-align: center;
position: relative;
}
.numero {
top:0px;
font-size: 10px;
text-align: left;
position: relative;
}
.total_distance {
font-size: 40px;
text-align: center;
position: relative;
}
.partial_distance {
position: relative;
font-size:10px;
bottom:0px;
text-align: right;
background-color: rgba(125,125,125,0.9);
}
.space_distance {
position: relative;
height:10px;
}
.instruction {
position: relative;
height:67px;
overflow:hidden;
}
.route {
position: relative;
bottom:0px;
text-align: center;
font-size:15px;
/* background-color: rgba(125,125,125,0.9); */
outline : 1px solid;
overflow:hidden;
height:20px;
max-height:20px;
}
.img_direction {
width: 100px;
height:100px;
font-size: 25px;
text-align: center;
position: relative;
}
#map { position:absolute; top:0; bottom:0; left:0px; right:0px; }
#mapmenu {
position: absolute;
background: #fff;
padding: 10px;
font-family: 'Open Sans', sans-serif;
}
</style>
</head>
<body>
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.0.9/mapbox-gl-draw.js'></script>
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.0.9/mapbox-gl-draw.css' type='text/css'/>
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-directions/v4.0.0/mapbox-gl-directions.js'></script>
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-directions/v4.0.0/mapbox-gl-directions.css' type='text/css' />
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.3.0/mapbox-gl-geocoder.min.js'></script>
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.3.0/mapbox-gl-geocoder.css' type='text/css' />
<!-- definition du layout -->
<!-- Titre -->
<div id='RbGen' class='w3-container w3-row'>
<div class='w3-col m3 w3-light-blue'>
<div id='calculated-line'>Distance: km<br>Temps de parcours: minutes<br>Nb de cases/intersections: </div>
<div id='info' class='stats'></div>
</div>
<div class='w3-col m8 w3-center'>
<h1>RpiRoadbook RB Generator</h1>
</div>
<div class='w3-col m1 w3-right'>
<!-- Trigger/Open the Modal -->
<button onclick="document.getElementById('config').style.display='block'" class="w3-button w3-right"><i class="w3-xxlarge fa fa-gear"></i></button>
<!-- The Config Modal -->
<div id="config" class="w3-modal">
<div class="w3-modal-content">
<div class="w3-container">
<span onclick="document.getElementById('config').style.display='none'"
class="w3-button w3-display-topright">×</span>
<h2>Configuration des options</h2>
<hr>
<!-- Choix du mode -->
<form id="mode_form" class="w3-container w3-left">
Routage pour :
<input class="w3-radio" type="radio" name="mode_transport" value="vl" checked>
<label>Voiture/Moto</label>
<input class="w3-radio" type="radio" name="mode_transport" value="velo">
<label>Vélo</label>
<input class="w3-radio" type="radio" name="mode_transport" value="piéton">
<label>Piéton</label>
</form>
<!-- Option de routage -->
<form id="options_form" class="w3-container w3-left">
Restrictions :
<input class="w3-radio" type="radio" name="transport_options" value="toll">
<label>Eviter les péages</label>
<input class="w3-radio" type="radio" name="transport_options" value="motorway" checked>
<label>Eviter les autoroutes</label>
<input class="w3-radio" type="radio" name="transport_options" value="ferry">
<label>Eviter les ferries</label>
<input class="w3-radio" type="radio" name="transport_options" value="no_limit">
<label>Pas de restriction</label>
</form>
<br><br><br>
<hr>
<!-- Option de representation -->
<form id="schema_form" class="w3-container w3-left">
Représentation :
<input class="w3-radio" type="radio" name="schema_options" value="boulefleche" checked>
<label>Boule-Flèche</label>
<input class="w3-radio" type="radio" name="schema_options" value="fishbone">
<label>Allemand (arête de poisson)</label>
</form>
<br><br>
</div>
</div>
</div>
</div>
</div>
<!-- Barre de fonctions -->
<div id='menu' class='w3-bar w3-black'>
<button class='w3-bar-item w3-button w3-hover-green' type="button" title= "Tablette/Liseuse=1 page par case<br/>A4 = 2x10 cases par page" onclick="switch_tablette_A4();">Aperçu Tablette <-> A4</button>
<button class='w3-bar-item w3-button w3-hover-red' type="button" onclick="printPDF();">Export PDF Tablette</button>
<button class='w3-bar-item w3-button w3-hover-blue' type="button" onclick="printPDF_A4();">Export PDF A4</button>
<button class='w3-bar-item w3-button w3-hover-blue' type="button" onclick="savePoints();">Sauvegarder</button>
<button class='w3-bar-item w3-button w3-hover-blue' type="button" onclick="restorePoints();">Restaurer</button>
</div>
<!-- Le Roadbook -->
<div id='rb' style='float:left;width:400px'>
<!-- Format RB -->
<div id='directions_instructions' >
<div id='instructions'>
<table id='instructable'>
<thead>
<tr>
<th width=100px><div class="total_distance_header">Distance Cumulée</div><p>
<div class="partial_distance">Partiel</div></th>
<th width=100px><div class="total_distance_header">Note</div></th>
<th width=180px><div class="total_distance_header">Description</div></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th width=100px><div class="total_distance_header">Distance Cumulée</div><p>
<div class="partial_distance">Partiel</div></th>
<th width=100px><div class="total_distance_header">Note</div></th>
<th width=180px><div class="total_distance_header">Description</div></th>
</tr>
</tfoot>
</table>
</div>
</div>
<!-- Format A4 -->
<div id='directions_instructions_A4' style="float:left;width:800px;display: none;">
<div id='instructions_A4'>
<table id='instructable_A4'>
<tbody>
</tbody>
</table>
</div>
</div>
<!-- Format allemandRB -->
<div id='directions_intersections_instructions' style="float:left;width:400px;display: none;">
<div id='instructions_fishbone'>
<table id='fishbonetable'>
<thead>
<tr>
<th width=100px><div class="total_distance_header">Distance Cumulée</div><p>
<div class="partial_distance">Partiel</div></th>
<th width=100px><div class="total_distance_header">Note</div></th>
<th width=180px><div class="total_distance_header">Description</div></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th width=100px><div class="total_distance_header">Distance Cumulée</div><p>
<div class="partial_distance">Partiel</div></th>
<th width=100px><div class="total_distance_header">Note</div></th>
<th width=180px><div class="total_distance_header">Description</div></th>
</tr>
</tfoot>
</table>
</div>
</div>
<!-- Format allemandA4 -->
<div id='directions_intersections_instructions_A4' style="float:left;width:800px;display: none;">
<div id='instructions_fishbone_A4'>
<table id='fishbone_A4'>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<!-- Partie carte et réglages -->
<div id='mapdiv' style='float:left;width:calc(100% - 400px);height:80%;top:0'>
<!-- Carte -->
<div style='position:relative;height:90%'>
<div id='map' >
</div>
<div id="mapmenu">
<input
id="streets-v11"
type="radio"
name="rtoggle"
value="streets"
checked="checked"
/>
<label for="streets">streets</label>
<input id="outdoors-v11" type="radio" name="rtoggle" value="outdoors" />
<label for="outdoors">outdoors</label>
<input id="satellite-streets-v11" type="radio" name="rtoggle" value="satellite" />
<label for="satellite">satellite</label>
</div>
</div>
<!-- Trigger/Open the Modal -->
<button onclick="document.getElementById('help_fr').style.display='block'" class="w3-button w3-right">Aide</button>
<!-- The Help Modal -->
<div id="help_fr" class="w3-modal">
<div class="w3-modal-content">
<div class="w3-container">
<span onclick="document.getElementById('help_fr').style.display='none'"
class="w3-button w3-display-topright">×</span>
<h2>Aide du générateur de Roadbook</h2>
<hr>
<div class="w3-content w3-display-container">
<div class="mySlides" style="display:block">
<img src="help/01-help.png" style="width:100%">
<div class="w3-display-middle w3-container w3-padding-16 w3-black">
Bienvenue sur l'aide du Générateur de Roadbook
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/02-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
Commençons notre roadbook ! Dans la boîte de recherche en haut à droite,
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/03-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
entrez les premières lettres du lieu de départ, puis cliquez sur la suggestion qui correspond.
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/04-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
La carte va se déplacer au lieu choisi.
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/05-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
Affinez la localisation en déplaçant la carte à la souris ou au clavier (flèches) et en zoomant (molette ou boutons + et - de la barre d'outils)
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/06-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
Basculez dans le mode Saisie en sélectionnant l'outil <bold>Ligne</bold>. La souris change de forme...
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/07-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
et cliquez sur le lieu du départ. Une pastille apparaît
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/08-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
Déplacez la carte vers le lieu suivant et cliquez sur le 2ème point de passage. Répétez pour les points suivants.
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/09-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
Double-cliquez pour marquer le point d'arrivée. Le Roadbook apparaît sur la gauche.
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/10-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
Pour rajouter un point de passage, positionnez-vous sur la ligne pointillée. Le curseur change de forme.
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/11-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
et double-cliquez. Le Roadbook est recalculé.
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/12-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
Pour déplacez un point au bon endroit : cliquez sur la pastille pour la sélectionner, puis glissez-déposez au nouvel emplacement.
Pour le supprimer, sélectionnez-le d'abord, puis cliquez sur la corbeille dans la barre d'outils
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/13-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
Le menu Configuration vous permet de choisir le mode de calcul (voiture/vélo/piéton), les restrictions et
surtout le mode de représentation du Roadbook : boule-flèche (par défaut) ou arête de poisson.
Vous pouvez basculer de l'un à l'autre à tout moment.
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/14-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
Voici ce que donne le même itinéraire en arête de poisson.
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/15-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
Choisissez ensuite la mise en page qui vous convient.
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/16-help.png" style="width:100%">
<div class="w3-display-topmiddle w3-container w3-padding-16 w3-black">
En mode tablette, le PDF comporte une seule ligne par page.
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/17-help.png" style="width:100%">
<div class="w3-display-topmiddle w3-container w3-padding-16 w3-black">
En mode A4, chaque page comporte 2 colonnes de 9 lignes.
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/18-help.png" style="width:100%">
<div class="w3-display-bottommiddle w3-container w3-padding-16 w3-black">
Cliquez sur le bouton d'exportation selon le format préféré pour télécharger votre fichier PDF.
</div>
</div>
<div class="mySlides" style="display:none">
<img src="help/01-help.png" style="width:100%">
<div class="w3-display-middle w3-container w3-padding-16 w3-black">
Amusez-vous bien et soyez prudent sur la route !
</div>
</div>
<button class="w3-button w3-display-left" onclick="plusDivs(-1)">❮</button>
<button class="w3-button w3-display-right" onclick="plusDivs(+1)">❯</button>
</div>
</div>
</div>
</div>
</div>
<!-- Partie à propos et aide -->
<div id='apropos' class='w3-container'>
<div class='w3-container w3-right'>
<p>Pour tout contact : rpiroadbook at gmail dot com</p>
<p>Pour les rapports de bugs : <a href="https://github.com/tqhien/RoadbookGen">le dépôt Github du projet</a></p>
</div>
</div>
<script>
mapboxgl.accessToken = myMapBoxToken ;
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/streets-v9', //style par défaut
center: [2.950,46.955], // position de départ
zoom: 14 // zoom initial
});
// MapStyles
var layerList = document.getElementById('mapmenu');
var inputs = layerList.getElementsByTagName('input');
function switchLayer(layer) {
var layerId = layer.target.id;
map.setStyle('mapbox://styles/mapbox/' + layerId);
}
for (var i = 0; i < inputs.length; i++) {
inputs[i].onclick = switchLayer;
}
var draw = new MapboxDraw({
displayControlsDefault: false,
clickBuffer: 10,
controls: {
line_string: true,
trash: true
},
styles: [
// ACTIVE (being drawn)
// line stroke
{
"id": "gl-draw-line",
"type": "line",
"filter": ["all", ["==", "$type", "LineString"], ["!=", "mode", "static"]],
"layout": {
"line-cap": "round",
"line-join": "round"
},
"paint": {
"line-color": "#3b9ddd",
"line-dasharray": [0.2, 2],
"line-width": 4,
"line-opacity": 0.7
}
},
// vertex point halos
{
"id": "gl-draw-polygon-and-line-vertex-halo-active",
"type": "circle",
"filter": ["all", ["==", "meta", "vertex"], ["==", "$type", "Point"], ["!=", "mode", "static"]],
"paint": {
"circle-radius": 10,
"circle-color": "#ff0066"
}
},
// vertex points
{
"id": "gl-draw-polygon-and-line-vertex-active",
"type": "circle",
"filter": ["all", ["==", "meta", "vertex"], ["==", "$type", "Point"], ["!=", "mode", "static"]],
"paint": {
"circle-radius": 6,
"circle-color": "#3b9ddd",
}
},
]
});
// add the geocoding tool to the map
map.addControl(new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
mapboxgl: mapboxgl
}));
// add the draw tool to the map
map.addControl(draw);
// Add zoom and rotation controls to the map.
map.addControl(new mapboxgl.NavigationControl());
// Add geolocate control to the map.
map.addControl(
new mapboxgl.GeolocateControl({
positionOptions: {
enableHighAccuracy: true
},
trackUserLocation: true
})
);
// add create, update, or delete actions
map.on('draw.create', updateRoute);
map.on('draw.update', updateRoute);
map.on('draw.delete', removeRoute);
// pour debug, position du curseur
// map.on('mousemove', function (e) {
// document.getElementById('info').innerHTML =
// //e.point is the x, y coordinates of the mousemove event relative
// //to the top-left corner of the map
// JSON.stringify(e.point) + '<br />' +
// //e.lngLat is the longitude, latitude geographical position of the event
// JSON.stringify(e.lngLat);
// });
map.on('load', function() {
map.getCanvas().focus();
// pour test ajout d'évènement sur touche
map.getCanvas().addEventListener('keydown', function(e) {
e.preventDefault();
if (e.which === 13) { // enter
console.log ('Enter') ;
} else if (e.which === 38) { // up
console.log ('Up') ;
} else if (e.which === 40) { // down
console.log ('Down') ;
} else if (e.which === 45) { // Insert
console.log ('Insert') ;
//draw.changeMode('cut_line');
}
});
});
// traitement du double clic
map.on('dblclick', function(e) {
const ids = draw.getFeatureIdsAt(e.point);
if (!ids.length) { return; }
// TODO : traitement de l'erreur fin de saisie draw vs insert point
// On récupère la ligne
const line = draw.get(ids[0]) ;
if (typeof line === 'undefined') {return;}
const old_line = line.geometry.coordinates ;
// Positions du curseur et du noeud précédent
const cursorAt = turf.point([e.lngLat.lng, e.lngLat.lat]);
const snapped = turf.pointOnLine(line, cursorAt);
// Insertion du point dans l'array de la linestring
// snapped.properties.index contient l'index du noeud précédent
old_line.splice(snapped.properties.index+1,0,cursorAt.geometry.coordinates) ;
// Construction de la nouvelle ligne, en gardant le même id
var feature = {
id : ids[0],
type : 'Feature',
properties: {},
geometry : {type : 'LineString', coordinates: old_line }
} ;
// On met à jour la ligne
var features = draw.add(feature) ;
// On met à jour le roadbook
updateRoute() ;
});
// Fonctions de dessin des fishbone
function drawFish(canvas, context,l,r){
var imagePaper = new Image();
imagePaper.onload = function(){
// dessin de la flèche vers le haut
context.save() ;
context.translate(100,100) ;
context.drawImage(imagePaper,-100, -100);
context.restore() ;
// dessin des traits
context.beginPath();
context.lineWidth=10;
var x1 = 100 ;
var y1 = 100 ;
var rayon = 65;
context.moveTo(x1, y1-rayon);
context.lineTo(x1, y1+rayon);
context.stroke();
var thetar = 180.0 / (r+1.0) ;
var thetal = 180.0 / (l+1.0) ;
for (i=0; i<r; i++) {
var theta = (i+1)*thetar - 90 ;
context.moveTo(x1, y1);
context.lineTo(x1 + rayon * Math.cos(Math.PI * theta/180.0), y1 + rayon * Math.sin(Math.PI * theta/180.0));
context.stroke();
}
for (i=0; i<l; i++) {
var theta = (i+1)*thetal + 90 ;
context.moveTo(x1, y1);
context.lineTo(x1 + rayon * Math.cos(Math.PI * theta/180.0), y1 + rayon * Math.sin(Math.PI * theta/180.0));
context.stroke();
}
};
imagePaper.src = "png/dark/roundabout_arrow.png";
// dessins des intersections à laisser
}
// Fonctions de dessin des giratoires
function drawlines(canvas, context,a){
// dessins des sorties (a) à laisser
context.beginPath();
context.lineWidth=5;
var x1 = 100 ;
var y1 = 100 ;
var r = 25;
var offset = 40 ;
a.forEach(function(element) {
theta = element - 90 ; // up north
context.moveTo(x1 + offset * Math.cos(Math.PI * theta / 180.0), y1 + offset * Math.sin(Math.PI * theta / 180.0));
context.lineTo(x1 + (offset+r) * Math.cos(Math.PI * theta / 180.0), y1 + (offset+r) * Math.sin(Math.PI * theta / 180.0));
context.stroke();
});
}
function drawarrow(canvas, context, onload,ang){
var imagePaper = new Image();
imagePaper.onload = function(){
// dessin de la flèche avec le bon angle
context.save() ;
context.translate(100,100) ;
context.rotate (Math.PI * ang / 180.0) ;
context.drawImage(imagePaper,-100, -100);
context.restore() ;
// dessin de la portion de rond point à parcourir
context.lineWidth=10;
context.beginPath();
context.arc(100,100,35,Math.PI * (ang-90) / 180.0, 0.5*Math.PI);
context.stroke();
// appel du dessin des sorties à laisser
//onload(canvas, context,a);
};
imagePaper.src = "png/dark/roundabout_arrow.png";
}
function drawbackground(canvas, context, onload,ang){
// Dessin du rond point de base
var imagePaper = new Image();
imagePaper.onload = function(){
context.drawImage(imagePaper,0, 0);
// appel du dessin de la flèche de sortie qui appellera les sorties à laisser
drawarrow(canvas,context,drawlines,ang) ;
};
imagePaper.src = "png/dark/roundabout_base.png";
}
function drawimg(canvas, context, imurl){
// Dessin du rond point de base
var imagePaper = new Image();
imagePaper.onload = function(){
context.drawImage(imagePaper,0, 0);
};
imagePaper.src = imurl;
}
// use the coordinates you just drew to make your directions request
function updateRoute() {
removeRoute(); // overwrite any existing layers
var data = draw.getAll();
var answer = document.getElementById('calculated-line');
var lastFeature = data.features.length - 1;
var coords = data.features[lastFeature].geometry.coordinates;
var newCoords = coords.join(';')
getMatch(newCoords);
}
// make a directions request
function getMatch(e) {
//Cleaning up linestrings
var features = draw.getAll();
// Keeping only last linestring
removed = features.features.splice(0,features.features.length-1) ;
draw.set(features) ;
// get mode_transport
var mode_transport = document.getElementById('mode_form').elements['mode_transport'].value ;
if (mode_transport == 'velo') {
var url = 'https://api.mapbox.com/directions/v5/mapbox/cycling/'
} else if ( mode_transport == 'piéton') {
var url = 'https://api.mapbox.com/directions/v5/mapbox/walking/'
} else { var url = 'https://api.mapbox.com/directions/v5/mapbox/driving/' };
// get transport options
transport_options = document.getElementById('options_form').elements['transport_options'].value ;
if (mode_transport == 'piéton') {
var exclusions = '' ;
} else if (mode_transport == 'velo') {
if (transport_options == 'no_limit') { var exclusions = '' } else { var exclusions = '&exclude=ferry' }
} else {
if (transport_options == 'no_limit') { var exclusions = '' } else { var exclusions = '&exclude='+transport_options; }
};
url = url + e +'?geometries=geojson&steps=true&overview=full' + exclusions + '&language=fr&access_token=' + mapboxgl.accessToken;
myDirections = e ;
//console.log(myPoints) ;
var req = new XMLHttpRequest();
req.responseType = 'json';
req.open('GET', url, true);
req.onload = function() {
var jsonResponse = req.response;
var distance = jsonResponse.routes[0].distance*0.001;
var duration = jsonResponse.routes[0].duration/60;
// Début du traitement pour le roadbook
var legs = jsonResponse.routes[0].legs
var nb_cases = 0 ;
var nb_intersections = 0 ;
var nb_all_intersections = 0 ;
// Nb de cases
legs.forEach(function(leg) {
var steps = leg.steps;
steps.forEach(function(step){
nb_cases = nb_cases + 1 ;
var intersections = step.intersections;
intersections.forEach(function(intersection){
var entries = intersection.entry ;
var bearings = intersection.bearings ;
try {
var b_in = intersection.in ;
}
catch(err) {
var b_in = intersection.out ;
} ;
try {
var b_out = intersection.out ;
}
catch(err) {
var b_out = intersection.in ;
} ;
var nb_right = 0 ;
var nb_left = 0 ;
var all_right = 0 ;
var all_left = 0 ;
var delta_b = (bearings[b_in] - bearings[b_out] + 360 ) % 360 ;
for (b = 0; b < bearings.length; b++) {
var d = (bearings[b] - bearings[b_out] + 360 ) % 360 ;
if (d < delta_b & d > 0) {
all_right = all_right + 1 ;
if (entries[b]) {
nb_right = nb_right + 1 ;
}
}
else if (d > delta_b) {
all_left = all_left + 1 ;
if (entries[b]) {
nb_left = nb_left + 1 ;
}
} ;
} ;
if (all_left+all_right > 0) { nb_all_intersections = nb_all_intersections + 1 } ;
if (nb_left+nb_right > 0) { nb_intersections = nb_intersections + 1 } ;
})
})
}) ;
// Préparation des tableaux
// format RB
var instructions = document.getElementById('instructable').getElementsByTagName('tbody')[0];
new_row = instructions.insertRow(0)
new_row.insertAdjacentHTML('beforeend','<div class="html2pdf__page-break"></div>');
for (i=0;i<nb_cases;i++) {
new_row = instructions.insertRow(0) ;
new_row.insertAdjacentHTML('beforeend','<td width=100px><div id="numero_'+i+'" class="numero"></div><div id="total_distance_'+i+'" class="total_distance"></div><div class="space_distance"></div><div id="partial_'+i+'" class="partial_distance"></div></td>');
new_row.insertAdjacentHTML('beforeend','<td width=100px><div width=100 height=100 style="width:100px;height:100px"><canvas id="myCanvas_' +i+ '" width=200 height=200 style="width:100px;height:100px;position: relative; left: 0; top: 0;"></canvas></td>');
new_row.insertAdjacentHTML('beforeend','<td width=180px><div id="instruction_'+i+'" class="instruction"></div><div class="space_distance"></div><div id="route_'+i+'" class="route"></div></td>');
new_row = instructions.insertRow(0)
new_row.insertAdjacentHTML('beforeend','<div class="html2pdf__page-break"></div>');
} ;