ITrafficSource Interface |
Namespace: Telogis.GeoBase.Traffic
The ITrafficSource type exposes the following members.
Name | Description | |
---|---|---|
CreatedTime |
The DateTime when the traffic data was created.
|
Name | Description | |
---|---|---|
GetTrafficInfo(String, DateTime) |
Implemented by derived classes to resolve a given TMC and DateTime
to a TrafficInfo.
| |
GetTrafficInfo(String, DateTime, TimeZone) |
Implemented by derived classes to resolve a given TMC code and DateTime
to a TrafficInfo.
|
The ITrafficSource interface is implemented to resolve a given TMC (Traffic Message Channel) code and DateTime
to a TrafficInfo. A Traffic object will have one or more
traffic sources which will be implemented with the ITrafficSource interface. GeoBase provides classes with implementations of this interface in support
of the following traffic data:
Additional traffic data sources can be added with the ITrafficSource interface. The interface exposes the GetTrafficInfo method, and the CreatedTime property. To implement this interface, code must be provided for both GetTrafficInfo, and CreatedTime.
CreatedTime - gets DateTime when the traffic data was created.
GetTrafficInfo - this method returns the TrafficInfo for the given TMC code at the specified DateTime. The speed can be found from the traffic source data by searching for the given TMC code with the given time, and then extracting the speed from the found TMC code.
Related articles: Routing with Traffic.
class MyTrafficSource : ITrafficSource { private DateTime createdTime; private Dictionary<string, int> speeds; //Constructor public MyTrafficSource(string src) { speeds = new Dictionary<string, int>(); // Populate speeds with traffic information from "src" LoadTrafficFile(src); } // Fill in createdTime and speeds based on the contents of src. private void LoadTrafficFile(string src) { // Set createdTime from a timestamp contained within src createdTime = ... // Scan through remainder of src, populating speeds as we go. ... } //ITrafficSource members public TrafficInfo GetTrafficInfo(string tmc, DateTime time) { return GetTrafficInfo(tmc, time, null); } //Get TrafficInfo for the specified TMC code and time public TrafficInfo GetTrafficInfo(string tmc, DateTime time, Telogis.GeoBase.TimeZone? timezone) { int speed; if (timezone != null) { time = ((Telogis.GeoBase.TimeZone)timezone).ConvertTime(time); } //Check if data is still valid if (createdTime.AddMinutes(15) < time) { return null; } if (speeds.TryGetValue(tmc, out speed)) { return new TrafficInfo(speed); } return null; } public DateTime CreatedTime { get { return createdTime; } } }