Disable/overrule popop FNC maps

Hi,

We have investigated this here, and this involves a little bit of JavaScript, and a custom event handler registration. The sample below is based on TTMSFNCOpenLayers, but you can map this on TTMSFNCMaps as well. It is written in FMX, but you can do something similar in VCL as well.

unit Unit21;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.TMSFNCTypes, FMX.TMSFNCUtils, FMX.TMSFNCGraphics, FMX.TMSFNCGraphicsTypes,
  FMX.TMSFNCCustomControl, FMX.TMSFNCWebBrowser, FMX.TMSFNCMaps,
  FMX.TMSFNCOpenLayers, FMX.Menus;

type
  TForm21 = class(TForm)
    TMSFNCOpenLayers1: TTMSFNCOpenLayers;
    PopupMenu1: TPopupMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    MenuItem3: TMenuItem;
    MenuItem4: TMenuItem;
    procedure TMSFNCOpenLayers1MapInitialized(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TMSFNCOpenLayers1CustomEvent(Sender: TObject;
      AEventData: TTMSFNCMapsEventData);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form21: TForm21;

implementation

{$R *.fmx}

procedure TForm21.TMSFNCOpenLayers1CustomEvent(Sender: TObject;
  AEventData: TTMSFNCMapsEventData);
var
  s: string;
  e: TTMSFNCMapsEventData;
  p: TPointF;
begin
  if AEventData.EventName = 'ContextMenuEvent' then
  begin
    e := TTMSFNCMapsEventData.Create;
    try
      e.JSON := AEventData.CustomData;
      p := TMSFNCOpenLayers1.LocalToScreen(PointF(e.X, e.Y));
      PopupMenu1.Popup(p.X, p.Y);
    finally
      e.Free;
    end;
  end;
end;

procedure TForm21.TMSFNCOpenLayers1MapInitialized(Sender: TObject);
const
  LB = #13#10;
var
  s: string;
begin
  TMSFNCOpenLayers1.EnableContextMenu := False;

  s := 'function customContextMenu() {' + LB +
       '  document.addEventListener("contextmenu", function(e) {' + LB +
       '    var jsonObj = getDefaultEventDataObject();' + LB +
       '    jsonObj["X"] = e.offsetX;' + LB +
       '    jsonObj["Y"] = e.offsetY;' + LB +
       '    var r = {''EventName'': ''ContextMenuEvent''};' + LB +
       '    ' + GETSENDEVENT + '(r, jsonObj);' + LB +
       '  });' + LB +
       '} customContextMenu();';

  TMSFNCOpenLayers1.ExecuteJavascript(s);
end;

end.