vcl-dxazuremapinformationproviders-78bf712c.md
An Azure Maps Route information provider.
TdxMapControlAzureMapRouteProvider = class(
TdxMapControlAzureMapInformationProvider
)
The TdxMapControlAzureMapRouteProvider component connects to Azure Maps Route servers and calculates routes on a map.
To use Microsoft Azure Maps® services, you need to create an Azure Maps account and obtain a key. Assign the account key to the AzureKey property to configure the information provider.
The list below outlines key members of the TdxMapControlAzureMapRouteProvider class. These members allow you to send queries to the Azure Maps Route services and build routes on the map.
AzureKey Required. Specifies the account key required to use the Azure Maps Route service.CancelRequestsCancels pending asynchronous queries to Azure Maps Route servers.CreateQueryParamsCreates an information container required to send a query to an Azure Maps Route server.Execute | ExecuteAsyncSend a query created by a CreateQueryParams function call.OnResponseAllows you to receive and process a server response after an asynchronous query.
CollectionProvides access to the parent collection.DisplayNameSpecifies the information provider’s name displayed in the design-time collection editor dialog.IndexSpecifies the information provider’s index in the parent collection.IDReturns the component’s unique identifier.
TdxMapControlAzureMapGeocodeProviderAn Azure Maps Geocode information provider.TdxMapControlAzureMapGeolocationProviderAn Azure Maps Geolocation information provider.TdxMapControlAzureMapReverseGeocodeProviderAn Azure Maps Reverse Geocode information provider.
The following code example implements a procedure that accepts an Azure Maps account key, and creates and configures all Azure Maps information provider components:
uses
dxAzureMapInformationProviders; // Declares all Azure Maps information provider classes
// ...
procedure TMyForm.CreateAzureMapsInformationProviders(const AAzureKey: string);
var
AProviders: TdxMapControlInformationProviders;
AProvider: TdxMapControlAzureMapInformationProvider;
I: Integer;
begin
AProviders := dxMapControl1.InformationProviders;
AProviders.BeginUpdate; // Initiates the following batch change
try
// Create all Azure Maps information providers
AProviders.Add(TdxMapControlAzureMapGeocodeProvider);
AProviders.Add(TdxMapControlAzureMapGeolocationProvider);
AProviders.Add(TdxMapControlAzureMapReverseGeocodeProvider);
AProviders.Add(TdxMapControlAzureMapRouteProvider);
for I := 0 to AProviders.Count - 1 do // Iterates through all created information providers
begin
AProvider := AProviders.Items[I] as TdxMapControlAzureMapInformationProvider;
AProvider.AzureKey := AAzureKey; // Assigns the same Azure Maps account key to all providers
end;
finally
AProviders.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
end;
end;
#include "dxAzureMapInformationProviders.hpp" // Declares all Azure Maps information provider classes
// ...
void __fastcall TMyForm::CreateAzureMapsInformationProviders(const UnicodeString &AAzureKey)
{
TdxMapControlInformationProviders *AProviders;
TdxMapControlAzureMapInformationProvider *AProvider;
AProviders = dxMapControl1->InformationProviders;
AProviders->BeginUpdate(); // Initiates the following batch change
try
{
// Create all Azure Maps information providers
AProviders->Add(__classid(TdxMapControlAzureMapGeocodeProvider));
AProviders->Add(__classid(TdxMapControlAzureMapGeolocationProvider));
AProviders->Add(__classid(TdxMapControlAzureMapReverseGeocodeProvider));
AProviders->Add(__classid(TdxMapControlAzureMapRouteProvider));
for(int i = 0; i < AProviders->Count; i++) // Iterates through all created information providers
{
AProvider = dynamic_cast<TdxMapControlAzureMapInformationProvider*>(AProviders->Items[i]);
AProvider->AzureKey = AAzureKey; // Assigns the same Azure Maps account key to all providers
}
}
__finally
{
AProviders->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
}
}
The following code example uses a configured information provider to draw a route between two specified points on a map:
uses
dxAzureMapInformationProviders, // Declares TdxMapControlAzureMapRouteProvider
dxCoreGraphics; // Declares TdxAlphaColors
// ...
procedure TMyForm.DrawMapRoute(ARouteStart, ARouteEnd: TdxMapControlGeoPoint);
var
APolyline: TdxMapPolyline;
ARoute: TdxAzureMapRouteItem;
AParams: IdxAzureMapRouteQueryParams;
AResponse: TdxAzureMapRouteRequestResponse;
ARouteWaypoints: TdxMapControlGeoPoints;
I, J: Integer;
begin
AParams := dxMapControl1AzureMapRouteProvider1.CreateQueryParams;
SetLength(ARouteWaypoints, 2);
ARouteWaypoints[0] := ARouteStart;
ARouteWaypoints[1] := ARouteEnd;
AParams.WayPoints := ARouteWaypoints;
AParams.TravelMode := TdxAzureMapRouteTravelMode.Car;
AParams.MaxAlternatives := 1;
dxMapControl1AzureMapRouteProvider1.Execute(AParams, AResponse);
dxMapControl1.BeginUpdate; // Initiates the following batch change
try
if AResponse <> nil then
begin
if AResponse.IsSuccess then // Draws a route if a valid server response is received
begin
APolyline := dxMapControl1ItemLayer1.AddItem(TdxMapPolyline) as TdxMapPolyline;
ARoute := AResponse.Routes.Items[0]; // Selects the first returned route
for I := 0 to ARoute.Legs.Count - 1 do
for J := 0 to ARoute.Legs.Items[I].Points.Count - 1 do
APolyline.GeoPoints.Add.GeoPoint := ARoute.Legs.Items[I].Points.Items[J];
APolyline.Style.BorderWidth := 4;
APolyline.Style.BorderColor := TdxAlphaColors.DarkBlue;
end;
end;
finally
dxMapControl1.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
end;
end;
#include "dxAzureMapInformationProviders.hpp" // Declares TdxMapControlAzureMapRouteProvider
#include "dxCoreGraphics.hpp" // Declares TdxAlphaColors
// ...
void __fastcall TMyForm::ValidateServerResponse(TdxMapControlGeoPoint *ARouteStart,
TdxMapControlGeoPoint *ARouteEnd)
{
TdxMapItem *AMapItem;
TdxMapPolyline *APolyline;
TdxAzureMapRouteItem *ARoute;
_di_IdxAzureMapRouteQueryParams AParams;
TdxAzureMapRouteRequestResponse *AResponse;
TdxMapControlGeoPoints *ARouteWaypoints;
AParams = dxMapControl1AzureMapRouteProvider1->CreateQueryParams();
SetLength(ARouteWaypoints, 2);
ARouteWaypoints[0] = ARouteStart;
ARouteWaypoints[1] = ARouteEnd;
AParams->WayPoints = ARouteWaypoints;
AParams->TravelMode = TdxAzureMapRouteTravelMode::Car;
AParams->MaxAlternatives = 1;
dxMapControl1AzureMapRouteProvider1->Execute(AParams, AResponse);
dxMapControl1->BeginUpdate(); // Initiates the following batch change
try
{
if(AResponse != nullptr)
{
if(AResponse->IsSuccess) // Draws a route if a valid server response is received
{
AMapItem = dxMapControl1ItemLayer1->AddItem(__classid(TdxMapPolyline));
APolyline = dynamic_cast<TdxMapPolyline*>(AMapItem);
ARoute = AResponse->Routes->Items[0]; // Selects the first returned route
for(int i = 0; i < ARoute->Legs->Count; i++)
for(int j = 0; j < ARoute->Legs->Items[i]->Points->Count; j++)
APolyline->GeoPoints->Add()->GeoPoint = ARoute->Legs->Items[i]->Points->Items[j];
APolyline->Style->BorderWidth = 4;
APolyline->Style->BorderColor = TdxAlphaColors::DarkBlue;
}
}
}
__finally
{
dxMapControl1->EndUpdate(); // Calls EndUpdate regardless of tha batch operation's success
}
}
The following public API members reference the TdxMapControlAzureMapRouteProvider class as a TdxMapControlInformationProvider object:
TdxMapControlInformationProviders.AddCreates an auxiliary map information provider of the required type and adds the provider to the collection.TdxMapControlInformationProviders.ItemsProvides indexed access to stored map information provider components.
The TdxMapControlInformationProviderClass references the TdxMapControlAzureMapRouteProvider class.
To see Microsoft Azure Map tile and information providers in action, run the Mapping demo in the VCL Demo Center installed with compiled DevExpress demos. When the demo is opened, it downloads tile data and additional information from Azure Map servers to display a map and build routes between specified points.
Tip
Compiled DevExpress demos ship with source code installed in the Public Documents folder (%Public%) for all users ( default ). You can find all project and source code files for the Map Control demo in the following folder:
%Public%\Documents\DevExpress VCL Demos\MegaDemos\Product Demos\ExpressMapControl
TObject TPersistent TComponent TcxCustomComponent TcxComponentCollectionItem TdxMapControlInformationProvider TdxMapControlAzureMapInformationProvider TdxMapControlAzureMapRouteProvider
See Also
TdxMapControlAzureMapImageryDataProvider Class