Skip to content

Events and clicks ​

From the map to Delphi ​

EventSignatureWhen
OnMapClick(ASender: TObject; ALatLng: TLatLng)The user clicks the map
OnMapRightClick(ASender: TObject; ALatLng: TLatLng)The user right clicks the map
OnMapZoom(ASender: TObject; AZoom: Integer)The zoom changes

ALatLng is the position under the mouse. A right click is the natural place for a menu; the demo pops up a menu that adds a marker where the user clicked, and keeps in sync the zoom field of the form:

pascal
procedure TformMain.OnMapRightClick(ASender: TObject; ALatLng: TLatLng);
begin
  FRightClickLatLng := ALatLng;
  PopupMenu.Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y);
end;

procedure TformMain.mnuAddMarkerClick(Sender: TObject);
begin
  EdgeGoogleMapViewer.PutMarker(FRightClickLatLng, 'Added from right click menu');
end;

procedure TformMain.OnMapZoom(ASender: TObject; AZoom: Integer);
begin
  Zoom.Value := AZoom;
end;

Centre the map where the user clicks, without adding a marker:

pascal
procedure TformMain.OnMapClick(ASender: TObject; ALatLng: TLatLng);
begin
  EdgeGoogleMapViewer.GotoLocation(ALatLng, False);
end;

Around the life of the map ​

EventWhen
BeforeInitMapBefore the browser is initialised: last moment to set things that WebView2 reads at start
BeforeShowMapBefore the map page is built and loaded: the place for the API key if you read it late
AfterHideMapAfter HideMap

Events of the browser ​

The component publishes the events of TEdgeBrowser, among them OnCreateWebViewCompleted, OnNavigationCompleted, OnContainsFullScreenElementChanged, OnNewWindowRequested, OnProcessFailed and OnWebMessageReceived.

OnWebMessageReceived is taken by the component, which uses it for its own messages from the page (click, zoom, map ready). The messages it does not know - the ones your own JavaScript posts, see How it works - arrive in OnWebUnhandledMessageReceived.

Released under the Apache License 2.0