CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Add own Javascript "onclick"

by c.schwoerer » 06 Mar 2018 12:44

Hi,
in the marker events only the "DragEnd" event supports the Lat/Lng position in the browserparams.

I need this in "onclick" too.

1.)
I tried to add the Browserparams like:
Code: Select all
         
          GMap3.JQGMapV3Options.Marker.Events.OnClick.BrowserParams.Clear;
          with GMap3.JQGMapV3Options.Marker.Events.OnClick.BrowserParams.Add do
          begin
            ServerName:= 'Getlatlng';
            //BrowserScript:= 'event.latLng'; // onclick fired but the result is [undefiened]
            //BrowserScript:= 'marker.getPosition().lng()'; // Not working
          end;
          GMap3.JQGMapV3Options.Marker.Events.OnClick.OnEvent:=    MultiMarkerClickEvent;


But I didnt know the right "Browserscript"

2.)
I tried to add Javascript in the map component like this:
Code: Select all
     
      JS:= TIWCGJScript.Create;
      try
        Js.Text:=
        'google.maps.event.addListener(marker, ''click'', function (event) {'+
        '  map.setCenter(event.latLng);'+
        '  map.setZoom(17);'+
        '});';
        GMap3.JQGMapV3Options.Marker.CGJSContainer.AddJavaScriptToAjaxResponse(js.Text);
        //GMap3.JQGMapV3Options.Marker.CGJSContainer.Script:=JS.Text;
      finally
        JS.Free;
      end;


Please bring me on the right way.
c.schwoerer
 
Posts: 18
Joined: 25 Jan 2018 11:09

by Alexander Bulei » 07 Mar 2018 12:21

Hi c.schwoerer,

Please check the following code:

delphi code
procedure TIWMainForm.IWCGAppFormCreate(Sender: TObject);
begin
with IWCGJQGMap31.JQGMapV3Options.Marker.Events.OnClick.BrowserParams.Add do
begin
ServerName:= 'lat';
BrowserScript:= 'event.position.lat()';
end;
with IWCGJQGMap31.JQGMapV3Options.Marker.Events.OnClick.BrowserParams.Add do
begin
ServerName:= 'lng';
BrowserScript:= 'event.position.lng()';
end;

end;

procedure TIWMainForm.IWCGJQGMap31JQGMapV3OptionsMarkerEventsClick(Sender: TObject; AParams: TStringList);
var
Lat, Lng: string;
myFormatSettings: TFormatSettings;
begin
myFormatSettings.DecimalSeparator:= '.';
Lat:= AParams.Values['lat'];
Lng:= AParams.Values['lng'];
WebApplication.ShowMessage( Format('Lat: %s - Lng: %s',[Lat, Lng]) );
IWCGJQGMap31.JQGMapV3Options.Map.Options.Zoom:= 16;
IWCGJQGMap31.JQGMapV3Options.Map.Options.Center.Latitude:= StrToFloat(Lat, myFormatSettings);
IWCGJQGMap31.JQGMapV3Options.Map.Options.Center.Longitude:= StrToFloat(Lng, myFormatSettings);
IWCGJQGMap31.JQGMapV3Options.Map.ApplyProps;
end;


On that code, you will find how to create and pass the browser parameters and also, how to apply the map options (answers for your 2 questions).

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal


Return to JQGMap3

cron

Who is online

Users browsing this forum: No registered users and 2 guests

Contact Us.