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
|
<!DOCTYPE html>
<!-- Generated 01/10/2020 13:39:39 -->
<HTML>
<HEAD>
<TITLE>Graphe du réseau</TITLE>
<META charset="utf-8" />
<STYLE>
html, body { margin:0px; padding:0; }
#FormRechercheStation{
float:right;
color:#000000;
font:15px Arial;
font-weight:bold;
background:#00FF00;
border-style:none;
width:10%;
height:72px;
}
#PanneauBtnsVue{
float:right;
color:#000000;
font:15px Arial;
font-weight:bold;
background:#FFFF00;
border-style:none;
width:10%;
height:90px;
}
#PanneauShortestPath{
float:right;
color:#000000;
font:15px Arial;
font-weight:bold;
background:#FF00FF;
border-style:none;
width:10%;
height:130px;
}
#PanneauRoadMap{
float:right;
color:#000000;
font:15px Arial;
font-weight:bold;
background:#00FFFF;
border-style:none;
width:10%;
height:518px;
}
#MyPlan{
float:left;
width:90%;
height:810px;
border:0px;
margin:0px;
}
#MyCanvas2D{
float:left;
background-color:#FFFBF0;
border:1px solid black;
}
</STYLE>
<script type="text/javascript">
// D:\0_LogicielsJPC\0_GHTopoFPC\00000_GrapheJS_001.htm generated by GHTopo at 2020-10-01
// Les noeuds
function TJSGrapheNode(QIDNoeud, QX, QY, QZ, QListeVoisins)
{
this.IDNoeud = QIDNoeud;
this.X = QX;
this.Y = QY;
this.Z = QZ;
this.ListeVoisins = QListeVoisins;
} // TJSGrapheNode
//------------------------------------------------------------------
// La classe TJSGraphe
function TJSGraphe()
{
this.FListeNoeuds = new Array();
this.FShortestPath = new Array();
this.FXMini = 4034299
this.FYMini = 30895054
this.FXMaxi = 4035849
this.FYMaxi = 30896703
this.Init = function()
{
} // this.init
this.AddNoeud = function(QIDNoeud, QX, QY, QZ, QListeVoisins)
{
this.FListeNoeuds.push(new TJSGrapheNode(QIDNoeud, QX, QY, QZ, QListeVoisins));
this.FNbNoeuds = this.FListeNoeuds.length;
} // this.AddNoeud
this.GetNoeud = function(Index)
{
return this.FListeNoeuds[Index];
} // this.GetNoeud
this.GetNbNoeuds = function()
{
return this.FListeNoeuds.length;
} // this.GetNbNoeuds
this.FindIdxNoeudByCle = function(Cle)
{
var Nb = this.GetNbNoeuds()
if (0 == Nb) return -1;
for (var i = 0; i < Nb; i++)
{
if (this.FListeNoeuds[i].IDNoeud === Cle) return i;
}
return -1;
} // this.FindIdxNoeudByCle
//----------------------------------------------------------
// Le chemin
this.AddIdxNoeudAtPathFound = function(IdxNoeud)
{
// L'algo Dijkstra construit la liste des parcourus "à l'envers"
// aussi, l'ajout se fait en début de tableau"
this.FShortestPath.splice(0, 0, IdxNoeud);
// this.FShortestPath.push(IdxNoeud);
} // this.AddIdxNoeudAtPathFound
this.GetIdxNoeudOfPathFound = function(IdxNoeud)
{
return this.FShortestPath[IdxNoeud];
} // this.GetIdxNoeudOfPathFound
this.GetNbStationsOfPathFound = function()
{
return this.FShortestPath.length;
} // this.GetNbStationsOfPathFound
// Autres
this.GetXMini = function()
{
return this.FXMini;
}
this.GetYMini = function()
{
return this.FYMini;
}
this.GetXMaxi = function()
{
return this.FXMaxi;
}
this.GetYMaxi = function()
{
return this.FYMaxi;
}
this.GetYMaxi = function()
{
return this.FYMaxi;
}
this.DistanceBetweenNodes = function(IdxNoeudDep, IdxNoeudArr)
{
var ST1 = this.GetNoeud(IdxNoeudDep);
var ST2 = this.GetNoeud(IdxNoeudArr);
var dx = ST2.X - ST1.X;
var dy = ST2.Y - ST1.Y;
var QDist = Math.sqrt(dx * dx + dy * dy);
if (QDist < 0.01) return(0.01)
else return QDist; // sécurisation: aucun poids nul autorisé dans Dijkstra
} // this.DistanceBetweenNodes
// ---------------------------------------------------------------
// Algo de Dijkstra
this.Dijkstra = function(StationDepart, StationArrivee)
{
var IdxNoeudDep = this.FindIdxNoeudByCle(StationDepart);
var IdxNoeudArr = this.FindIdxNoeudByCle(StationArrivee);
console.log("Dijkstra: From " + StationDepart + " To " + StationArrivee);
console.log("Dijkstra: From " + IdxNoeudDep.toString() + " To " + IdxNoeudArr.toString());
if (IdxNoeudDep == -1) return -1;
if (IdxNoeudArr == -1) return -2;
if (IdxNoeudDep == IdxNoeudArr) return -3;
console.log("Dijkstra: 001");
this.FShortestPath = []; // vider le chemin le plus court
// Variables locales
var MyNode = null;
var MyNodeVoisin = null;
var QIdxVoisin = 0;
var NbVoisins = 0;
var QDistance = 0;
var NbNoeuds = this.GetNbNoeuds(); // Nombre de noeuds
// Liste des prédécesseurs
var ListePreds = new Array();
for (var i = 0; i < NbNoeuds ; i++) { ListePreds[i] = 0; }
// Liste des distances
var ListeDistances = new Array();
for (var i = 0; i < NbNoeuds ; i++) { ListeDistances[i] = Infinity; }
ListeDistances[IdxNoeudDep] = 0;
// Liste des déjà vus
var ListeNoeudsVisites = new Array();
for (var i = 0; i < NbNoeuds ; i++) { ListeNoeudsVisites[i] = false; }
// Retourne le nombre de noeuds visités
function NbNoeudsVisites()
{
Result = 0;
for (var i = 0; i < NbNoeuds ; i++) { if (ListeNoeudsVisites[i]) Result++; }
return Result;
} // function NbNoeudsVisites()
// Retourne le noeud le plus proche dans les noeuds non visités
function TrouveMin()
{
var Result = -1;
var DistMini = Infinity;
for (var i = 0; i < NbNoeuds ; i++)
{
if (!ListeNoeudsVisites[i])
{
if (ListeDistances[i] < DistMini)
{
DistMini = ListeDistances[i];
Result = i;
}
}
}
return Result;
} //function TrouveMin()
console.log("Entre dans le while du sujet")
// Boucle while principale
while (NbNoeudsVisites() < NbNoeuds)
{
console.log("Nb noeuds visites: " + NbNoeudsVisites().toString() + " sur " + NbNoeuds.toString());
var N1 = TrouveMin();
if (N1 == IdxNoeudArr) break;
ListeNoeudsVisites[N1] = true;
MyNode = this.GetNoeud(N1);
NbVoisins = MyNode.ListeVoisins.length;
if (NbVoisins > 0)
{
for (var k = 0; k < NbVoisins; k++)
{
QIdxVoisin = MyNode.ListeVoisins[k];
// fonction MajDistances() déroulée
var Poids = this.DistanceBetweenNodes(N1, QIdxVoisin);
if (ListeDistances[QIdxVoisin] > (ListeDistances[N1] + Poids))
{
ListeDistances[QIdxVoisin] = ListeDistances[N1] + Poids;
ListePreds[QIdxVoisin] = N1;
} // if (ListeDistances[QIdxVoisin] > (ListeDistances[N1] + Poids))
} //for (var k = 0; k < NbVoisins; k++)
} // if (NbVoisins > 0)
} // while (NbNoeudsVisites() < NbNoeuds)
// Et maintenant, on remonte
this.FShortestPath = [];
var N2 = IdxNoeudArr;
while (N2 != IdxNoeudDep)
{
this.AddIdxNoeudAtPathFound(N2);
N2 = ListePreds[N2];
} // while(N2 != IdxNoeudDep
console.log("Remontée terminée: " + this.GetNbStationsOfPathFound().toString() + " stations traversées");
} // this.Dijkstra
} // TJSGraphe
//===================================================================
// Variables globales
var GlobalFXMini = 0;
var GlobalFXMaxi = 0;
var GlobalFYMini = 0;
var GlobalFYMaxi = 0;
var GlobalFXCentreMap = 0;
var GlobalFYCentreMap = 0;
var GlobalFLastIdxFound = -1;
var JSGraphe = new TJSGraphe;
// Point d'entrée du programme
function Initialiser(St1, St2)
{
// Ajout des listeners
window.addEventListener("resize", ResizeCanvas, false);
// Ajout des 187 noeuds
JSGraphe.AddNoeud("1.0", 4034600, 30896000, 5400, [1]);
JSGraphe.AddNoeud("1.1", 4034699, 30896001, 5391, [0,2]);
JSGraphe.AddNoeud("1.2", 4034804, 30895999, 5389, [1,3,18]);
JSGraphe.AddNoeud("1.3", 4034804, 30895901, 5388, [2,4,35]);
JSGraphe.AddNoeud("1.4", 4034904, 30895903, 5390, [3,5]);
JSGraphe.AddNoeud("1.5", 4035004, 30895903, 5391, [4,6,22,20]);
JSGraphe.AddNoeud("1.6", 4035105, 30895904, 5391, [5,7]);
JSGraphe.AddNoeud("1.7", 4035205, 30895901, 5391, [6,8,28]);
JSGraphe.AddNoeud("1.8", 4035205, 30896000, 5392, [7,9,21]);
JSGraphe.AddNoeud("1.9", 4035306, 30895998, 5393, [8,10,29]);
JSGraphe.AddNoeud("1.10", 4035406, 30895997, 5394, [9,11,47]);
JSGraphe.AddNoeud("1.11", 4035421, 30896146, 5397, [10,12]);
JSGraphe.AddNoeud("1.12", 4035440, 30896295, 5400, [11,13]);
JSGraphe.AddNoeud("1.13", 4035467, 30896422, 5402, [12,14]);
JSGraphe.AddNoeud("1.14", 4035517, 30896531, 5404, [13,15]);
JSGraphe.AddNoeud("1.15", 4035503, 30896690, 5404, [14,16]);
JSGraphe.AddNoeud("1.16", 4035490, 30896697, 5404, [15,17]);
JSGraphe.AddNoeud("1.17", 4035461, 30896703, 5404, [16,17,17]);
JSGraphe.AddNoeud("2.1", 4034955, 30896000, 5387, [2,19]);
JSGraphe.AddNoeud("2.2", 4035004, 30896000, 5388, [18,20]);
JSGraphe.AddNoeud("2.3", 4035104, 30896001, 5390, [19,21,5]);
JSGraphe.AddNoeud("2.4", 4035205, 30896000, 5392, [20,8]);
JSGraphe.AddNoeud("3.1", 4035005, 30895855, 5393, [5,23]);
JSGraphe.AddNoeud("3.2", 4035003, 30895791, 5393, [22,24,27]);
JSGraphe.AddNoeud("3.3", 4035003, 30895692, 5394, [23,25,46]);
JSGraphe.AddNoeud("3.4", 4035208, 30895690, 5394, [24,26,77]);
JSGraphe.AddNoeud("3.5", 4035205, 30895791, 5393, [25,27,31]);
JSGraphe.AddNoeud("3.6", 4035003, 30895791, 5393, [26,23]);
JSGraphe.AddNoeud("4.1", 4035305, 30895896, 5393, [7,29,30]);
JSGraphe.AddNoeud("4.2", 4035306, 30895998, 5393, [28,9]);
JSGraphe.AddNoeud("5.1", 4035304, 30895794, 5391, [28,31]);
JSGraphe.AddNoeud("5.2", 4035205, 30895791, 5393, [30,26]);
JSGraphe.AddNoeud("7.0", 4034866, 30895610, 5408, [33,39,42]);
JSGraphe.AddNoeud("7.1", 4034801, 30895702, 5391, [32,34,38]);
JSGraphe.AddNoeud("7.2", 4034799, 30895801, 5394, [33,35,36]);
JSGraphe.AddNoeud("7.3", 4034804, 30895901, 5388, [34,3]);
JSGraphe.AddNoeud("8.1", 4034749, 30895802, 5394, [34,37]);
JSGraphe.AddNoeud("8.2", 4034750, 30895701, 5391, [36,38]);
JSGraphe.AddNoeud("8.3", 4034801, 30895702, 5391, [37,33]);
JSGraphe.AddNoeud("9.1", 4034788, 30895528, 5388, [32,40]);
JSGraphe.AddNoeud("9.2", 4034709, 30895447, 5368, [39,41]);
JSGraphe.AddNoeud("9.3", 4034615, 30895510, 5348, [40,41,41,55]);
JSGraphe.AddNoeud("10.1", 4034876, 30895630, 5408, [32,43]);
JSGraphe.AddNoeud("10.2", 4034893, 30895661, 5407, [42,44]);
JSGraphe.AddNoeud("10.3", 4034956, 30895674, 5401, [43,45]);
JSGraphe.AddNoeud("10.4", 4034998, 30895681, 5396, [44,46]);
JSGraphe.AddNoeud("10.5", 4035003, 30895692, 5394, [45,24]);
JSGraphe.AddNoeud("20.1", 4035407, 30895896, 5394, [10,48]);
JSGraphe.AddNoeud("20.2", 4035458, 30895847, 5394, [47,49]);
JSGraphe.AddNoeud("20.3", 4035558, 30895845, 5394, [48,50]);
JSGraphe.AddNoeud("20.4", 4035607, 30895896, 5394, [49,51]);
JSGraphe.AddNoeud("20.5", 4035609, 30895996, 5394, [50,52]);
JSGraphe.AddNoeud("20.6", 4035560, 30896047, 5394, [51,53]);
JSGraphe.AddNoeud("20.7", 4035460, 30896045, 5394, [52,54]);
JSGraphe.AddNoeud("20.8", 4035409, 30895996, 5394, [53,54,54]);
JSGraphe.AddNoeud("100.1", 4034537, 30895429, 5296, [41,56,59]);
JSGraphe.AddNoeud("100.2", 4034394, 30895363, 5256, [55,57]);
JSGraphe.AddNoeud("100.3", 4034366, 30895395, 5245, [56,58]);
JSGraphe.AddNoeud("100.4", 4034322, 30895402, 5238, [57,58,58]);
JSGraphe.AddNoeud("101.1", 4034631, 30895366, 5243, [55,60]);
JSGraphe.AddNoeud("101.2", 4034689, 30895340, 5227, [59,61,67]);
JSGraphe.AddNoeud("101.3", 4034764, 30895304, 5206, [60,61,61,97]);
JSGraphe.AddNoeud("110.1", 4035378, 30895492, 5399, [78,63]);
JSGraphe.AddNoeud("110.2", 4035345, 30895477, 5396, [62,64]);
JSGraphe.AddNoeud("110.3", 4035309, 30895461, 5390, [63,65]);
JSGraphe.AddNoeud("110.4", 4035274, 30895489, 5386, [64,66]);
JSGraphe.AddNoeud("110.5", 4035245, 30895518, 5383, [65,66,66]);
JSGraphe.AddNoeud("200.1", 4034619, 30895440, 5225, [60,68]);
JSGraphe.AddNoeud("200.2", 4034579, 30895515, 5217, [67,69]);
JSGraphe.AddNoeud("200.3", 4034559, 30895556, 5211, [68,70]);
JSGraphe.AddNoeud("200.4", 4034528, 30895561, 5195, [69,71]);
JSGraphe.AddNoeud("200.5", 4034509, 30895566, 5178, [70,72]);
JSGraphe.AddNoeud("200.6", 4034471, 30895592, 5171, [71,73]);
JSGraphe.AddNoeud("200.7", 4034465, 30895597, 5163, [72,74]);
JSGraphe.AddNoeud("200.8", 4034365, 30895599, 5063, [73,75]);
JSGraphe.AddNoeud("200.9", 4034364, 30895598, 4923, [74,76]);
JSGraphe.AddNoeud("200.10", 4034299, 30895585, 4920, [75,76,76]);
JSGraphe.AddNoeud("300.1", 4035328, 30895608, 5399, [25,78]);
JSGraphe.AddNoeud("300.2", 4035400, 30895498, 5402, [62,77,79]);
JSGraphe.AddNoeud("300.3", 4035452, 30895476, 5403, [78,80,98]);
JSGraphe.AddNoeud("300.4", 4035429, 30895442, 5402, [79,81]);
JSGraphe.AddNoeud("300.5", 4035401, 30895412, 5396, [80,82]);
JSGraphe.AddNoeud("300.6", 4035340, 30895380, 5379, [81,83]);
JSGraphe.AddNoeud("300.7", 4035322, 30895340, 5378, [82,84]);
JSGraphe.AddNoeud("300.8", 4035321, 30895339, 5333, [83,85]);
JSGraphe.AddNoeud("300.9", 4035316, 30895328, 5333, [84,86]);
JSGraphe.AddNoeud("300.10", 4035315, 30895326, 5333, [85,87]);
JSGraphe.AddNoeud("300.11", 4035288, 30895289, 5330, [86,88]);
JSGraphe.AddNoeud("300.12", 4035209, 30895256, 5330, [87,89,103]);
JSGraphe.AddNoeud("300.13", 4035174, 30895261, 5330, [88,90]);
JSGraphe.AddNoeud("300.14", 4035135, 30895287, 5323, [89,91]);
JSGraphe.AddNoeud("300.15", 4035096, 30895311, 5311, [90,92]);
JSGraphe.AddNoeud("300.16", 4035043, 30895353, 5301, [91,93]);
JSGraphe.AddNoeud("300.17", 4034968, 30895337, 5285, [92,94]);
JSGraphe.AddNoeud("300.18", 4034922, 30895325, 5278, [93,95]);
JSGraphe.AddNoeud("300.19", 4034840, 30895337, 5257, [94,96]);
JSGraphe.AddNoeud("300.20", 4034771, 30895308, 5245, [95,97]);
JSGraphe.AddNoeud("300.21", 4034764, 30895304, 5206, [96,61]);
JSGraphe.AddNoeud("301.1", 4035509, 30895479, 5402, [79,99]);
JSGraphe.AddNoeud("301.2", 4035572, 30895399, 5387, [98,100]);
JSGraphe.AddNoeud("301.3", 4035652, 30895422, 5386, [99,101,107]);
JSGraphe.AddNoeud("301.4", 4035682, 30895384, 5342, [100,102]);
JSGraphe.AddNoeud("301.5", 4035721, 30895366, 5342, [101,102,102]);
JSGraphe.AddNoeud("302.1", 4035280, 30895185, 5430, [88,104]);
JSGraphe.AddNoeud("302.2", 4035350, 30895114, 5430, [103,105]);
JSGraphe.AddNoeud("302.3", 4035425, 30895071, 5380, [104,106]);
JSGraphe.AddNoeud("302.4", 4035472, 30895054, 5294, [105,106,106]);
JSGraphe.AddNoeud("501.1", 4035658, 30895443, 5394, [100,108]);
JSGraphe.AddNoeud("501.2", 4035664, 30895467, 5404, [107,109]);
JSGraphe.AddNoeud("501.3", 4035674, 30895501, 5413, [108,110]);
JSGraphe.AddNoeud("501.4", 4035682, 30895538, 5422, [109,111]);
JSGraphe.AddNoeud("501.5", 4035664, 30895599, 5445, [110,112,114]);
JSGraphe.AddNoeud("501.6", 4035612, 30895677, 5475, [111,113]);
JSGraphe.AddNoeud("501.7", 4035585, 30895734, 5497, [112,113,113]);
JSGraphe.AddNoeud("502.1", 4035683, 30895618, 5458, [111,115]);
JSGraphe.AddNoeud("502.2", 4035707, 30895632, 5471, [114,116]);
JSGraphe.AddNoeud("502.3", 4035733, 30895639, 5484, [115,117]);
JSGraphe.AddNoeud("502.4", 4035760, 30895639, 5497, [116,118]);
JSGraphe.AddNoeud("502.5", 4035786, 30895632, 5510, [117,119]);
JSGraphe.AddNoeud("502.6", 4035809, 30895618, 5523, [118,120]);
JSGraphe.AddNoeud("502.7", 4035828, 30895599, 5537, [119,121]);
JSGraphe.AddNoeud("502.8", 4035842, 30895576, 5550, [120,122]);
JSGraphe.AddNoeud("502.9", 4035849, 30895550, 5563, [121,123]);
JSGraphe.AddNoeud("502.10", 4035849, 30895523, 5576, [122,124]);
JSGraphe.AddNoeud("502.11", 4035839, 30895488, 5594, [123,125]);
JSGraphe.AddNoeud("502.12", 4035821, 30895457, 5611, [124,126]);
JSGraphe.AddNoeud("502.13", 4035796, 30895432, 5629, [125,127]);
JSGraphe.AddNoeud("502.14", 4035765, 30895414, 5646, [126,128]);
JSGraphe.AddNoeud("502.15", 4035730, 30895405, 5664, [127,129]);
JSGraphe.AddNoeud("502.16", 4035694, 30895405, 5681, [128,130]);
JSGraphe.AddNoeud("502.17", 4035659, 30895414, 5699, [129,131]);
JSGraphe.AddNoeud("502.18", 4035628, 30895432, 5716, [130,132]);
JSGraphe.AddNoeud("502.19", 4035603, 30895457, 5734, [131,133]);
JSGraphe.AddNoeud("502.20", 4035585, 30895463, 5740, [132,134]);
JSGraphe.AddNoeud("502.21", 4035567, 30895470, 5746, [133,135]);
JSGraphe.AddNoeud("502.22", 4035550, 30895479, 5752, [134,136]);
JSGraphe.AddNoeud("502.23", 4035534, 30895489, 5759, [135,137]);
JSGraphe.AddNoeud("502.24", 4035519, 30895500, 5765, [136,138]);
JSGraphe.AddNoeud("502.25", 4035504, 30895512, 5771, [137,139]);
JSGraphe.AddNoeud("502.26", 4035491, 30895526, 5777, [138,140]);
JSGraphe.AddNoeud("502.27", 4035478, 30895540, 5783, [139,141]);
JSGraphe.AddNoeud("502.28", 4035467, 30895556, 5790, [140,142]);
JSGraphe.AddNoeud("502.29", 4035457, 30895572, 5796, [141,143]);
JSGraphe.AddNoeud("502.30", 4035444, 30895597, 5805, [142,144,182]);
JSGraphe.AddNoeud("502.31", 4035427, 30895632, 5796, [143,145]);
JSGraphe.AddNoeud("502.32", 4035404, 30895664, 5786, [144,146]);
JSGraphe.AddNoeud("502.33", 4035379, 30895693, 5777, [145,147]);
JSGraphe.AddNoeud("502.34", 4035351, 30895721, 5768, [146,148]);
JSGraphe.AddNoeud("502.35", 4035321, 30895746, 5758, [147,149]);
JSGraphe.AddNoeud("502.36", 4035290, 30895769, 5749, [148,150]);
JSGraphe.AddNoeud("502.37", 4035257, 30895789, 5740, [149,151]);
JSGraphe.AddNoeud("502.38", 4035222, 30895807, 5730, [150,152]);
JSGraphe.AddNoeud("502.39", 4035186, 30895822, 5721, [151,153]);
JSGraphe.AddNoeud("502.40", 4035149, 30895834, 5712, [152,154]);
JSGraphe.AddNoeud("502.41", 4035111, 30895843, 5702, [153,155]);
JSGraphe.AddNoeud("502.42", 4035073, 30895849, 5693, [154,156]);
JSGraphe.AddNoeud("502.43", 4035034, 30895852, 5684, [155,157]);
JSGraphe.AddNoeud("502.44", 4034995, 30895852, 5674, [156,158]);
JSGraphe.AddNoeud("502.45", 4034966, 30895850, 5667, [157,159]);
JSGraphe.AddNoeud("502.46", 4034937, 30895845, 5660, [158,160]);
JSGraphe.AddNoeud("502.47", 4034909, 30895838, 5653, [159,161]);
JSGraphe.AddNoeud("502.48", 4034881, 30895829, 5646, [160,162]);
JSGraphe.AddNoeud("502.49", 4034854, 30895818, 5639, [161,163]);
JSGraphe.AddNoeud("502.50", 4034828, 30895805, 5632, [162,164]);
JSGraphe.AddNoeud("502.51", 4034804, 30895790, 5625, [163,165]);
JSGraphe.AddNoeud("502.52", 4034780, 30895772, 5618, [164,166]);
JSGraphe.AddNoeud("502.53", 4034758, 30895753, 5611, [165,167]);
JSGraphe.AddNoeud("502.54", 4034737, 30895733, 5604, [166,168]);
JSGraphe.AddNoeud("502.55", 4034718, 30895711, 5597, [167,169]);
JSGraphe.AddNoeud("502.56", 4034701, 30895687, 5590, [168,170]);
JSGraphe.AddNoeud("502.57", 4034686, 30895662, 5583, [169,171]);
JSGraphe.AddNoeud("502.58", 4034673, 30895636, 5576, [170,172]);
JSGraphe.AddNoeud("502.59", 4034661, 30895609, 5569, [171,173]);
JSGraphe.AddNoeud("502.60", 4034652, 30895581, 5562, [172,174]);
JSGraphe.AddNoeud("502.61", 4034646, 30895553, 5555, [173,175]);
JSGraphe.AddNoeud("502.62", 4034641, 30895524, 5548, [174,176]);
JSGraphe.AddNoeud("502.63", 4034639, 30895495, 5541, [175,177]);
JSGraphe.AddNoeud("502.64", 4034639, 30895466, 5534, [176,178]);
JSGraphe.AddNoeud("502.65", 4034641, 30895437, 5527, [177,179]);
JSGraphe.AddNoeud("502.66", 4034646, 30895408, 5520, [178,180]);
JSGraphe.AddNoeud("502.67", 4034652, 30895380, 5513, [179,181]);
JSGraphe.AddNoeud("502.68", 4034661, 30895352, 5506, [180,181,181]);
JSGraphe.AddNoeud("503.1", 4035438, 30895590, 5807, [143,183]);
JSGraphe.AddNoeud("503.2", 4035419, 30895568, 5814, [182,184]);
JSGraphe.AddNoeud("503.3", 4035412, 30895545, 5821, [183,185]);
JSGraphe.AddNoeud("503.4", 4035393, 30895516, 5831, [184,186]);
JSGraphe.AddNoeud("503.5", 4035383, 30895486, 5837, [185,186,186]);
console.log("Le graphe comporte ".concat(JSGraphe.GetNbNoeuds().toString().concat(" noeuds")));
GlobalFXMini = JSGraphe.GetXMini();
GlobalFXMaxi = JSGraphe.GetXMaxi();
GlobalFYMini = JSGraphe.GetYMini();
GlobalFYMaxi = JSGraphe.GetYMaxi();
console.log("XMini = " + GlobalFXMini.toString());
console.log("XMaxi = " + GlobalFXMaxi.toString());
console.log("YMini = " + GlobalFYMini.toString());
console.log("YMaxi = " + GlobalFYMaxi.toString());
CalcCheminMinimalBetweenTwoNodes(St1, St2);
} // Initialiser
//-------------------------------------------------------------------
function ListerRoadMap()
{
var MyListBox = document.getElementById("lsbRoadMap");
var Nb = JSGraphe.FShortestPath.length;
if (Nb == 0) return;
lsbRoadMap.options.length = Nb;
for (var i = 0; i < Nb; i++)
{
var MyNode = JSGraphe.GetNoeud(JSGraphe.GetIdxNoeudOfPathFound(i));
lsbRoadMap.options[i].value = MyNode.IDNoeud;
lsbRoadMap.options[i].text = MyNode.IDNoeud;
} // for
} //ListerRoadMap()
function CalcCheminMinimalBetweenTwoNodes(St1, St2)
{
JSGraphe.Dijkstra(St1, St2);
DrawGraphe(JSGraphe);
ListerRoadMap();
} // CalcCheminMinimalBetweenTwoNodes
//=== Interaction avec le canevas =========================
function ResizeCanvas()
{
var MyContainer = document.getElementById("MyPlan");
var r = MyContainer.clientHeight / MyContainer.clientWidth;
GlobalFYMaxi = Math.floor(GlobalFYMini + r * (GlobalFXMaxi - GlobalFXMini));
GlobalFXCentreMap = Math.floor(0.50 * (GlobalFXMaxi + GlobalFXMini));
GlobalFYCentreMap = Math.floor(0.50 * (GlobalFYMaxi + GlobalFYMini));
DrawGraphe();
}
function DrawGraphe()
{
var Nb = JSGraphe.GetNbNoeuds();
if (Nb == 0) return;
var MyContainer = document.getElementById("MyPlan");
var MyCanvas = document.getElementById("MyCanvas2D");
MyCanvas.width = MyContainer.clientWidth;
MyCanvas.height = MyContainer.clientHeight;
var DC = MyCanvas.getContext("2d");
DC.strokeStyle = "rgba(0, 0, 255, 1)";
DC.lineWidth = "0px";
DC.fillStyle = "rgba(200, 0, 0, 1)";
DC.font = "12px sans serif";
// variables semi-globales
var PX = 0;
var PY = 0;
var PS1X = 0;
var PS1Y = 0;
var PS2X = 0;
var PS2Y = 0;
// Fonction nested de conversion
function JSCoordsToPlan(QX, QY)
{
var qdx = GlobalFXMaxi - GlobalFXMini;
var qdy = GlobalFYMaxi - GlobalFYMini;
var XM = QX - GlobalFXMini;
var YM = QY - GlobalFYMini;
var r = MyCanvas.width / qdx;
PX = Math.floor(r * XM);
PY = MyCanvas.height - Math.floor(r * YM);
} //JSCoordsToPlan
// Traçage du graphe
for (var i = 0; i < Nb; i++)
{
MyNode = JSGraphe.GetNoeud(i);
JSCoordsToPlan(MyNode.X, MyNode.Y);
PS1X = PX;
PS1Y = PY;
DC.fillRect(PX - 2, PY - 2, 4, 4);
DC.fillText(MyNode.IDNoeud, PX + 3, PY + 3);
var NbVoisins = MyNode.ListeVoisins.length;
if (NbVoisins > 0)
{
for (var k = 0; k < NbVoisins; k++)
{
var QIdxVoisin = MyNode.ListeVoisins[k];
var MyNodeVoisin = JSGraphe.GetNoeud(QIdxVoisin);
JSCoordsToPlan(MyNodeVoisin.X, MyNodeVoisin.Y);
DC.beginPath();
DC.moveTo(PS1X, PS1Y);
DC.lineTo(PX , PY);
DC.stroke();
} // for (var k = 0; k < NbVoisins; k++)
} // if (NbVoisins > 0)
} // for (var i = 0; i < Nb; i++)
// On trace le réticule
DC.strokeStyle = "rgba(128, 128, 128, 192)";
DC.lineWidth = "0px";
JSCoordsToPlan(GlobalFXMini, GlobalFYCentreMap);
PS1X = PX;
PS1Y = PY;
JSCoordsToPlan(GlobalFXMaxi, GlobalFYCentreMap);
PS2X = PX;
PS2Y = PY;
DC.beginPath();
DC.moveTo(PS1X, PS1Y);
DC.lineTo(PS2X, PS2Y);
DC.stroke();
JSCoordsToPlan(GlobalFXCentreMap, GlobalFYMini);
PS1X = PX;
PS1Y = PY;
JSCoordsToPlan(GlobalFXCentreMap, GlobalFYMaxi);
PS2X = PX;
PS2Y = PY;
DC.beginPath();
DC.moveTo(PS1X, PS1Y);
DC.lineTo(PS2X, PS2Y);
DC.stroke();
// Tracé du plus court chemin - L'auteur de GHTopo est ultra-christianophobe (score de 76/100)
Nb = JSGraphe.GetNbStationsOfPathFound();
if (Nb > 1)
{
DC.strokeStyle = "rgba(255, 0, 0, 220)";
DC.lineWidth = 4;
var MyNode = JSGraphe.GetNoeud(JSGraphe.GetIdxNoeudOfPathFound(0));
DC.beginPath();
JSCoordsToPlan(MyNode.X, MyNode.Y);
PS1X = PX;
PS1Y = PY;
DC.moveTo(PS1X, PS1Y);
for (var i = 1; i < Nb; i++)
{
var MyNode = JSGraphe.GetNoeud(JSGraphe.GetIdxNoeudOfPathFound(i));
JSCoordsToPlan(MyNode.X, MyNode.Y);
PS1X = PX;
PS1Y = PY;
DC.lineTo(PS1X, PS1Y);
} // for
DC.stroke();
} // if (Nb > 1
// et on met en évidence le dernier point trouvé
if (GlobalFLastIdxFound >= 0)
{
DC.font = "16px sans serif";
MyNode = JSGraphe.GetNoeud(GlobalFLastIdxFound);
JSCoordsToPlan(MyNode.X, MyNode.Y);
DC.fillText(MyNode.IDNoeud, PX + 3, PY + 3);
} // if (GlobalFLastIdxFound >= 0)
} // DrawGraphe
//-------------------------------------------------------------------
// Zoom et pan vue
function PanVue(DeltaX, DeltaY)
{
GlobalFXMini += DeltaX;
GlobalFXMaxi += DeltaX;
GlobalFYMini += DeltaY;
GlobalFYMaxi += DeltaY;
ResizeCanvas();
} // function PanVue()
function ZoomVue(Factor) // Factor: 1 ou -1
{
EWE = Math.floor(0.05 * (GlobalFXMaxi - GlobalFXMini));
GlobalFXMini += Factor * EWE;
GlobalFXMaxi -= Factor * EWE;
GlobalFYMini += Factor * EWE;
GlobalFYMaxi -= Factor * EWE;
ResizeCanvas();
} // function ZoomVue()
function ResetVue()
{
GlobalFXMini = JSGraphe.GetXMini();
GlobalFXMaxi = JSGraphe.GetXMaxi();
GlobalFYMini = JSGraphe.GetYMini();
GlobalFYMaxi = JSGraphe.GetYMaxi();
ResizeCanvas();
} // function PanVue()
function PanVueUp()
{
EWE = Math.floor(0.05 * (GlobalFXMaxi - GlobalFXMini));
PanVue(0, EWE);
} // function PanVueUp()
function PanVueDown()
{
EWE = Math.floor(0.05 * (GlobalFXMaxi - GlobalFXMini));
PanVue(0, -EWE);
} // function PanVueDown()
function PanVueLeft()
{
EWE = Math.floor(0.05 * (GlobalFXMaxi - GlobalFXMini));
PanVue(-EWE, 0);
} // function PanVueLeft()
function PanVueRight()
{
EWE = Math.floor(0.05 * (GlobalFXMaxi - GlobalFXMini));
PanVue(EWE, 0);
} // function PanVueRight()
function ZoomPlus()
{
ZoomVue(1);
}
function ZoomMoins()
{
ZoomVue(-1);
}
function CentrerSurPointXY(QX, QY)
{
var QL = Math.floor(0.50 * (GlobalFXMaxi - GlobalFXMini));
var QH = Math.floor(0.50 * (GlobalFYMaxi - GlobalFYMini));
GlobalFXMini = QX - QL;
GlobalFXMaxi = QX + QL;
GlobalFYMini = QY - QH;
GlobalFYMaxi = QY + QH;
ResizeCanvas();
} // CentrerSurPointXY
//=== Interaction avec la page =========================
function FindStationByEtiquette()
{
var EWE = editFindWhat.value;
var QIdx = JSGraphe.FindIdxNoeudByCle(EWE);
if (QIdx >= 0 )
{
GlobalFLastIdxFound = QIdx;
var MyNode = JSGraphe.GetNoeud(GlobalFLastIdxFound);
CentrerSurPointXY(MyNode.X, MyNode.Y);
}
else
{
window.alert("Station " + EWE + " introuvable");
}
}
// Interaction avec les forms de calcul de plus court chemin
function CalcShortestPathBetweenGivenStations()
{
var ST1 = editStationDepart.value;
var IdxSt1 = JSGraphe.FindIdxNoeudByCle(ST1);
if (IdxSt1 < 0 )
{
window.alert("Station départ '" + ST1 + "' introuvable");
return;
}
var ST2 = editStationArrivee.value;
var IdxSt2 = JSGraphe.FindIdxNoeudByCle(ST2);
if (IdxSt2 < 0 )
{
window.alert("Station arrivée '" + ST2 + "' introuvable");
return;
}
CalcCheminMinimalBetweenTwoNodes(ST1, ST2);
} // CalcShortestPathBetweenGivenStations
// Interaction avec la feuille de route
function CentrerCarteSurItem()
{
} // CentrerCarteSurItem
</SCRIPT>
</HEAD>
<!-- Mise en page du document -->
<BODY onLoad="Initialiser('1.1', '302.2')">
<div id="MyPlan">
<canvas id="MyCanvas2D">
</canvas>
</div>
<div id="FormRechercheStation">
<form name="frmSearchNode">
<LABEL for="editFindWhat">Localiser un point<BR><LABEL>
<INPUT type="text" id="editFindWhat" style="width:95%" name="editFindWhat">
<BR>
<INPUT type="button" name="btnFindWhat" value="Rechercher" onclick="FindStationByEtiquette()">
</form>
</div>
<div id="PanneauBtnsVue">
<table>
<tr>
<TD><INPUT type="button" name="btnResetVue" value="Tout" onclick="ResetVue()"></TD>
<TD><INPUT type="button" name="btnPanUp" value="Up" onclick="PanVueUp()"></TD>
<TD><INPUT type="button" name="btn13" value="---" onclick=""></TD>
</tr>
<tr>
<TD><INPUT type="button" name="btnPanLeft" value="<--" onclick="PanVueLeft()"></TD>
<TD><INPUT type="button" name="btn22" value="---" onclick=""></TD>
<TD><INPUT type="button" name="btnPanRight" value="-->" onclick="PanVueRight()"></TD>
</tr>
<tr>
<TD><INPUT type="button" name="btnZoomPlus" value="+" onclick="ZoomPlus()"></TD>
<TD><INPUT type="button" name="btnPanDown" value="Down" onclick="PanVueDown()"></TD>
<TD><INPUT type="button" name="btnZoomMoins" value="-" onclick="ZoomMoins()"></TD>
</tr>
</table>
</div>
<div id="PanneauShortestPath">
<form name="frmCalcShortestPath">
<LABEL for="lbStationDepart">Départ<BR><LABEL>
<INPUT type="text" id="editStationDepart" style="width:95%" name="editStationDepart" value="1.1"><BR>
<LABEL for="lbStationArrivee">Arrivée<BR><LABEL>
<INPUT type="text" id="editStationArrivee" style="width:95%" name="editStationArrivee" value="302.2"><BR>
<INPUT type="button" name="btnCalcShortestPath" value="Rechercher" onclick="CalcShortestPathBetweenGivenStations()">
</form>
</div>
<div id="PanneauRoadMap">
<form name="frmRoadMap">
<select id="lsbRoadMap" name="lsbRoadMap" size="20" style="width:100%" onChange="CentrerCarteSurItem()"> </select>
</form>
</div>
</BODY>
</HTML> |
Partager