Hi,
I'd like to present a context menu upon right click within a map. I have tried to use onContextPopop, PopupMenu etc. But I am only presented a context menu from Edge which provides options to save the image etc. I have tried to find switches within Map/OpenLayers options and also investigated if I can implement the behaviour by using onMapClick/OnMarkerClick and detect if the right mouse button was used, but I fail in obtaining the event data which would tell me which mouse button was used.
Is there something I am missing? THanks for the support!
Hi Pieter,
thanks! For others being potentially interested in some point in time: Here's my slightly changed code for the custom event in VCL, with which I got it to work.
procedure TMainForm.TMSFNCOpenLayers1CustomEvent(Sender: TObject;
AEventData: TTMSFNCMapsEventData);
var
s: string;
e: TTMSFNCMapsEventData;
p: TPoint;
begin
if AEventData.EventName = 'ContextMenuEvent' then
begin
e := TTMSFNCMapsEventData.create;
try
e.JSON := AEventData.CustomData;
p := TMSFNCOpenLayers1.ClientToScreen(TPoint.create(trunc(e.X),
trunc(e.Y)));
PopupMenu1.Popup(p.X, p.Y);
finally
e.Free;
end;
end;
end;
@Pieter_Scheldeman : A further question in this direction - i'd like the context menu to actually only react on markers. Is there also a way to achieve this? I don't appear to be able to hook into the OnMarkerClick event.
Hi Bart,
thanks! I am afraid I need to use OpenLayers because I need to use a rather new feature of yours, which is only implemented in openlayers as I understand: support for WMS layers.
Also I am not sure If that would work anyway respectively I don't understand why. I don't get the connection between the code provided in MapInitialized and the "onCustumEvent" Event. Is it a general mechanism that code I provide via MapInitialized is hooked up with "onCustomEvent"? At least it didn't work when linking the code from custom event to events like "onMarkerClick". My assumption would be that I would have to do something about the javascript code to have the event handler react to right clicks on markers to invoke context menus...? But I am not sure.