|
22 | 22 |
|
23 | 23 | //Setting Map View Mode
|
24 | 24 | EdgeGoogleMapViewer.MapTypeId := TGoogleMapTypeId(MapTypeIdComboBox.ItemIndex);
|
25 |
| - |
26 | 25 | ```
|
| 26 | + |
| 27 | +## How it works |
| 28 | + |
| 29 | +The component works in a simple way: creates an html file with some javascript functions inside it and load it from disk, so the Delphi component can call those javascript functions inside the component methods, calling ExecuteScript(ScriptCommand) method of the TEdgeBrowser. If you want to analyse the content of the file created, put a break-point into TEdgeGoogleMapViewer.ShowMap at this line to know the name of the file created: |
| 30 | + |
| 31 | +```pascal |
| 32 | +NavigateToURL('file:///'+LFileName); |
| 33 | +``` |
| 34 | +If you want to see how the component calls a javascript function inside the page, look for example at the method "GotoAddress": |
| 35 | + |
| 36 | +```pascal |
| 37 | +procedure TEdgeGoogleMapViewer.GotoAddress(const Address: string); |
| 38 | +var |
| 39 | + ScriptCommand: String; |
| 40 | +begin |
| 41 | + FAddress := Address; |
| 42 | + if FAddress = '' then |
| 43 | + HideMap |
| 44 | + else if not MapVisible then |
| 45 | + ShowMap(FAddress) |
| 46 | + else |
| 47 | + begin |
| 48 | + ScriptCommand := Format('codeAddress(%s)',[QuotedStr(ClearAddressText(Address))]); |
| 49 | + ExecuteScript(ScriptCommand); |
| 50 | + end; |
| 51 | +end; |
| 52 | +``` |
| 53 | +You can extend the component with any functionality you can execute at javascipt level, adding the function into the code, in the method "GetHTMLScript" that collect all the Javascript functions, or you can add your personal javascript code in the event "OnGetJavascript". |
| 54 | + |
| 55 | +```pascal |
| 56 | +function TEdgeGoogleMapViewer.GetHTMLScript : string; |
| 57 | +var |
| 58 | + LJSScript : string; |
| 59 | +begin |
| 60 | + LJSScript := GetJSVariables +sLineBreak+ |
| 61 | + GetJSInitialize +sLineBreak+ |
| 62 | + (...) |
| 63 | + GetJSRouteAddress + sLineBreak + |
| 64 | + GetJSCalcRoute; |
| 65 | + if Assigned(FOnGetJavascript) then |
| 66 | + FOnGetJavascript(Self,LJSScript); |
| 67 | + Result := |
| 68 | + '<script type="text/javascript"> '+sLineBreak+ |
| 69 | + LJSScript + sLineBreak + |
| 70 | + '</script> '+ sLineBreak; |
| 71 | +end; |
| 72 | +``` |
| 73 | + |
| 74 | +Look at the [GoogleAPI documentation](https://developers.google.com/maps/documentation/javascript?hl=it) if you need more functionality and please make a pull request to the project. |
| 75 | + |
27 | 76 | ## A complete demo is available!
|
28 | 77 |
|
29 | 78 | Notice that in the same folder of the executable you must place the correct webview2loader.dll (32 or 64 bit) as you can see into Demo\GoogleMaps\Bin\Win32 and Demo\GoogleMaps\Bin\Win64.
|
|
0 commit comments