Changeset 248 in tmcsimulator for trunk/src/tmcsim/cadsimulator


Ignore:
Timestamp:
02/09/2019 08:18:35 AM (7 years ago)
Author:
jdalbey
Message:

TrafficModelManager?: multi-file commit to enhance Traffic Mgr to output highway status to json file for viewing in Google Map.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/cadsimulator/managers/TrafficModelManager.java

    r228 r248  
    11package tmcsim.cadsimulator.managers; 
    22 
     3import atmsdriver.GoogleMapAnimator; 
    34import atmsdriver.model.Highways; 
    45import atmsdriver.model.LoopDetector; 
     
    89import java.io.FileInputStream; 
    910import java.io.FileNotFoundException; 
     11import java.io.PrintWriter; 
    1012import java.rmi.RemoteException; 
    1113import java.text.ParseException; 
     
    208210            wtConsole.start(); 
    209211        } 
     212        // Always write to json for google map display 
     213        Thread wtJson = new WriteToJsonThread(); 
     214        wtJson.start(); 
    210215    } 
    211216    /** Accessor to event queue 
     
    403408            while (true) 
    404409            { 
    405                  // Write the highway network status to the FEP Simulator 
     410                 // Write the highway network status to the Console 
    406411                 System.out.println(highways.toString()); 
    407  
    408                 // Wait for FEP Sim to process the data we just sent 
     412                // Output the highway model  
     413                String geojson = highways.toJson(); 
     414                //System.out.println(geojson); // diagnostic 
     415                PrintWriter out; 
     416                try 
     417                { 
     418                    out = new PrintWriter("highways.json"); 
     419                    out.print(geojson); 
     420                    out.close(); 
     421                } 
     422                catch (FileNotFoundException ex) 
     423                { 
     424                    Logger.getLogger(GoogleMapAnimator.class.getName()).log(Level.SEVERE, null, ex); 
     425                } 
     426                // Wait for Google Map to process the data we just sent 
    409427                try 
    410428                { 
    411429                    Thread.sleep(5000); 
     430                } 
     431                catch (InterruptedException ie) 
     432                { 
     433                    ie.printStackTrace(); 
     434                } 
     435            } 
     436 
     437        } 
     438    } 
     439    /** Writes the highway model to a GeoJson file for reading 
     440     *  by Google Maps. 
     441     */ 
     442    class WriteToJsonThread extends Thread 
     443    { 
     444 
     445        public void run() 
     446        { 
     447            System.out.println("WriteToJson Thread starting."); 
     448            // Run indefinitely 
     449            while (true) 
     450            { 
     451                 // Write the highway network status to Json 
     452                String geojson = highways.toJson(); 
     453                PrintWriter out; 
     454                try 
     455                { 
     456                    // currently writes to local file 
     457                    out = new PrintWriter("highways.json"); 
     458                    out.print(geojson); 
     459                    out.close(); 
     460                } 
     461                catch (FileNotFoundException ex) 
     462                { 
     463                    Logger.getLogger(GoogleMapAnimator.class.getName()).log(Level.SEVERE, null, ex); 
     464                } 
     465                // Wait for Google Map to process the data we just sent 
     466                try 
     467                { 
     468                    Thread.sleep(30000); 
    412469                } 
    413470                catch (InterruptedException ie) 
Note: See TracChangeset for help on using the changeset viewer.