We like to add MouseHints (HTML would be great) to the Map Marker on the Google Map - is this possible? how?
TIA
Yes Marker mouse hints are supported in TTMSFNCGoogleMaps.
There are two possible techniques to add hints on a Marker.
- Simple Marker mouse hint (no HTML support)
TMSFNCGoogleMaps1.AddMarker(TMSFNCGoogleMaps1.Options.DefaultLatitude, TMSFNCGoogleMaps1.Options.DefaultLongitude, 'Marker Title');
- Marker OverlayView (with HTML support)
Please note that a Marker OverlayView is always visible by default.
You can toggle the visibility with the Visible property in the MarkerMouseEnter and MarkerMouseLeave events to simulate the behaviour of a mouse hint.
procedure TForm1.Button1Click(Sender: TObject);
var
m: TTMSFNCGoogleMapsMarker;
begin
m := TMSFNCGoogleMaps1.AddMarker(TMSFNCGoogleMaps1.Options.DefaultLatitude, TMSFNCGoogleMaps1.Options.DefaultLongitude);
m.AddOverlayView('<b>Marker Overlay</b>');
m.OverlayView.Visible := False;
end;
procedure TForm1.TMSFNCGoogleMaps1MarkerMouseEnter(Sender: TObject;
AEventData: TTMSFNCMapsEventData);
var
o: TTMSFNCGoogleMapsOverlayView;
begin
o := TTMSFNCGoogleMapsMarker(AEventData.Marker).OverlayView;
if Assigned(o) then
o.Visible := True;
end;
procedure TForm1.TMSFNCGoogleMaps1MarkerMouseLeave(Sender: TObject;
AEventData: TTMSFNCMapsEventData);
var
o: TTMSFNCGoogleMapsOverlayView;
begin
o := TTMSFNCGoogleMapsMarker(AEventData.Marker).OverlayView;
if Assigned(o) then
o.Visible := False;
end;
1 Like
There is also a third possible technique by using Popups:
unit Unit29;
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.Controls.Presentation, FMX.StdCtrls, FMX.TMSFNCCustomControl,
FMX.TMSFNCWebBrowser, FMX.TMSFNCMaps, FMX.TMSFNCGoogleMaps, Generics.Collections;
type
TMarkerPopupInfo = class
private
FID: string;
FInfo: string;
FVisible: Boolean;
public
constructor Create(AInfo: string);
property Info: string read FInfo write FInfo;
property ID: string read FID write FID;
property Visible: Boolean read FVisible write FVisible;
end;
TMarkerPopupInfoList = class(TObjectList<TMarkerPopupInfo>);
TForm29 = class(TForm)
TMSFNCGoogleMaps1: TTMSFNCGoogleMaps;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure TMSFNCGoogleMaps1MarkerMouseEnter(Sender: TObject;
AEventData: TTMSFNCMapsEventData);
procedure TMSFNCGoogleMaps1MarkerMouseLeave(Sender: TObject;
AEventData: TTMSFNCMapsEventData);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
mil: TMarkerPopupInfoList;
public
{ Public declarations }
end;
var
Form29: TForm29;
implementation
{$R *.fmx}
uses
FMX.TMSFNCMapsCommonTypes;
procedure TForm29.Button1Click(Sender: TObject);
var
m: TTMSFNCGoogleMapsMarker;
mi: TMarkerPopupInfo;
begin
TMSFNCGoogleMaps1.BeginUpdate;
m := TMSFNCGoogleMaps1.AddMarker(DefaultCoordinate);
mi := TMarkerPopupInfo.Create('My <span style="background-color:red">HTML</span> formatted <i>text</i> <b>hint</b>');
mil.Add(mi);
m.DataObject := mi;
TMSFNCGoogleMaps1.EndUpdate;
end;
procedure TForm29.FormCreate(Sender: TObject);
begin
mil := TMarkerPopupInfoList.Create;
ReportMemoryLeaksOnShutdown := True;
end;
procedure TForm29.FormDestroy(Sender: TObject);
begin
mil.Free;
end;
procedure TForm29.TMSFNCGoogleMaps1MarkerMouseEnter(Sender: TObject;
AEventData: TTMSFNCMapsEventData);
var
mi: TMarkerPopupInfo;
begin
mi := TMarkerPopupInfo(AEventData.Marker.DataObject);
if not mi.Visible then
begin
mi.Visible := True;
mi.ID := TMSFNCGoogleMaps1.ShowPopup(AEventData.Marker.Coordinate.ToRec, mi.Info, 0, -40);
end;
end;
procedure TForm29.TMSFNCGoogleMaps1MarkerMouseLeave(Sender: TObject;
AEventData: TTMSFNCMapsEventData);
var
mi: TMarkerPopupInfo;
begin
mi := TMarkerPopupInfo(AEventData.Marker.DataObject);
if mi.Visible then
begin
mi.Visible := False;
TMSFNCGoogleMaps1.ClosePopup(mi.ID);
end;
end;
{ TMarkerPopupInfo }
constructor TMarkerPopupInfo.Create(AInfo: string);
begin
FInfo := AInfo;
FID := '';
FVisible := False;
end;
end.
1 Like
This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.