forked from mountyzilla/mountyzilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trajet_canvas.user.js
2742 lines (2631 loc) · 99.5 KB
/
trajet_canvas.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 Trajet des gowap MkII
// @namespace http://feldspath.free.fr/
// @include */mountyhall/MH_Play/Play_e_follo.php*
// @include */mountyhall/MH_Play/Play_a_Action.php*
// @include */mountyhall/MH_Play/Play_a_ActionResult.php*
// @include */mountyhall/MH_Play/Play_vue.php*
// @include */mountyhall/MH_Lieux/Lieu_Description.php*
// @downloadURL https://greasyfork.org/scripts/23887-trajet-des-gowap-mkii/code/Trajet%20des%20gowap%20MkII.user.js
// @version 2.39
// @description Trajet des gowaps
// @grant GM_getValue
// @grant GM_setValue
// @injectframes 1
// ==/UserScript==
// À faire
// tenir compte de la profondeur pour la détection des collisions gowap-trou (voir calc_inter())
// réécrire en mode objet
//var MY_DEBUG = true;
try { // ajout par Vapulabehemot (82169) le 30/08/2013
var ie = (window.attachEvent)? true:false;
if("function" != typeof isPage) {
function isPage(url) {
return window.location.pathname.indexOf("/mountyhall/"+url) == 0;
}
}
if("function" != typeof isPageWithParam) {
function isPageWithParam(filters) {
if (filters.url && window.location.pathname.indexOf(`/mountyhall/${filters.url}`) != 0) return false;
if (filters.body_id && document.body.id != filters.body_id) return false;
if (filters.params) {
let paramsGET = new URLSearchParams(window.location.search);
for (let param in filters.params)
if (paramsGET.get(param) != filters.params[param]) return false;
}
if (filters.ids)
for (let id of filters.ids)
if (!document.getElementById(id)) return false
if (filters.names)
for (let name of filters.names)
if (document.getElementsByName(name).length == 0) return false
return true;
}
}
if("function" != typeof MY_getValue) {
//if(typeof localStorage == "object") {
if(typeof window.localStorage == "object") { // correction par Vapulabehemot (82169) le 14/01/2015
function MY_getValue(nom) {
//return localStorage.getItem(nom);
return window.localStorage.getItem(nom); // correction par Vapulabehemot (82169) le 14/01/2015
}
function MY_setValue(nom,valeur) {
//localStorage.setItem(nom,valeur);
window.localStorage.setItem(nom,valeur); // correction par Vapulabehemot (82169) le 14/01/2015
}
//if(window.localStorage.getItem("favori_gow") === null && "function" == typeof GM_getValue && GM_getValue("favori_gow")) window.localStorage.setItem("favori_gow", GM_getValue("favori_gow"));
if(window.localStorage.getItem("favori_gow") === null && "function" == typeof GM_getValue && GM_getValue("favori_gow")) window.localStorage.setItem("favori_gow", GM_getValue("favori_gow")); // correction par Vapulabehemot (82169) le 14/01/2015
}
else if("function" == typeof GM_getValue) {
function MY_getValue(nom) {
return GM_getValue(nom);
}
function MY_setValue(nom,valeur) {
GM_setValue(nom,valeur);
}
}
else if("function" == typeof PRO_getValue) {
function MY_getValue(nom) {
return PRO_getValue(nom);
}
function MY_setValue(nom,valeur) {
PRO_setValue(nom,valeur);
}
}
else {
function MY_getValue(nom) {
var dc = document.cookie;
var prefix = nom + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return "";
}
else
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}
function MY_setValue(nom,valeur) {
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
var curCookie = nom + "=" + escape(valeur) + "; expires="+expdate.toGMTString();
document.cookie = curCookie;
}
}
}
if ("function" != typeof addEvent) {
if (ie) {
function addEvent(obj, typ, fn, sens) {
obj["e"+typ+fn] = fn; obj[typ+fn] = function() {
obj["e"+typ+fn]( window.event );
}
obj.attachEvent("on"+typ, obj[typ+fn] );
}
}
else {
function addEvent(obj, typ, fn, sens) {
obj.addEventListener(typ, fn, sens);
}
}
}
var lien = window.self.location.toString();
var MZ_fo_ordres = isPageWithParam({url: 'MH_Play/Play_a_Action', ids:['t_fo_ordre']});
var MZ_fo_profil = isPageWithParam({url: 'MH_Play/Play_a_Action', ids:['t_fo_profil']});
var MZ_fo_newordre = isPageWithParam({url: 'MH_Play/Play_a_Action', names:['gus_ordre', 'type', 'id_target']});
//console.log('trajet MZ_fo_newordre=' + MZ_fo_newordre);
var page = "";
if(MZ_fo_ordres) {
page = "trajet";
}
else if(lien.indexOf("/mountyhall/MH_Play/Play_e_follo.php") != -1) {
page = "suivants";
}
else if(MZ_fo_profil) {
page = "profil_gow";
}
else if((lien.indexOf("/mountyhall/MH_Play/Play_a_Action.php") != -1)
&& (lien.indexOf("id=-3") != -1)
&& (window.document.getElementsByTagName("body")[0].innerHTML.indexOf("Portail de T") != -1)) {
console.log('trajet lieu_tp');
var sortie = null;
var page = "lieu_tp";
}
else if(MZ_fo_newordre) {
page = "action_ordre";
}
else if(lien.indexOf("/mountyhall/MH_Play/Play_vue.php") != -1) {
// else if(true) {
function aj_fav_gow() {
var pt, x2, y2, n2;
pt = this.parentNode.parentNode.childNodes[3].innerHTML.split("_");
x2 = parseInt(pt[2]);
y2 = parseInt(pt[3]);
n2 = parseInt(pt[4]);
var maintenant = new Date();
if(!MY_getValue("favori_gow")) {
MY_setValue("favori_gow", "vue-"+maintenant.getDate()+"-"+(maintenant.getMonth()+1)+"-"+maintenant.getFullYear()+"/"+x2+"/"+y2+"/"+n2+"/");
}
else {
var texte = MY_getValue("favori_gow");
var param = texte.split("/");
var nb_fav = Math.floor(param.length/4);
if (param.length > 3) {
for (var i=0; i<nb_fav; i++) {
if(parseInt(param[4*i+1]) == x2 && parseInt(param[4*i+2]) == y2 && parseInt(param[4*i+3]) == n2) return;
}
}
MY_setValue("favori_gow", texte+"vue-"+maintenant.getDate()+"-"+(maintenant.getMonth()+1)+"-"+maintenant.getFullYear()+"/"+x2+"/"+y2+"/"+n2+"/");
}
document.getElementById("action_lieu").style.display = "none";
}
if(!document.getElementById("action_lieu")) {
var tableau_tete = new Array();
tableau_tete[1] = document.getElementById('VueMONSTRE');
tableau_tete[2] = document.getElementById('VueTROLL');
tableau_tete[3] = document.getElementById('VueTRESOR');
tableau_tete[4] = document.getElementById('VueCHAMPIGNON');
tableau_tete[5] = document.getElementById('VueLIEU');
tableau_tete[6] = document.getElementById('VueCADAVRE');
function prepare_click(num) {
if(!tableau_tete[num]) return;
if ( !tableau_tete[num].getElementsByTagName("tbody")[0] ) return; // ajout par Vapulabehemot (82169) le 10/07/2015
var tableau = tableau_tete[num].getElementsByTagName("tbody")[0].getElementsByTagName("tr");
var nb = tableau.length;
//if(nb > 1) {
if(nb > 0) { // correction par Vapulabehemot (82169) le 10/07/2015
//debut = (tableau[i].firstChild.getElementsByTagName("input").length > 0)? 0:1; // suppression par Vapulabehemot (82169) le 30/08/2013 (la variable "i" n'existe pas)
//for (var i = 1; i < nb; i++) {
for (var i = 0; i < nb; i++) { // correction par Vapulabehemot (82169) le 10/07/2015
//addEvent(tableau[i].childNodes[debut], "click", function(event) { affiche_action(this, event); }, true);
addEvent(tableau[i].childNodes[0], "click", function(event) { affiche_action(this, event); }, true); // correction par Vapulabehemot (82169) le 30/08/2013
//tableau[i].childNodes[debut].style.cursor = "pointer";
tableau[i].childNodes[0].style.cursor = "pointer"; // correction par Vapulabehemot (82169) le 30/08/2013
//tableau[i].childNodes[debut].id = num+"_"+i+"_";
tableau[i].childNodes[0].id = num+"_"+i+"_"; // correction par Vapulabehemot (82169) le 30/08/2013
}
}
}
function affiche_action(cible, evt) {
var ligne = cible.parentNode;
var nb = ligne.childNodes.length;
var ref = cible.id+ligne.childNodes[nb-3].innerHTML+"_"+ligne.childNodes[nb-2].innerHTML+"_"+ligne.childNodes[nb-1].innerHTML;
var cadre = document.getElementById("action_lieu");
if (cadre.style.display == "none" || document.getElementById("action_coord").innerHTML != ref) {
document.getElementById("action_coord").innerHTML = ref;
cadre.style.display = "block";
cadre.style.left = evt.clientX;
cadre.style.top = (evt.clientY + (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0) - 20);
}
else {
cadre.style.display = "none";
}
}
var nvdiv = document.createElement("div");
nvdiv.id = "action_lieu";
nvdiv.className = "mh_tdtitre";
nvdiv.style.display = "none";
nvdiv.style.position = "absolute";
nvdiv.style.padding = "1px";
nvdiv.style.border = "1px solid";
nvdiv.appendChild(document.createElement("span"));
nvdiv.appendChild(document.createElement("span"));
nvdiv.appendChild(document.createElement("span"));
var nvsp = document.createElement("span");
nvsp.id = "action_coord"
nvsp.style.display = "none";
nvdiv.appendChild(nvsp);
document.body.appendChild(nvdiv);
for(var i=1; i<7; i++) {
prepare_click(i);
}
}
var imag = document.createElement("img");
imag.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMAgMAAAArG7R0AAAAAXNSR0IArs4c6QAAAAlQTFRFXAByVA0Lyqp4QnItCgAAAAF0Uk5TAEDm2GYAAAABYktHRACIBR1IAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH2wcTCTMHIX+pMQAAAC9JREFUCNdjYACBUAaGwFWuDGGrpjJIZqYwSGUuYZBaBcShSxjYVk0AY8ZVDiB1AP9ZC3P9zCaoAAAAAElFTkSuQmCC";
imag.style.cursor = "pointer";
imag.id = "avec_gowap";
imag.title = "Ajouter une destination gowap";
addEvent(imag, "click", aj_fav_gow, true);
document.getElementById("action_lieu").childNodes[2].appendChild(imag);
}
if(page) {
function aj_opt(ref,desc,val) {
nvspan = aligne();
choix = document.createElement("input");
choix.id = ref;
choix.type = "checkbox";
choix.checked = val;
choix.title = desc;
etik = document.createElement("label");
etik.appendChild(document.createTextNode(desc));
etik.htmlFor = ref;
nvspan.appendChild(choix);
nvspan.appendChild(etik);
return nvspan;
}
function bloc(ref) {
nvdiv = document.createElement("div");
nvdiv.id = ref;
return nvdiv;
}
function enligne(ref) {
nvspan = document.createElement("span");
nvspan.id = ref;
return nvspan;
}
function aligne() {
nspan = document.createElement("span");
nspan.className = "aligne";
return nspan;
}
function aj_entree(ref,val) {
entree = document.createElement("input");
entree.id = ref;
entree.name = ref;
entree.className = "TextboxV2";
entree.size = "5";
entree.value = val;
addEvent(entree, "keyup", modifier_coord, true);
addEvent(entree, "change", modifier_coord, true);
addEvent(entree, "click", action_trajet, true);
return entree;
}
function get_opt(ref) {
val = document.getElementById(ref).value;
if(!val) {
val = 0;
}
else {
val = (isNaN(val))? 0:parseInt(val);
}
return val;
}
function set_opt(ref,val) {
document.getElementById(ref).value = val;
}
function inserer_tableau(tablo,rg,elt) {
tablo.splice(rg, 0, elt);
}
function effacer_tableau(tablo,rg) {
tablo.splice(rg,1);
}
function creer_canvas(ref) {
var dessin = document.createElement("canvas");
dessin.id = ref;
return dessin;
}
function creer_icone(lx, ly, desc, clique) {
var dessin = document.createElement("canvas");
dessin.width = lx;
dessin.height = ly;
dessin.className = "a_cliquer";
dessin.title = desc;
addEvent(dessin, "click", clique, true);
return dessin;
}
function dessine_svg(trace, chemin) {
for(var i in chemin) {
if(chemin[i][0] == 0) {
trace.moveTo(chemin[i][1], chemin[i][2]);
}
else if(chemin[i][0] == 1) {
trace.lineTo(chemin[i][1], chemin[i][2]);
}
else if(chemin[i][0] == 2) {
trace.bezierCurveTo(chemin[i][1],chemin[i][2], chemin[i][3],chemin[i][4], chemin[i][5],chemin[i][6]);
}
else if(chemin[i][0] == 3) {
trace.arc(chemin[i][1], chemin[i][2], chemin[i][3], 0, Math.PI*2, true);
}
}
}
function creer_glissiere(ref, val) {
var div_gliss = bloc("choix_zoom_"+ref);
div_gliss.appendChild(document.createTextNode("Zoom : "));
div_gliss.className = "choix_zoom";
dessin = creer_canvas("glissiere_"+ref);
dessin.width = 104;
dessin.height = 12;
addEvent(dessin, "mousedown", ini_glisse, true);
addEvent(dessin, "mousemove", sur_curseur, true);
if (ref != 'fav') { // ajout par Vapulabehemot (82169) le 10/07/2015
addEvent(dessin, "mouseup", drop, true); // ajout par Vapulabehemot (82169) le 10/07/2015
addEvent(dessin, "mousemove", glisse, true); // ajout par Vapulabehemot (82169) le 10/07/2015
} // ajout par Vapulabehemot (82169) le 10/07/2015
addEvent(dessin, "mouseout", function() { haut.getElementById("bulle_zoom").style.visibility="hidden" }, true);
addEvent(dessin, "mouseover", function() { haut.getElementById("bulle_zoom").style.visibility="visible" }, true);
div_gliss.appendChild(dessin);
div_gliss.appendChild(enligne("val_zoom_"+ref));
div_gliss.lastChild.innerHTML = val+"%";
creer_bulle_zoom();
return div_gliss;
}
function dessine_glissiere(ref, val) {
dessin = haut.getElementById("glissiere_"+ref);
if (dessin.getContext){
var ctx = dessin.getContext('2d');
ctx.clearRect(0, 0,104, 12);
ctx.fillStyle = "rgb(0,0,0)";
ctx.fillRect(0,0,2,12);
ctx.fillRect(102,0,2,12);
ctx.fillRect(0,5,104,2);
ctx.fillStyle = "rgb(80,80,80)";
ctx.fillRect(val,0,5,12);
ctx.fillStyle = "rgb(200,200,200)";
ctx.fillRect(val+1,1,3,10);
}
}
function coord_x(val) {
return decalh+TC_coeff*(val+100);
}
function coord_y(val) {
return decalv+TC_coeff*(100-val);
}
function creer_bulle_trajet() {
if(haut.getElementById("bulle_trajet")) {
bulle = haut.getElementById("bulle_trajet");
return;
}
haut.body.appendChild(bloc("bulle_trajet"));
bulle = haut.getElementById("bulle_trajet");
bulle.className = "mh_tdtitre";
nvdiv = bloc("mobile_bulleVue");
nvdiv.className = "bulle_haut_gow";
nvdiv.appendChild(enligne("bulle_haut_gow"));
bulle.appendChild(nvdiv);
bulle.appendChild(bloc("bulle_desc_gow"));
bulle.lastChild.className = "mh_tdpage";
}
function declare_css() {
if(haut.getElementById("css_gow")) return;
css = "#carte_trajet { position: relative; text-align: left; }\ndiv#carte_gowap, #MZ_carte_cartegogo { display: none; }\ndiv.mh_tdpage#cadre_liste, div.mh_tdpage#bulle_desc_gow { display: block !important; }\n#trou, #trajet, #surligne, #danger, #cadre_liste {\n position: absolute;\n top: 0px;\n left: 0px;\n}\n#cadre_liste {\n padding: 10px 20px 5px 10px;\n}\n.etape {\n width: 100%;\n border: 1px solid #000;\n padding: 1px 5px 1px 5px;\n margin: -1px 0px 0px 0px;\n}\nlabel {\n cursor: pointer;\n}\n.etape_surlignee {\n width: 100%;\n border : 2px solid #ff2222;\n padding: 1px 5px 0px 5px;\n margin: -2px -1px -1px -1px;\n}\n.etape canvas, .etape_surlignee canvas {\n position: relative; float: right;\n margin-left:10px; margin-right: -3px; margin-top : 2px;\n}\n.a_cliquer {\n cursor: pointer;\n}\n#aj_noeud { cursor : pointer; }\n#trou_fav, #trace_fav { position: absolute; top: 20px; left: 0px; }\n.choix_zoom { position: relative; margin-left:30px; margin-top:3px; }\n#glissiere_gow, #glissiere_fav { position: relative; }\n\n#bulle_trajet { \n visibility:hidden;\n position:absolute; z-index:3100;\n width:400px;\n border-width:1px; border-style:solid; border-color:#a1927f;\n}\n#mobile_bulleVue { cursor:move; }\n.bulle_haut { font-weight:bold; text-align:left; padding:2px; }\n#bulle_desc_gow { font-size:11px; padding:2px; white-space: nowrap;}\n\n#gestion_fav_gow { position:absolute; padding: 1px; border-with:1px; border-style:solid; min-width:300px; z-index:3000; }\n#titre_gow, .fav, .fav_dessus { min-height:15px; }\n.fav { margin:0; margin:0 0 -1px 0; padding: 1px 1px 1px 1px; border : 1px solid #a1927f; }\n.fav_dessus { margin:-1px; margin:-1px -1px -2px -1px; padding: 0px 1px 0px 1px; border : 2px solid #a1927f; }\n#gestion_fav_gow .a_cliquer { position: relative; float: right; margin-left: 2px; }\n#gestion_fav_gow { display: block !important; }\n#cadre_fav { position: relative; }\n#bulle_zoom { display:block !important; visibility: hidden; position: absolute; z-index: 3500; border : 1px solid #a1927f; }";
var node = document.createElement("style");
node.type = "text/css";
node.id = "css_gow";
node.appendChild(document.createTextNode(css));
haut.getElementsByTagName("head")[0].appendChild(node);
}
function bouton(ref,desc) {
entree = document.createElement("input");
entree.type = "button"
entree.id = ref;
entree.value = desc;
entree.className = "mh_form_submit";
return entree;
}
function trim(str) {
return str.replace(/(^\s*)|(\s*$)/g,"");
}
////////////////////////////////////////////////////////////
function charge_trajet() {
let data_gowap = MY_getValue("TRAJET_"+num_gow);
if(!data_gowap) {
//console.log('trajet_canvas pas de trajet pour suivant ' + num_gow);
return;
}
let param = data_gowap.split("/");
//window.console.log('charge_trajet TRAJET_' + num_gow + '=' + MY_getValue("TRAJET_"+num_gow) + ', on va splitter sur /');
if(param[0] != "zoom") {
console.log('trajet_canvas pas zoom en début de trajet pour suivant ' + num_gow);
return;
}
zoom = parseInt(param[1]);
if (isNaN(zoom)) zoom = 100;
TC_coeff = zoom/50.0; // ajout par Vapulabehemot (82169) le 10/07/2015
//window.console.log('charge_trajet ' + num_gow + ' ' + param.join('/') + ', zoom=' + zoom + ', TC_coeff=' + TC_coeff);
typ_gow = parseInt(param[3]);
if (typ_gow == 2) typ_gow = 3;
dla = parseInt(param[5]);
let coord = param[7].split(",");
etapes_ini = new Array();
if(coord.length > 1) {
nb_ini = Math.floor(coord.length/3);
for(var i = 0; i<nb_ini; i++) {
etapes_ini.push([parseInt(coord[3*i]), parseInt(coord[3*i+1]), parseInt(coord[3*i+2]), coord[3*i].match(/^\d+e$/g) !== null]);
}
}
etapes = new Array();
coord = param[9].split(",");
if(coord.length > 1) {
nb_coord = Math.floor(coord.length/3);
for(var i = 0; i<nb_coord; i++) {
etapes.push([parseInt(coord[3*i]), parseInt(coord[3*i+1]), parseInt(coord[3*i+2])]);
}
}
else {
choix_ini = true;
}
if(param.length > 10) {
param = param[11].split(",");
if(param.length > 1) {
nb_a = Math.floor(param.length/2);
for(var i=0; i<nb_a; i++) {
arret.push([parseInt(param[2*i]), parseInt(param[2*i+1])]);
}
}
else {
arret = [[-1, parseInt(param[0])]];
}
}
else {
arret = [[-1, etapes.length]];
}
//if (num_gow == 5813233) window.console.log('trajet_canvas charge_trajet pour suivant ' + num_gow + '\netapes_ini=' + JSON.stringify(etapes_ini) + '\netapes=' + JSON.stringify(etapes) + '\narret=' + JSON.stringify(arret));
}
function sauve_trajet() {
let param = "zoom/"+zoom+"/typ_gow/"+typ_gow+"/dla/"+dla+"/t_enreg/";
for(var i = 0; i<etapes_ini.length; i++) {
param += etapes_ini[i][0]+(etapes_ini[i][3]? "e":"")+","+etapes_ini[i][1]+","+etapes_ini[i][2]+",";
}
param += "/t_prev/";
for(var i = 0; i<nb_ajout; i++) {
param += etapes[i][0]+","+etapes[i][1]+","+etapes[i][2]+",";
}
param += "/arret/"
for(var i in arret) {
param += arret[i][0]+","+arret[i][1]+",";
}
//window.console.log('sauve_trajet ' + num_gow + ' ' + param);
MY_setValue("TRAJET_"+num_gow,param);
}
function charge_opt_position() {
if(MY_getValue("OPT_POSITION_GOWAP")) {
param = MY_getValue("OPT_POSITION_GOWAP").split("/");
zoom = parseInt(param[1]);
TC_coeff = zoom/50.0; // ajout par Vapulabehemot (82169) le 10/07/2015
//window.console.log('charge_opt_position ' + param.join('/') + ', zoom=' + zoom + ', TC_coeff=' + TC_coeff);
t_enreg = (param[3] == "1");
t_prev = (param[5] == "1");
}
}
function sauve_opt_position() {
MY_setValue("OPT_POSITION_GOWAP","zoom/"+zoom+"/t_enreg/"+(t_enreg? 1:0)+"/t_prev/"+(t_prev? 1:0));
}
////////////////////////////////////////////////////////////
function ini_canvas() {
trajet = bloc("carte_trajet");
dessin = creer_canvas("trou");
dessin.className = "mh_tdpage";
trajet.appendChild(dessin);
trajet.appendChild(creer_canvas("trajet"));
trajet.appendChild(creer_canvas("danger"));
dessin = creer_canvas("surligne");
addEvent(dessin, "click", action_trajet, true);
addEvent(dessin, "mousedown", start_v, true);
addEvent(dessin, "mousemove", afficher_position, true);
addEvent(dessin, "mouseout", function() { cacher_bulle(true) }, true);
addEvent(dessin, "mouseover", function() { cacher_bulle(false) }, true);
trajet.appendChild(dessin);
trajet.appendChild(creer_glissiere("gow", zoom));
cadre_liste = bloc("cadre_liste");
cadre_liste.className = "mh_tdpage";
//cadre_liste.style.display = 'none';
cadre_liste.appendChild(bloc("liste_etapes"));
cadre_liste.appendChild(document.createElement("br"));
cadre_liste.appendChild(document.createTextNode("Type de gowap : "));
etik = ["Rapide", "Normal", "Lent"]; val = [6, 4, 3];
sel = document.createElement('select');
sel.name = "selgow";
sel.id = "selgow";
for(var i=0; i<etik.length; i++) {
option=document.createElement('option');
option.value = val[i];
option.appendChild(document.createTextNode(etik[i]));
sel.appendChild(option);
}
sel.value = typ_gow;
addEvent(sel, "keyup", change_gow, true);
addEvent(sel, "change", change_gow, true);
cadre_liste.appendChild(sel);
nvdiv = bloc("ligne_fav");
choix = document.createElement("select");
choix.id = "sel_fav";
addEvent(choix, "mouseover", surligne_fav, true);
addEvent(choix, "mouseout", efface_surligne, true);
nvdiv.appendChild(choix);
dessin = dessine_plus();
addEvent(dessin, "click", inserer_fav, true);
nvdiv.appendChild(dessin);
dessin = dessin = creer_icone(21, 21, "Gérer les destinations favorites", ini_gestion);
if (dessin.getContext){
var ctx = dessin.getContext('2d');
ctx.strokeStyle = "rgb(50,50,50)";
ctx.fillStyle = "rgb(220,220,220)";
ctx.lineWidth = "1";
dessine_svg(ctx, data_svg["param"]);
ctx.stroke();
ctx.fill();
}
dessin.style.verticalAlign = "text-bottom";
nvdiv.appendChild(dessin);
cadre_liste.appendChild(nvdiv);
cadre_liste.appendChild(bloc("inserer_etape"));
aj = bouton("aj_etape", "Ajouter une étape ");
addEvent(aj, "click", alterne_ajout, true);
cadre_liste.appendChild(aj);
if(nb_ini > 0) {
aj = bouton("raz_liste", "Initialiser");
addEvent(aj, "click", raz, true);
cadre_liste.appendChild(aj);
}
aj = bouton("eff_trajet", "Effacer tout");
addEvent(aj, "click", efface_trajet, true);
cadre_liste.appendChild(aj);
trajet.appendChild(cadre_liste);
let footer = document.getElementById('footer1');
footer.parentNode.insertBefore(trajet,footer);
}
function inserer_fav() {
ref = parseInt(document.getElementById("sel_fav").value);
if(ref == -2) return;
etapes[nb_ajout] = (ref == -1)? soi:[favori[ref][1], favori[ref][2], favori[ref][3]];
if(choix_ini) {
liste_etapes.innerHTML = "";
choix_ini = false;
liste_etapes.innerHTML = "";
liste_etapes.appendChild(aj_depart());
choix_ini = false;
}
if(!document.getElementById("etape_"+nb_ajout)) {
document.getElementById("liste_etapes").appendChild(aj_liste(nb_ajout, etapes[nb_ajout]));
if(nb_ajout > 0) {
document.getElementById("etape_"+(nb_ajout-1)).insertBefore(aj_descendre(nb_ajout-1), document.getElementById("etape_"+(nb_ajout-1)).getElementsByTagName("br")[0]);
}
}
nb_ajout++;
sauve_trajet();
prepare_inserer();
trace_trajet_prev();
}
function surligne_fav() {
if(page != "trajet") return;
var val = parseInt(this.value);
if(val == -2) return;
dessin = document.getElementById("surligne");
dessin.width = 200*TC_coeff+2*decalh;
dessin.height = 200*TC_coeff+2*decalv;
if(choix_ini) {
var debut = depart
}
else {
var debut = (nb_ajout > 0)? etapes[nb_ajout-1]:depart
}
trace_trajet(couleur_surligne, "surligne", debut, [(val == -1)? soi:[favori[val][1], favori[val][2], favori[val][3]]], true);
}
function change_gow() {
typ_gow = this.value;
calc_dist();
sauve_trajet();
}
function alterne_ajout() {
aj_noeud = !aj_noeud;
if(aj_noeud) {
document.getElementById("aj_etape").style.borderStyle = "inset";
if(nb_ajout == 0) {
etapes[nb_ajout] = depart;
}
else {
etapes[nb_ajout] = etapes[nb_ajout-1];
}
if(choix_ini) {
liste_etapes.innerHTML = "";
liste_etapes.appendChild(aj_depart());
choix_ini = false;
}
if(!document.getElementById("etape_"+nb_ajout)) {
document.getElementById("liste_etapes").appendChild(aj_liste( nb_ajout, etapes[nb_ajout]));
if(nb_ajout > 0) {
document.getElementById("etape_"+(nb_ajout-1)).insertBefore(aj_descendre(nb_ajout-1), document.getElementById("etape_"+(nb_ajout-1)).getElementsByTagName("br")[0]);
}
prepare_inserer();
}
}
else {
document.getElementById("aj_etape").style.borderStyle = "outset";
nb_ajout++;
sauve_trajet();
prepare_inserer();
trace_trajet_prev();
}
}
function trace_trou() {
document.getElementById("carte_trajet").style.height = (200*TC_coeff+2*decalv+10)+"px";
dessin = document.getElementById("trou");
dessin.width = 200*TC_coeff+2*decalh;
dessin.height = 200*TC_coeff+2*decalv;
if (dessin.getContext){
var ctx = dessin.getContext('2d');
//repere
ctx.beginPath();
dessine_svg(ctx, [[0,100*TC_coeff+decalh, decalv], [1,100*TC_coeff+decalh, 200*TC_coeff+decalv], [0,decalh, 100*TC_coeff+decalv], [1,200*TC_coeff+decalh, 100*TC_coeff+decalv]]);
ctx.stroke();
ctx.strokeRect(decalh, decalv, TC_coeff*200, TC_coeff*200);
//trous
ctx.fillStyle = couleur_trou;
for(var i in position_trous) {
ctx.beginPath();
ctx.arc(coord_x(position_trous[i][0]), coord_y(position_trous[i][1]), TC_coeff*position_trous[i][3], 0, Math.PI*2, true);
ctx.fill();
}
}
}
function trace_trou_fav() {
dessin = haut.getElementById("trou_fav");
dessin.width = 200*TC_coeff+2*decalh;
dessin.height = 200*TC_coeff+2*decalv;
if (dessin.getContext){
var ctx = dessin.getContext('2d');
//repere
ctx.beginPath();
ctx.moveTo(100*TC_coeff+decalh, decalv);
ctx.lineTo(100*TC_coeff+decalh, 200*TC_coeff+decalv);
ctx.moveTo(decalh, 100*TC_coeff+decalv);
ctx.lineTo(200*TC_coeff+decalh, 100*TC_coeff+decalv);
ctx.stroke();
ctx.strokeRect(decalh, decalv, TC_coeff*200, TC_coeff*200);
//trous
ctx.fillStyle = "rgb(200,0,0)";
for(var i in position_trous) {
ctx.beginPath();
ctx.arc(coord_x(position_trous[i][0]), coord_y(position_trous[i][1]), TC_coeff*position_trous[i][3], 0, Math.PI*2, true);
ctx.fill();
}
}
}
function trace_position(pos) {
dessin = document.getElementById("trou");
if (dessin.getContext){
var ctx = dessin.getContext('2d');
ctx.strokeStyle = "rgba(0,0,0,0.6)";
ctx.lineWidth = 2;
ctx.beginPath();
dessine_svg(ctx, [[3,coord_x(pos[0]), coord_y(pos[1]), 8],[0,coord_x(pos[0])-8, coord_y(pos[1])],[1,coord_x(pos[0])+8, coord_y(pos[1])],[0,coord_x(pos[0]), coord_y(pos[1])-8],[1,coord_x(pos[0]), coord_y(pos[1])+8]]);
ctx.stroke();
}
}
function trace_sortie(pos) {
dessin = document.getElementById("trou");
if (dessin.getContext){
var ctx = dessin.getContext('2d');
ctx.strokeStyle = "rgba(0,0,0,0.6)";
ctx.lineWidth = 2;
ctx.strokeRect(coord_x(pos[0]-2.5), coord_y(pos[1]+2.5), 5*TC_coeff, 5*TC_coeff)
ctx.beginPath();
dessine_svg(ctx, [[0,coord_x(pos[0]-2.5), coord_y(pos[1])], [1,coord_x(pos[0]-2.5)+5*TC_coeff, coord_y(pos[1])], [0,coord_x(pos[0]), coord_y(pos[1]+2.5)], [1,coord_x(pos[0]), coord_y(pos[1]+2.5)+5*TC_coeff]]);
ctx.stroke();
}
}
function trace_trajet_prev() {
sauve_trajet();
if(choix_ini) {
dessin = document.getElementById("trajet");
dessin.width = 200*TC_coeff+2*decalh;
dessin.height = 200*TC_coeff+2*decalv;
}
else {
trace_trajet(couleur_prev, "trajet", depart, etapes, true);
}
calc_dist();
}
function trace_trajet(couleur, ou, ref, noeuds, refaire) {
var dessin = document.getElementById(ou);
var dx, dy, x_inter, y_inter;
if(refaire) {
dessin.width = 200*TC_coeff+2*decalh;
dessin.height = 200*TC_coeff+2*decalv;
}
var pts = [[ref[0], ref[1]]];
var nb_etape = noeuds.length;
if(nb_etape == 0) return;
for(var i=0; i< nb_etape; i++) {
if (!noeuds[i]) {
window.console.log('trace_trajet_log, noeuds vide pour i=' + i + ', noeuds=' + JSON.stringify(noeuds));
return; // Roule' 14/11/2018 protection
}
dx = noeuds[i][0] - ref[0];
dy = noeuds[i][1] - ref[1];
if(dx != 0 && dy != 0 && dx != dy) {
if (Math.abs(dx) < Math.abs(dy)) {
x_inter = noeuds[i][0];
y_inter = (dy<0)? ref[1]-Math.abs(dx):ref[1]+Math.abs(dx);
}
else {
x_inter = (dx>0)? ref[0]+Math.abs(dy):ref[0]-Math.abs(dy);
y_inter = noeuds[i][1];
}
pts.push([x_inter, y_inter]);
}
pts.push([noeuds[i][0], noeuds[i][1]]);
ref = noeuds[i];
}
if (dessin.getContext){
var ctx = dessin.getContext('2d');
ctx.lineWidth = TC_coeff;
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.strokeStyle = couleur;
ctx.beginPath();
var nb_pts = pts.length;
ctx.moveTo(coord_x(pts[0][0]), coord_y(pts[0][1]));
for (var i=1; i<nb_pts; i++) {
ctx.lineTo(coord_x(pts[i][0]), coord_y(pts[i][1]));
}
ctx.stroke();
ctx.fillStyle = couleur;
for (var i=0; i<nb_etape; i++) {
if(noeuds[i][3]) {
ctx.fillRect(coord_x(noeuds[i][0])-TC_coeff, coord_y(noeuds[i][1])-TC_coeff, 2*TC_coeff, 2*TC_coeff);
}
else {
ctx.beginPath();
ctx.arc(coord_x(noeuds[i][0]), coord_y(noeuds[i][1]), TC_coeff, 0, Math.PI*2, true);
ctx.fill();
}
}
}
}
function trace_fav() {
TC_coeff = zoom_fav/50.0;
place_fav();
TC_coeff = zoom/50.0;
retrace_fav = false;
}
function place_fav() {
dessin = haut.getElementById("trace_fav");
dessin.width = 4*zoom_fav+2*decalh;
dessin.height = 4*zoom_fav+2*decalv;
if (nb_fav == 0) return;
if (dessin.getContext){
var ctx = dessin.getContext('2d');
var mini = favori[0][3], maxi = favori[0][3], couleur;
for (var i=1; i<nb_fav; i++) {
if(mini > favori[i][3]) mini = favori[i][3];
if(maxi < favori[i][3]) maxi = favori[i][3];
}
var delta = maxi-mini;
if(!delta) delta = 1;
for (var i=0; i<nb_fav; i++) {
trace_point(ctx, coord_x(favori[i][1]), coord_y(favori[i][2]), "rgb(50,"+(150-Math.round(100.0*(maxi-favori[i][3])/delta))+","+(50+Math.round(100.0*(maxi-favori[i][3])/delta))+")")
}
if(nv_pt !== null) {
trace_point(ctx, coord_x(nv_pt[0]), coord_y(nv_pt[1]), "rgba(0,0,0,0.5)")
}
}
}
function trace_point(trace, xx, yy, couleur) {
trace.strokeStyle = couleur;
trace.fillStyle = couleur;
trace.lineWidth = TC_coeff;
trace.beginPath();
trace.arc(xx, yy, TC_coeff, 0, Math.PI*2, true);
trace.fill();
trace.beginPath();
trace.arc(xx, yy, 3*TC_coeff, 0, Math.PI*2, true);
trace.stroke();
}
function trace_glissiere() {
dessine_glissiere("gow", Math.min(99,Math.max(0,Math.round(zoom/2.0)-25)));
if ( page == 'trajet' || page == 'lieu_tp' ) { // ajout par Vapulabehemot (82169) le 10/07/2015
document.getElementById('choix_zoom_gow').style.top = '4px'; // ajout par Vapulabehemot (82169) le 10/07/2015
} // ajout par Vapulabehemot (82169) le 10/07/2015
}
function trace_glissiere_fav() {
dessine_glissiere("fav", Math.min(99,Math.max(0,Math.round(zoom_fav/2.0)-25)));
}
function ini_glisse(evt) {
if(this.id == "glissiere_gow") {
xpage = (evt.offsetX)? evt.offsetX:evt.layerX;
zoom = Math.min(250,Math.max(50,(xpage+23.0)*2.0));
trace_glissiere();
document.getElementById("val_zoom_gow").innerHTML = zoom+"%";
TC_coeff = zoom/50.0;
//window.console.log('ini_glisse, xpage=' + xpage + ', zoom=' + zoom + ', TC_coeff=' + TC_coeff);
if(page == "trajet") {
echelle_trajet();
trace_trajet_prev();
sauve_trajet();
}
else if(page == "suivants") {
echelle_position();
sauve_opt_position();
}
else {
echelle_teleport();
}
glissable = true;
this.style.cursor = "e-resize";
}
if(this.id == "glissiere_fav") {
xpage = (evt.offsetX)? evt.offsetX:evt.layerX;
zoom_fav = Math.min(250,Math.max(50,(xpage+23.0)*2.0));
MY_setValue("zoom_fav", zoom_fav)
trace_glissiere_fav();
haut.getElementById("val_zoom_fav").innerHTML = zoom_fav+"%";
echelle_fav();
}
}
function sur_curseur(evt) {
if (evt.offsetX) {
xpage = evt.offsetX;
ypage = evt.offsetY;
xpos = evt.clientX;
ypos = evt.clientY + (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0);
}
else {
xpage = evt.layerX;
ypage = evt.layerY;
xpos = evt.pageX;
ypos = evt.pageY;
}
if(this.id == "glissiere_gow") {
curseur = Math.min(100,Math.max(0,Math.round(zoom/2.0)-25))+2;
this.style.cursor = (xpage <= (curseur+2) && xpage >= (curseur-2)) ? "e-resize":"pointer";
val = Math.min(250,Math.max(50,(xpage+23.0)*2.0))+"%";
}
else if(this.id == "glissiere_fav") {
this.style.cursor = "pointer"; // ajout par Vapulabehemot (82169) le 10/07/2015
val = Math.min(250,Math.max(50,(xpage+23.0)*2.0))+"%";
}
var bulle_zoom = haut.getElementById("bulle_zoom")
bulle_zoom.style.top = (ypos+3)+'px';
bulle_zoom.style.left = (xpos+16)+'px';
bulle_zoom.style.visibility = "visible";
bulle_zoom.innerHTML = val;
}
function glisse(evt) {
if(glissable) {
xpage = (evt.offsetX)? evt.offsetX:evt.layerX;
zoom = Math.min(250,Math.max(50,(xpage+23.0)*2.0));
trace_glissiere();
document.getElementById("val_zoom_gow").innerHTML = zoom+"%";
TC_coeff = zoom/50.0;
//window.console.log('glisse, xpage=' + xpage + ',zoom=' + zoom + ', TC_coeff=' + TC_coeff);
if(page == "trajet") {
echelle_trajet();
trace_trajet_prev();
sauve_trajet();
}
else if(page == "suivants") {
echelle_position();
sauve_opt_position();
}
else {
echelle_teleport();
}
}
}
function drop() {
glissable = false;
bougeable = false;
}
function action_trajet(evt) {
if(aj_noeud) {
aj_noeud = false;
nb_ajout++;
document.getElementById("aj_etape").style.borderStyle = "outset";
sauve_trajet();
prepare_inserer();
}
}
function afficher_position(evt) {
var xpage = 0, ypage = 0, xpos = 0, ypos = 0;
if (evt.offsetX) {
xpage = evt.offsetX;
ypage = evt.offsetY;
xpos = evt.clientX;
// https://stackoverflow.com/questions/28633221/document-body-scrolltop-firefox-returns-0-only-js
ypos = evt.clientY + (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0);
}
else {
xpage = evt.layerX;
ypage = evt.layerY;
xpos = evt.pageX;
ypos = evt.pageY;
}
xcase = Math.round((xpage-decalh)/TC_coeff-100.0);
ycase = Math.round(100.0-(ypage-decalv)/TC_coeff);
bulle.style.top = (ypos+8)+'px';
bulle.style.left = (xpos+16)+'px';
bulle.style.visibility = "visible";
document.getElementById("bulle_haut_gow").innerHTML = "x = "+Math.round(xcase)+", y = "+Math.round(ycase);
desc = document.getElementById("bulle_desc_gow");
desc.innerHTML = "";
for(var i in position_trous) {
dist = (xcase-position_trous[i][0])*(xcase-position_trous[i][0])+(ycase-position_trous[i][1])*(ycase-position_trous[i][1])-position_trous[i][2]
if(dist <= 0) {
desc.appendChild(document.createTextNode(" Trous de Météorite : n=-1 -> n="+position_trous[i][4]));
desc.appendChild(document.createElement("br"));
break;
}
}
document.getElementById("surligne").style.cursor = "";
if(aj_noeud) {
if(nb_ajout == 0) {
etapes[nb_ajout] = [xcase, ycase, depart[2]];
}
else {
etapes[nb_ajout] = [xcase, ycase, etapes[nb_ajout-1][2]];
}
deplace_noeud(nb_ajout, xcase, ycase);
trace_trajet_prev();
}
else if(bougeable) {
etapes[noeud_courant] = [xcase, ycase, etapes[noeud_courant][2]];
deplace_noeud(noeud_courant, xcase, ycase);
trace_trajet_prev();
}
else {
document.getElementById("etape_depart").className = "etape";
nb_liste = choix_ini? nb_tt:nb_ajout;
for (var i=0; i<nb_liste; i++) {
document.getElementById("etape_"+i).className = "etape";