TrafficIncidentCalculationResult.IncidentResults Property
Returns a list of traffic incidents with additional information (the location, incident type, and much more).
Namespace: DevExpress.Xpf.Map
Assembly: DevExpress.Xpf.Map.v24.1.dll
NuGet Package: DevExpress.Wpf.Map
Declaration
Property Value
Type | Description |
---|---|
List<BingTrafficIncidentResult> | A list of traffic incidents. |
Example
How to: Obtain and Display a List of Traffic Incidents
This example obtains a list of incidents in the specified area from the Bing Maps service and displays information about obtained incidents in a TextEdit control.
Create an InformationLayer object and add it to the MapControl.Layers collection.
Initialize the layer’s DataProvider property with a BingTrafficIncidentDataProvider object.
Specify the provider’s BingKey property.
Call the provider’s RequestTrafficIncidents method to receive a list of incidents.
Handle the provider’s TrafficIncidentCalculated event to access the list of incidents and display incident-related information in a TextEdit control.
<Window xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TrafficIncidents"
xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map"
x:Class="TrafficIncidents.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Loaded="OnWindowLoaded">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<dxm:MapControl x:Name="mapControl" Grid.Column="0">
<dxm:ImageLayer>
<dxm:BingMapDataProvider BingKey="Insert your Bing key."
Kind="RoadLight"/>
</dxm:ImageLayer>
<dxm:InformationLayer DataRequestCompleted="OnDataRequestCompleted">
<dxm:BingTrafficIncidentDataProvider x:Name="incidentProvider"
BingKey="Insert your Bing key."
TrafficIncidentCalculated="OnTrafficIncidentCalculated" />
</dxm:InformationLayer>
</dxm:MapControl>
<dxe:TextEdit x:Name="textEdit" TextWrapping="Wrap" Grid.Column="1"/>
</Grid>
</Window>
using DevExpress.Xpf.Map;
using System.Text;
using System.Windows;
namespace TrafficIncidents {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void OnWindowLoaded(object sender, RoutedEventArgs e) {
BingTrafficIncidentSeverity incidentSeverity = BingTrafficIncidentSeverity.LowImpact | BingTrafficIncidentSeverity.Minor |
BingTrafficIncidentSeverity.Moderate | BingTrafficIncidentSeverity.Serious;
BingTrafficIncidentType incidentType = BingTrafficIncidentType.Accident | BingTrafficIncidentType.Construction |
BingTrafficIncidentType.Miscellaneous | BingTrafficIncidentType.Weather;
SearchBoundingBox searchArea = new SearchBoundingBox { WestLongitude = -115.338457, NorthLatitude = 36.268745,
EastLongitude = -114.988268, SouthLatitude= 36.1010376 };
incidentProvider.RequestTrafficIncidents( searchArea, incidentSeverity, incidentType);
}
private void OnDataRequestCompleted(object sender, RequestCompletedEventArgs e) {
// Zoom the map so that it displays the obtained incidents.
mapControl.ZoomToFitLayerItems();
}
private void OnTrafficIncidentCalculated(object sender, BingTrafficIncidentCalculatedEventArgs e) {
if (e.Cancelled) return;
if (e.RequestResult.ResultCode != RequestResultCode.Success) {
textEdit.Text = "Traffic incidents were not found for this area.";
return;
}
StringBuilder resultList = new StringBuilder("");
int resCounter = 1;
foreach (BingTrafficIncidentResult resultInfo in e.RequestResult.IncidentResults) {
resultList.Append(string.Format("Incident {0}: \r\n", resCounter));
resultList.Append(string.Format("Type: {0}\r\n", resultInfo.Type));
resultList.Append(string.Format("Description: {0}\r\n", resultInfo.Description));
resultList.Append(string.Format("Start Time: {0}\r\n", resultInfo.StartTime));
resultList.Append(string.Format("End Time: {0}\r\n", resultInfo.EndTime));
resultList.Append(string.Format("Lat: {0}, Lon: {1}\r\n", resultInfo.Point.Latitude, resultInfo.Point.Longitude));
resultList.Append(string.Format("______________________________\r\n"));
resCounter++;
}
textEdit.Text = resultList.ToString();
}
}
}