Back to Devexpress

TdxMapPushpin Class

vcl-dxmapitem-77c800b4.md

latest5.8 KB
Original Source

TdxMapPushpin Class

A map pushpin.

Declaration

delphi
TdxMapPushpin = class(
    TdxMapPointer
)

Remarks

A map pushpin marks a point on a map. Map pushpins can display a label, image, and hint.

Main API Members

The list below outlines key members of the TdxMapPushpin class. These members allow you to position a pushpin on a map item layer.

Appearance Settings

Style | StyleHot | StyleSelectedSpecify map pushpin appearance settings in different states.

Content Settings

Hint | ScreenTipAllow you to assign a hint or ScreenTip to the map pushpin.Image | ImageOriginAllow you to load and position an image within the map pushpin.LocationSpecifies the pushpin position on the map.TextSpecifies the pushpin caption.

General-Purpose API Members

AttributesAllows you to associate the pushpin with custom values.SelectedSpecifies if the map pushpin is selected.VisibleSpecifies if the map pushpin is visible.

Map Pushpin Creation

To create a map pushpin, you can call one of the following functions of a map item layer and pass a reference to the TdxMapPushpin class as a parameter:

AddItemCreates a map item of a specified type and appends it to the layer’s MapItems collection.MapItems.AddCreates a map item of the required type and adds the item to the collection.

Code Example: Display a Map Point Address as a Hint

The following code example implements a procedure that uses a configured information provider component to create a pushpin at the specified point on the map and assign the point’s address to the pushpin hint:

delphi
uses
  dxAzureMapInformationProviders; // Declares TdxMapControlAzureMapReverseGeocodeProvider
// ...

procedure TMyForm.AddPushpin(AGeoPoint: TdxMapControlGeoPoint);
var
  APushpin: TdxMapPushpin;
  AParams: IdxAzureMapReverseGeocodeQueryParams;
  AResponse: TdxAzureMapReverseGeocodeRequestResponse;
begin
  // Creates a new pushpin on an existing map item layer
  APushpin := dxMapControl1ItemLayer1.MapItems.Add(TdxMapPushpin) as TdxMapPushpin;
  APushpin.Location.GeoPoint := AGeoPoint;
  AParams := dxMapControl1AzureMapReverseGeocodeProvider1.CreateQueryParams;
  AParams.Coordinates := APushpin.Location.GeoPoint;
  // Uses a configured reverse geocode provider to send a query to an Azure Maps server
  dxMapControl1AzureMapReverseGeocodeProvider1.Execute(AParams, AResponse);
  try
    if AResponse <> nil then // Checks if a server response is received
    begin
      if AResponse.IsSuccess and (AResponse.Features.Count > 0) then // Checks if the query is successful
        APushpin.Hint := AResponse.Features.First.Properties.Address.FormattedAddress;
    end;
  finally
    AResponse.Free; // Deletes the query result regardless of the operation's success 
  end;
end;
cpp
#include "dxAzureMapInformationProviders.hpp" // Declares TdxMapControlAzureMapReverseGeocodeProvider
// ...

void __fastcall TMyForm::AddPushpin(TdxMapControlGeoPoint *AGeoPoint)
{
  TdxMapPushpin *APushpin;
  _di_IdxAzureMapReverseGeocodeQueryParams AParams;
  TdxAzureMapReverseGeocodeRequestResponse *AResponse;

  // Creates a new pushpin on an existing map item layer
  APushpin = dynamic_cast<TdxMapPushpin*>(dxMapControl1ItemLayer1->MapItems->Add(__classid(TdxMapPushpin)));
  APushpin->Location->GeoPoint = AGeoPoint;
  AParams = dxMapControl1AzureMapReverseGeocodeProvider1->CreateQueryParams();
  AParams->Coordinates = APushpin->Location->GeoPoint;
  // Uses a configured reverse geocode provider to send a query to an Azure Maps server
  dxMapControl1AzureMapReverseGeocodeProvider1->Execute(AParams, AResponse);
  try
  {
    if(AResponse != nullptr) // Checks if a server response is received
    {
      if((AResponse->IsSuccess) && (AResponse->Features->Count > 0)) // Checks if the query is successful
        APushpin->Hint = AResponse->Features->First()->Properties->Address->FormattedAddress;
    }
  }
  __finally
  {
    delete AResponse; // Deletes the query result response regardless of the operation's success
  }
}

Inheritance

TObject TPersistent TComponent TcxCustomComponent TcxComponentCollectionItem TdxMapItem TdxMapSinglePointItem TdxMapPointer TdxMapPushpin

See Also

TdxMapDot Class

TdxMapPushpin Members

dxMapItem Unit