Back to Devexpress

IInformationData Interface

windowsforms-devexpress-dot-xtramap-f0a2ae18.md

latest7.5 KB
Original Source

IInformationData Interface

Interface that should be implemented by any object which can obtain the information data from map services.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
public interface IInformationData
vb
Public Interface IInformationData

Example

This example demonstrates how create a custom route provider and use it to calculate a route between two geographic points.

To do this, design a class inheriting the InformationDataProviderBase abstract class and implement its CreateData() abstract method. Then, design a class inheriting the IInformationData interface and override its IInformationData.OnDataResponse event. Implement the CalculateRouteCore method to provide custom route calculations.

csharp
using DevExpress.XtraMap;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace CustomRouteProvider {
    public partial class Form1 : Form {
        InformationLayer Layer { get { return (InformationLayer)mapControl1.Layers[1]; } }
        public Form1() {
            InitializeComponent();
            RouteProvider provider = new RouteProvider();
            Layer.DataProvider = provider;
            provider.CalculateRoute(new GeoPoint(70, 60), new GeoPoint(-60, -70));
        }
    }
    public class RouteProvider : InformationDataProviderBase {
        protected new RouteData Data { get { return (RouteData)base.Data; } }
        public IEnumerable<GeoPoint> Route { get { return Data.Route; } }

        protected override IInformationData CreateData() {
            return new RouteData();
        }
        public void CalculateRoute(GeoPoint point1, GeoPoint point2) {
            Data.CalculateRoute(point1, point2);
        }
    }
    public class RouteData : IInformationData {
        readonly List<GeoPoint> route = new List<GeoPoint>();
        public List<GeoPoint> Route { get { return route; } }
        public event EventHandler<RequestCompletedEventArgs> OnDataResponse;
        RequestCompletedEventArgs CreateEventArgs() {
            MapItem[] items = new MapItem[3];
            items[1] = new MapCallout() { Location = route[0], Text = route[0].ToString() };
            items[2] = new MapCallout() { Location = route[route.Count - 1], Text = route[route.Count - 1].ToString() };
            MapPolyline polyline = new MapPolyline() { IsGeodesic = true, Stroke = System.Drawing.Color.Red, StrokeWidth = 4 };
            for (int i = 0; i < route.Count; i++)
                polyline.Points.Add(route[i]);
            items[0] = polyline;
            return new RequestCompletedEventArgs(items, null, false, null);
        }
        protected void RaiseChanged() {
            if (OnDataResponse != null)
                OnDataResponse(this, CreateEventArgs());
        }
        public void CalculateRoute(GeoPoint point1, GeoPoint point2) {
            CalculateRouteCore(point1, point2);
            RaiseChanged();
        }
        void CalculateRouteCore(GeoPoint point1, GeoPoint point2) {
            this.route.Clear();
            route.Add(point1);
            route.Add(point2);
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Threading.Tasks
Imports System.Windows.Forms

Namespace CustomRouteProvider
    Friend NotInheritable Class Program
        ''' <summary>
        ''' The main entry point for the application.
        ''' </summary>
        Private Sub New()
        End Sub
        <STAThread> _
        Shared Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
            Application.Run(New Form1())
        End Sub
    End Class
End Namespace
vb
Imports Microsoft.VisualBasic
Imports DevExpress.XtraMap
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms

Namespace CustomRouteProvider
    Partial Public Class Form1
        Inherits Form
        Private ReadOnly Property Layer() As InformationLayer
            Get
                Return CType(mapControl1.Layers(1), InformationLayer)
            End Get
        End Property
        Public Sub New()
            InitializeComponent()
            Dim provider As New RouteProvider()
            Layer.DataProvider = provider
            provider.CalculateRoute(New GeoPoint(70, 60), New GeoPoint(-60, -70))
        End Sub
    End Class
    Public Class RouteProvider
        Inherits InformationDataProviderBase
        Protected Shadows ReadOnly Property Data() As RouteData
            Get
                Return CType(MyBase.Data, RouteData)
            End Get
        End Property
        Public ReadOnly Property Route() As IEnumerable(Of GeoPoint)
            Get
                Return Data.Route
            End Get
        End Property

        Protected Overrides Function CreateData() As IInformationData
            Return New RouteData()
        End Function
        Public Sub CalculateRoute(ByVal point1 As GeoPoint, ByVal point2 As GeoPoint)
            Data.CalculateRoute(point1, point2)
        End Sub
    End Class
    Public Class RouteData
        Implements IInformationData
        Private ReadOnly route_Renamed As New List(Of GeoPoint)()
        Public ReadOnly Property Route() As List(Of GeoPoint)
            Get
                Return route_Renamed
            End Get
        End Property
        Public Event OnDataResponse As EventHandler(Of RequestCompletedEventArgs) Implements IInformationData.OnDataResponse

        Private Function CreateEventArgs() As RequestCompletedEventArgs
            Dim items(2) As MapItem
            items(1) = New MapCallout() With {.Location = route_Renamed(0), .Text = route_Renamed(0).ToString()}
            items(2) = New MapCallout() With {.Location = route_Renamed(route_Renamed.Count - 1), .Text = route_Renamed(route_Renamed.Count - 1).ToString()}
            Dim polyline As New MapPolyline() With {.IsGeodesic = True, .Stroke = System.Drawing.Color.Red, .StrokeWidth = 4}
            Dim i As Integer = 0
            Do While i < route_Renamed.Count
                polyline.Points.Add(route_Renamed(i))
                i += 1
            Loop
            items(0) = polyline
            Return New RequestCompletedEventArgs(items, Nothing, False, Nothing)
        End Function
        Protected Sub RaiseChanged()
            RaiseEvent OnDataResponse(Me, CreateEventArgs())
        End Sub
        Public Sub CalculateRoute(ByVal point1 As GeoPoint, ByVal point2 As GeoPoint)
            CalculateRouteCore(point1, point2)
            RaiseChanged()
        End Sub
        Private Sub CalculateRouteCore(ByVal point1 As GeoPoint, ByVal point2 As GeoPoint)
            Me.route_Renamed.Clear()
            route_Renamed.Add(point1)
            route_Renamed.Add(point2)
        End Sub
    End Class
End Namespace

See Also

IInformationData Members

DevExpress.XtraMap Namespace