Changeset 243 in tmcsimulator for trunk/src/atmsdriver/model/Highways.java
- Timestamp:
- 02/07/2019 03:10:15 PM (7 years ago)
- File:
-
- 1 edited
-
trunk/src/atmsdriver/model/Highways.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/atmsdriver/model/Highways.java
r238 r243 5 5 import atmsdriver.model.Station.DIRECTION; 6 6 import java.io.File; 7 import java.io.FileInputStream; 7 8 import java.io.FileNotFoundException; 8 9 import java.io.IOException; … … 522 523 return result.toString(); 523 524 } 525 /** Return a json representation of the Highways, readable by Google Maps */ 526 public String toJson() 527 { 528 PostmileCoords pmList = new PostmileCoords(); 529 FileInputStream fis = null; 530 try 531 { 532 fis = new FileInputStream("config/vds_data/postmile_coordinates.txt"); 533 } 534 catch (FileNotFoundException ex) 535 { 536 Logger.getLogger(Highways.class.getName()).log(Level.SEVERE, null, ex); 537 } 538 Scanner s = new Scanner(fis).useDelimiter("\\A"); 539 pmList.load(s); 540 String header = "{\n" + 541 " \"type\": \"FeatureCollection\",\n" + 542 " \"features\": ["; 543 StringBuilder result = new StringBuilder(); 544 result.append(header); 545 for (Highway hwy: highways) 546 { 547 // Consider each route direction 548 //for (DIRECTION dir: DIRECTION.values()) 549 // TODO: Needs fixing so proper direction is displayed 550 Station.DIRECTION dir = Station.DIRECTION.SOUTH; 551 if (hwy.routeNumber == 55) 552 dir = Station.DIRECTION.SOUTH; 553 if (hwy.routeNumber == 405) 554 dir = Station.DIRECTION.NORTH; 555 { 556 String rowLabel = ""+String.format("%3s ",hwy.routeNumber)+dir.getLetter()+' '; 557 StringBuilder lineout = new StringBuilder(); 558 // Examine every station on this highway and direction 559 for (Station stat: hwy.stations) 560 { 561 String pmID = "" + hwy.routeNumber + " " + stat.postmile; 562 PostmileCoords.Postmile currentPM = pmList.find(pmID); 563 if (currentPM != null) 564 { 565 //lineout.append("" + dir.getLetter() + stat.postmile); 566 //lineout.append(stat.getColorByDirection(dir)); 567 String outString = currentPM.toJson(); 568 String colorName=""; 569 switch (stat.getColorByDirection(dir)) 570 { 571 case '@': colorName = "red";break; 572 case '+': colorName = "yellow"; break; 573 case '-': colorName = "green";break; 574 case ' ': colorName = "green";break; 575 } 576 outString = outString.replace("green",colorName); 577 lineout.append(outString); 578 lineout.append(" "); 579 } 580 } 581 // See if there were stations for this direction 582 String checkMe = lineout.toString().trim(); 583 // if any stations were colored, output the line 584 if (checkMe.length() > 1) 585 { 586 //result.append(rowLabel); 587 result.append(lineout + "\n"); 588 } 589 590 } 591 } 592 // remove last trailing comma 593 result.replace(result.lastIndexOf(","), result.lastIndexOf(",") + 1, " " ); 594 595 result.append(" ]\n" + "}"); 596 return result.toString(); 597 } 524 598 525 599 /**
Note: See TracChangeset
for help on using the changeset viewer.
