Back to Devexpress

TdxMapLayers.Add(TdxMapLayerClass) Method

vcl-dxmaplayer-dot-tdxmaplayers-dot-add-x28-dxmaplayer-dot-tdxmaplayerclass-x29.md

latest4.9 KB
Original Source

TdxMapLayers.Add(TdxMapLayerClass) Method

Creates a map layer of the required type and adds the layer to the collection.

Declaration

delphi
function Add(AItemClass: TdxMapLayerClass): TdxMapLayer;

Parameters

NameTypeDescription
AItemClassTdxMapLayerClass

The reference to the required map layer class.

|

Returns

TypeDescription
TdxMapLayer

The created map layer.

To access all public API members of the created map layer, cast the returned object to the corresponding terminal TdxMapLayer class descendant (AItemClass).

|

Remarks

Call the Add function to create any supported map layer and add it to the end of the collection. Map layer indexes determine the Z-order (draw order) of corresponding map layers. A map layer with the highest index is displayed on top of all other layers.

All created map layers are accessible through the Items property. You can use an individual map layer’s Index property to change the layer’s draw order.

Code Example: Add a Tile Map Layer and Load Azure Maps Data

The following code example implements a procedure that accepts an Azure Maps account key, creates and configures a map tile layer, and loads data:

delphi
uses
  dxAzureMapImageryDataProvider; // Declares TdxMapControlAzureMapImageryDataProvider
// ...

procedure TMyForm.AddAzureMapLayer(const AAzureKey: string);
var
  ATileLayer: TdxMapImageTileLayer;
  AProvider: TdxMapControlAzureMapImageryDataProvider;
begin
  ATileLayer := dxMapControl1.Layers.Add(TdxMapImageTileLayer) as TdxMapImageTileLayer;
  ATileLayer.ProviderClass := TdxMapControlAzureMapImageryDataProvider;
  AProvider := ATileLayer.Provider as TdxMapControlAzureMapImageryDataProvider;
  AProvider.BeginUpdate; // Initiates the following batch change
  try
    AProvider.AzureKey := AAzureKey; // Assigns the Azure account key
    AProvider.Tileset := TdxAzureMapTileset.Satellite; // Changes the default tileset
    AProvider.MaxParallelConnectionCount := 8; // Explicitly defines the number of parallel connections
  finally
    AProvider.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
  end;
end;
cpp
#include "dxAzureMapImageryDataProvider.hpp" // Declares TdxMapControlAzureMapImageryDataProvider
// ...

void __fastcall TMyForm::AddAzureMapLayer(const UnicodeString &AAzureKey)
{
  TdxMapLayer *ALayer;
  TdxMapImageTileLayer *ATileLayer;
  TdxMapControlAzureMapImageryDataProvider *AProvider;

  ALayer = dxMapControl1->Layers->Add(__classid(TdxMapImageTileLayer));
  ATileLayer = dynamic_cast<TdxMapImageTileLayer*>(ALayer);
  ATileLayer->ProviderClass = __classid(TdxMapControlAzureMapImageryDataProvider);
  AProvider = dynamic_cast<TdxMapControlAzureMapImageryDataProvider*>(ATileLayer->Provider);
  AProvider->BeginUpdate(); // Initiates the following batch change
  try
  {
    AProvider->AzureKey = AAzureKey; // Assigns the Azure account key
    AProvider->Tileset = TdxAzureMapTileset::Satellite; // Changes the default tileset
    AProvider->MaxParallelConnectionCount = 8; // Explicitly defines the number of parallel connections
  }
  __finally
  {
    AProvider->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
  }
}

Type-Specific Map Layer Creation Methods

Alternatively, you can call the following functions of the Map Control to create corresponding map layers:

TdxCustomMapControl.AddImageTileLayerCreates a new image tile layer and adds it to the map layer collection.TdxCustomMapControl.AddItemFileLayerCreates a new item file layer and adds it to the map layer collection.TdxCustomMapControl.AddItemLayerCreates a new item layer. See Also

TdxMapControlInformationProviders.Add Function

TdxMapLayers Class

TdxMapLayers Members

dxMapLayer Unit