Changeset 266 in tmcsimulator for trunk/src/atmsdriver/model


Ignore:
Timestamp:
02/16/2019 03:22:09 PM (7 years ago)
Author:
jdalbey
Message:

PostmileCoords?.java: Add cross street name attribute and modified toJson to include it.

Location:
trunk/src/atmsdriver/model
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/atmsdriver/model/Highways.java

    r260 r266  
    556556                            + stat.postmile; 
    557557                    PostmileCoords.Postmile currentPM = pmList.find(pmID); 
     558                    if (currentPM == null) 
     559                    {  
     560                    Logger.getLogger(Highways.class.getName()).log(Level.INFO,  
     561                            "Postmile Coords lookup couldn't find Station: "+pmID, 
     562                            " "); 
     563                    } 
    558564                    if (currentPM != null) 
    559565                    {     
    560                     //lineout.append("" + dir.getLetter() + stat.postmile); 
    561                     //lineout.append(stat.getColorByDirection(dir)); 
    562                     String outString = currentPM.toJson(); 
    563                     // replace the color code with the color name 
    564                     String colorName=""; 
    565                     switch (stat.getColorByDirection(stat.direction)) 
    566                     { 
    567                         case '@': colorName = "red";break; 
    568                         case '+': colorName = "yellow"; break; 
    569                         case '-': colorName = "lime";break; 
    570                         case ' ': colorName = "lime";break; 
    571                     } 
    572                     outString = outString.replace("desiredcolor",colorName); 
    573                     lineout.append(outString); 
    574                     lineout.append("  "); 
     566                        //lineout.append("" + dir.getLetter() + stat.postmile); 
     567                        //lineout.append(stat.getColorByDirection(dir)); 
     568                        String outString = currentPM.toJson(); 
     569                        // replace the color code with the color name 
     570                        String colorName=""; 
     571                        switch (stat.getColorByDirection(stat.direction)) 
     572                        { 
     573                            case '@': colorName = "red";break; 
     574                            case '+': colorName = "yellow"; break; 
     575                            case '-': colorName = "lime";break; 
     576                            case ' ': colorName = "lime";break; 
     577                        } 
     578                        outString = outString.replace("desiredcolor",colorName); 
     579                        lineout.append(outString); 
     580                        lineout.append("  "); 
    575581                    } 
    576582                } 
  • trunk/src/atmsdriver/model/PostmileCoords.java

    r260 r266  
    4848    public void load(Scanner scan) 
    4949    { 
     50        try 
     51        { 
    5052        String out = scan.next(); 
    5153        //  split into an array  
     
    6264            }   
    6365            String revisedpm = nameparts[0] + " " + nameparts[1] + " " + statepm; 
    64             Postmile pm = new Postmile(revisedpm,fields[1],fields[2]); 
     66            Postmile pm = new Postmile(revisedpm,fields[1],fields[2],fields[3]); 
    6567            postmileList.add(pm); 
     68        } 
     69        } 
     70        catch (Exception ex) 
     71        { 
     72            ex.printStackTrace(); 
    6673        } 
    6774    } 
     
    7784    final static class Postmile   
    7885    { 
    79         String name;  // the postmile name (Route,Direction,State postmile) 
     86        String name;  // the postmile name (Route,Direction,State postmile, e.g., 5 N 6.2) 
    8087        String latitude; // the latitude coordinate for this postmile 
    8188        String longitude; // the longitude coordinate for this postmile 
    82         public Postmile(String name, String lat, String longitude) 
     89        String street; // cross street name 
     90        public Postmile(String name, String lat, String longitude, String street) 
    8391        { 
    8492            this.name = name.trim(); 
    8593            this.latitude = lat.trim(); 
    8694            this.longitude = longitude.trim(); 
     95            this.street = street.trim(); 
    8796        } 
    8897        public boolean nameEquals(String target) 
     
    98107            boolean r2 = this.latitude.equals(that.latitude); 
    99108            boolean r3 = this.longitude.equals(that.longitude); 
    100             return r1 && r2 && r3; 
     109            boolean r4 = this.street.equals(that.street); 
     110            return r1 && r2 && r3 && r4; 
    101111        } 
    102112        @Override public String toString() 
    103113        { 
    104             return name + ": " + latitude +","+ longitude; 
     114            return name + ": " + latitude +","+ longitude +","+ street; 
    105115        } 
    106116        public String toJson() 
    107117        { 
    108             String kFeature = "\n{\n   \"type\": \"Feature\",\n   \"id\": \""; 
    109             String kPoint = "\", \n     \"geometry\":\n       {\n        \"type\": \"Point\",\n        \"coordinates\": ["; 
    110             String kProp = "]\n" + 
    111 "      },\n" + 
    112 "      \"properties\": \n" + 
    113 "        {\"color\": \"desiredcolor\""; 
    114             String kTail = "}\n" + 
    115 "    },"; 
    116             return kFeature + name + kPoint + longitude + "," + latitude + kProp + kTail; 
     118            String pattern =  "\n{\n   \"type\": \"Feature\",\n"  
     119                    + "   \"geometry\":\n       {\n        \"type\": \"Point\",\n" + 
     120                    "        \"coordinates\": [%s,%s]\n" + 
     121                    "       },\n" + 
     122                    "      \"properties\": \n" +          
     123                    "        {\"id\": \"%s\", " + 
     124                    "\"street\": \"%s\", " + 
     125                    "\"color\": \"desiredcolor\"" + 
     126                    "}\n},"; 
     127 
     128            return String.format(pattern, longitude, latitude, name, street); 
    117129        } 
    118130    } 
Note: See TracChangeset for help on using the changeset viewer.