Skip to main content
All docs
V21.2

BingTrafficIncidentDataProvider Class

Allows you to receive information about traffic incidents within a specified area from the Bing Maps service and display incident icons on the map.

Namespace: DevExpress.Xpf.Map

Assembly: DevExpress.Xpf.Map.v21.2.dll

Declaration

public class BingTrafficIncidentDataProvider :
    BingMapDataProviderBase

Remarks

Follow the steps below to create a map with traffic incidents:

To include traffic location codes in the method’s result, enable the BingTrafficIncidentDataProvider.Options.IncludeLocationCodes property.

After you obtain a list of incidents, the provider raises the TrafficIncidentCalculated event. You can handle the event to access the collection of received incidents or add custom logic.

Example

How to: Display Traffic Incidents on the Map

The following code displays traffic incidents that occur in a specified area:

A map that displays traffic incidents.

<Window
        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>
        <dxm:MapControl x:Name="mapControl">
            <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." />
            </dxm:InformationLayer>
        </dxm:MapControl>
    </Grid>
</Window>
using DevExpress.Xpf.Map;
using System.Windows;

namespace TrafficIncidents {
    public partial class MainWindow : Window {
        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();
        }
    }
}

Implements

See Also