diff --git a/Demo/Runtime/GoogleMapsRuntimeTest.dpr b/Demo/Runtime/GoogleMapsRuntimeTest.dpr new file mode 100644 index 0000000..e73d174 --- /dev/null +++ b/Demo/Runtime/GoogleMapsRuntimeTest.dpr @@ -0,0 +1,17 @@ +program GoogleMapsRuntimeTest; + +uses + Forms, + MIdasLib, + MainForm in 'MainForm.pas' {formMain}, + Vcl.GoogleMap in '..\..\Source\Vcl.GoogleMap.pas'; + +{$R *.res} + +begin + Application.Initialize; + Application.Title := 'Delphi with Edge Google Maps Viewer Component Demo'; + Application.MainFormOnTaskbar := True; + Application.CreateForm(TformMain, formMain); + Application.Run; +end. diff --git a/Demo/Runtime/GoogleMapsRuntimeTest.dproj b/Demo/Runtime/GoogleMapsRuntimeTest.dproj new file mode 100644 index 0000000..455eb7e --- /dev/null +++ b/Demo/Runtime/GoogleMapsRuntimeTest.dproj @@ -0,0 +1,926 @@ + + + {89b008d3-2b9c-414e-8323-2a1b0e524f1c} + GoogleMapsRuntimeTest.dpr + Debug + DCC32 + GoogleMapsTest.exe + 20.1 + Debug + True + 3 + Application + VCL + Win32 + GoogleMapsTest + + + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + true + Cfg_2 + true + true + + + true + Cfg_2 + true + true + + + 1033 + Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;Winapi;$(DCC_Namespace) + GoogleMapsRuntimeTest + CompanyName=Ethea S.r.l.;FileDescription=Edge GoogleMap Viewer Demo;FileVersion=1.0.0.0;InternalName=;LegalCopyright=CopyRight (c) 2021 - Ethea S.r.l.;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0;Comments= + GoogleMapsTest.exe + ..\Source;$(DCC_UnitSearchPath) + .\Bin\$(Platform) + true + .\Dcu\$(Platform) + + + $(BDS)\bin\default_app.manifest + System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + GoogleMapsTest_Icon.ico + true + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + PerMonitorV2 + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + + + $(BDS)\bin\default_app.manifest + GoogleMapsTest_Icon.ico + true + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace) + Debug + PerMonitorV2 + CompanyName=Ethea S.r.l.;FileDescription=Edge GoogleMap Viewer Demo;FileVersion=1.0.0.0;InternalName=;LegalCopyright=CopyRight (c) 2021 - Ethea S.r.l.;LegalTrademarks=;OriginalFilename=;ProgramID=;ProductName=;ProductVersion=1.0;Comments= + + + 7.0 + 0 + False + 0 + RELEASE;$(DCC_Define) + + + true + Debug + + + true + CompanyName=Ethea S.r.l.;FileDescription=Edge GoogleMap Viewer Demo;FileVersion=1.0.0.0;InternalName=;LegalCopyright=CopyRight (c) 2021 - Ethea S.r.l.;LegalTrademarks=;OriginalFilename=;ProgramID=;ProductName=;ProductVersion=1.0;Comments= + + + true + 7.0 + DEBUG;$(DCC_Define) + + + Debug + + + true + CompanyName=Ethea S.r.l.;FileDescription=Edge GoogleMap Viewer Demo;FileVersion=1.0.0.0;InternalName=;LegalCopyright=CopyRight (c) 2021 - Ethea S.r.l.;LegalTrademarks=;OriginalFilename=;ProgramID=;ProductName=;ProductVersion=1.0;Comments= + + + Delphi.Personality.12 + VCLApplication + + + + False + True + False + + + False + False + 1 + 0 + 0 + 0 + False + False + False + False + False + 13322 + 1252 + + + + + 1.0.0.0 + + + + + + 1.0.0.0 + + + + GoogleMapsRuntimeTest.dpr + + + + + True + True + + + + + GoogleMapsRuntimeTest.exe + true + + + + + 1 + + + 0 + + + + + classes + 64 + + + classes + 64 + + + + + res\xml + 1 + + + res\xml + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + library\lib\armeabi + 1 + + + library\lib\armeabi + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + library\lib\mips + 1 + + + library\lib\mips + 1 + + + + + library\lib\armeabi-v7a + 1 + + + library\lib\arm64-v8a + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\values + 1 + + + res\values + 1 + + + + + res\values-v21 + 1 + + + res\values-v21 + 1 + + + + + res\values + 1 + + + res\values + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable-xxhdpi + 1 + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-xxxhdpi + 1 + + + res\drawable-xxxhdpi + 1 + + + + + res\drawable-ldpi + 1 + + + res\drawable-ldpi + 1 + + + + + res\drawable-mdpi + 1 + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + res\drawable-xhdpi + 1 + + + + + res\drawable-mdpi + 1 + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + res\drawable-xhdpi + 1 + + + + + res\drawable-xxhdpi + 1 + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-xxxhdpi + 1 + + + res\drawable-xxxhdpi + 1 + + + + + res\drawable-small + 1 + + + res\drawable-small + 1 + + + + + res\drawable-normal + 1 + + + res\drawable-normal + 1 + + + + + res\drawable-large + 1 + + + res\drawable-large + 1 + + + + + res\drawable-xlarge + 1 + + + res\drawable-xlarge + 1 + + + + + res\values + 1 + + + res\values + 1 + + + + + 1 + + + 1 + + + 0 + + + + + 1 + .framework + + + 1 + .framework + + + 1 + .framework + + + 0 + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + 0 + .dll;.bpl + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + 0 + .bpl + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 1 + + + 1 + + + + + + + + Contents\Resources + 1 + + + Contents\Resources + 1 + + + Contents\Resources + 1 + + + + + library\lib\armeabi-v7a + 1 + + + library\lib\arm64-v8a + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 0 + + + + + library\lib\armeabi-v7a + 1 + + + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + + + + 1 + + + 1 + + + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + + + + + + + + + + + + 12 + + + + MainSource + + +
formMain
+
+ + + Base + + + Cfg_1 + Base + + + Cfg_2 + Base + +
+ + + + +
diff --git a/Demo/Runtime/GoogleMapsTest_Icon.ico b/Demo/Runtime/GoogleMapsTest_Icon.ico new file mode 100644 index 0000000..18f949f Binary files /dev/null and b/Demo/Runtime/GoogleMapsTest_Icon.ico differ diff --git a/Demo/Runtime/MainForm.dfm b/Demo/Runtime/MainForm.dfm new file mode 100644 index 0000000..774f695 --- /dev/null +++ b/Demo/Runtime/MainForm.dfm @@ -0,0 +1,276 @@ +object formMain: TformMain + Left = 427 + Top = 268 + Caption = + 'Delphi with Edge Google Maps Viewer Component Demo - Copyright (' + + 'c) Ethea S.r.l.' + ClientHeight = 729 + ClientWidth = 1445 + Color = clBtnFace + Constraints.MinHeight = 550 + Constraints.MinWidth = 890 + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + Position = poScreenCenter + Visible = True + WindowState = wsMaximized + OnCreate = FormCreate + OnDestroy = FormDestroy + OnShow = FormShow + TextHeight = 13 + object PanelHeader: TPanel + Left = 0 + Top = 0 + Width = 1445 + Height = 209 + Align = alTop + TabOrder = 0 + ExplicitWidth = 1441 + object gbMapAttributes: TGroupBox + Left = 1 + Top = 1 + Width = 198 + Height = 207 + Align = alLeft + Caption = 'Map Attributes' + TabOrder = 0 + object lbZoom: TLabel + Left = 135 + Top = 16 + Width = 26 + Height = 13 + Caption = 'Zoom' + end + object Label5: TLabel + Left = 6 + Top = 16 + Width = 51 + Height = 13 + Caption = 'View Mode' + end + object Zoom: TSpinEdit + Left = 135 + Top = 32 + Width = 57 + Height = 22 + MaxValue = 0 + MinValue = 0 + TabOrder = 1 + Value = 15 + OnChange = ZoomChange + end + object MapTypeIdComboBox: TComboBox + Left = 6 + Top = 32 + Width = 126 + Height = 22 + Style = csOwnerDrawFixed + ItemIndex = 0 + TabOrder = 0 + Text = 'ROADMAP' + OnChange = MapTypeIdComboBoxChange + Items.Strings = ( + 'ROADMAP' + 'SATELLITE' + #39'HYBRID' + 'TERRAIN') + end + object cbCenterOnClick: TCheckBox + Left = 6 + Top = 60 + Width = 100 + Height = 17 + Caption = 'Center on click' + TabOrder = 2 + OnClick = CheckBoxStreeViewClick + end + object mapControlGroupBox: TGroupBox + Left = -1 + Top = 79 + Width = 196 + Height = 99 + Caption = 'Map Controls' + TabOrder = 3 + object CheckBoxTraffic: TCheckBox + Left = 7 + Top = 17 + Width = 90 + Height = 17 + Caption = 'Traffic' + TabOrder = 0 + OnClick = CheckBoxTrafficClick + end + object CheckBoxBicycling: TCheckBox + Left = 102 + Top = 17 + Width = 90 + Height = 17 + Caption = 'Bicycling' + TabOrder = 1 + OnClick = CheckBoxBicyclingClick + end + object CheckBoxStreeView: TCheckBox + Left = 7 + Top = 40 + Width = 90 + Height = 17 + Caption = 'Street View' + TabOrder = 2 + OnClick = CheckBoxStreeViewClick + end + object CheckBoxFullScreen: TCheckBox + Left = 7 + Top = 63 + Width = 90 + Height = 17 + Caption = 'Full Screen' + TabOrder = 4 + OnClick = CheckBoxFullScreenClick + end + object CheckBoxZoom: TCheckBox + Left = 102 + Top = 40 + Width = 90 + Height = 17 + Caption = 'Zoom' + TabOrder = 3 + OnClick = CheckBoxZoomClick + end + object CheckBoxMapType: TCheckBox + Left = 102 + Top = 63 + Width = 90 + Height = 17 + Caption = 'Map Type' + TabOrder = 5 + OnClick = CheckBoxMapTypeClick + end + end + end + object GroupBox1: TGroupBox + Left = 199 + Top = 1 + Width = 302 + Height = 207 + Align = alLeft + Caption = 'Location' + TabOrder = 1 + object LabelLongitude: TLabel + Left = 30 + Top = 109 + Width = 47 + Height = 13 + Alignment = taRightJustify + Caption = 'Longitude' + end + object LabelAddress: TLabel + Left = 10 + Top = 14 + Width = 39 + Height = 13 + Caption = 'Address' + end + object LabelLatitude: TLabel + Left = 38 + Top = 79 + Width = 39 + Height = 13 + Alignment = taRightJustify + Caption = 'Latitude' + end + object MemoAddress: TMemo + Left = 10 + Top = 29 + Width = 163 + Height = 44 + Lines.Strings = ( + '') + TabOrder = 0 + end + object ButtonGotoLocation: TButton + Left = 177 + Top = 79 + Width = 99 + Height = 48 + Caption = 'Go to Latitude Lngitude' + TabOrder = 3 + WordWrap = True + OnClick = ButtonGotoLocationClick + end + object Longitude: TEdit + Left = 83 + Top = 106 + Width = 90 + Height = 21 + TabOrder = 4 + end + object ButtonGotoAddress: TButton + Left = 178 + Top = 29 + Width = 99 + Height = 44 + Caption = 'Go to Address' + TabOrder = 1 + OnClick = ButtonGotoAddressClick + end + object Latitude: TEdit + Left = 83 + Top = 79 + Width = 90 + Height = 21 + TabOrder = 2 + end + end + object BottomPanel: TPanel + Left = 1292 + Top = 1 + Width = 152 + Height = 207 + Align = alRight + TabOrder = 2 + object ShowPrintUIButton: TButton + AlignWithMargins = True + Left = 4 + Top = 66 + Width = 144 + Height = 25 + Align = alTop + Caption = 'Show Print UI' + TabOrder = 2 + OnClick = ShowPrintUIButtonClick + ExplicitWidth = 564 + end + object ShowMapButton: TButton + AlignWithMargins = True + Left = 4 + Top = 35 + Width = 144 + Height = 25 + Align = alTop + Caption = 'Show Map' + TabOrder = 1 + OnClick = ShowMapButtonClick + ExplicitWidth = 564 + end + object HideMapButton: TButton + AlignWithMargins = True + Left = 4 + Top = 4 + Width = 144 + Height = 25 + Align = alTop + Caption = 'Hide map' + TabOrder = 0 + OnClick = HideMapButtonClick + ExplicitWidth = 564 + end + end + end + object PopupMenu: TPopupMenu + Left = 416 + Top = 264 + end +end diff --git a/Demo/Runtime/MainForm.pas b/Demo/Runtime/MainForm.pas new file mode 100644 index 0000000..c310578 --- /dev/null +++ b/Demo/Runtime/MainForm.pas @@ -0,0 +1,330 @@ +{ ****************************************************************************** } +{ } +{ Delphi Google Map Viewer Demo } +{ } +{ Copyright (c) 2021-2024 (Ethea S.r.l.) } +{ Author: Carlo Barazzetta } +{ Contributors: } +{ littleearth (https://github.com/littleearth) } +{ chaupero (https://github.com/chaupero) } +{ } +{ https://github.com/EtheaDev/DelphiGoogleMap } +{ } +{ ****************************************************************************** } +{ } +{ Licensed under the Apache License, Version 2.0 (the "License"); } +{ you may not use this file except in compliance with the License. } +{ You may obtain a copy of the License at } +{ } +{ http://www.apache.org/licenses/LICENSE-2.0 } +{ } +{ Unless required by applicable law or agreed to in writing, software } +{ distributed under the License is distributed on an "AS IS" BASIS, } +{ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. } +{ See the License for the specific language governing permissions and } +{ limitations under the License. } +{ } +{ ****************************************************************************** } +unit MainForm; + +interface + +uses + WebView2, System.SysUtils, Winapi.ActiveX, Vcl.Forms, + Vcl.GoogleMap, Vcl.Edge, Data.DB, Datasnap.DBClient, Vcl.Menus, Vcl.ExtCtrls, + Vcl.DBCtrls, Vcl.Grids, Vcl.DBGrids, Vcl.StdCtrls, Vcl.Samples.Spin, + Vcl.Controls, System.Classes, Vcl.Mask, Vcl.ComCtrls, Vcl.Buttons; + +type + TformMain = class(TForm) + PanelHeader: TPanel; + PopupMenu: TPopupMenu; + gbMapAttributes: TGroupBox; + lbZoom: TLabel; + Zoom: TSpinEdit; + Label5: TLabel; + GroupBox1: TGroupBox; + MemoAddress: TMemo; + ButtonGotoLocation: TButton; + Longitude: TEdit; + LabelLongitude: TLabel; + LabelAddress: TLabel; + ButtonGotoAddress: TButton; + LabelLatitude: TLabel; + Latitude: TEdit; + MapTypeIdComboBox: TComboBox; + cbCenterOnClick: TCheckBox; + mapControlGroupBox: TGroupBox; + CheckBoxTraffic: TCheckBox; + CheckBoxBicycling: TCheckBox; + CheckBoxStreeView: TCheckBox; + CheckBoxFullScreen: TCheckBox; + CheckBoxZoom: TCheckBox; + CheckBoxMapType: TCheckBox; + BottomPanel: TPanel; + ShowPrintUIButton: TButton; + ShowMapButton: TButton; + HideMapButton: TButton; + procedure FormCreate(Sender: TObject); + procedure ButtonGotoAddressClick(Sender: TObject); + procedure ButtonGotoLocationClick(Sender: TObject); + procedure CheckBoxTrafficClick(Sender: TObject); + procedure CheckBoxBicyclingClick(Sender: TObject); + procedure CheckBoxStreeViewClick(Sender: TObject); + procedure ButtonClearMarkersClick(Sender: TObject); + procedure ZoomChange(Sender: TObject); + procedure ShowPrintUIButtonClick(Sender: TObject); + procedure ShowMapButtonClick(Sender: TObject); + procedure HideMapButtonClick(Sender: TObject); + procedure MapTypeIdComboBoxChange(Sender: TObject); + procedure FormDestroy(Sender: TObject); + procedure EdgeGoogleMapViewerBeforeShowMap(Sender: TObject); + procedure FormShow(Sender: TObject); + procedure mnuAddMarkerClick(Sender: TObject); + procedure CheckBoxFullScreenClick(Sender: TObject); + procedure CheckBoxZoomClick(Sender: TObject); + procedure EdgeGoogleMapViewerContainsFullScreenElementChanged( + Sender: TCustomEdgeBrowser; + ContainsFullScreenElement: Boolean); + procedure CheckBoxMapTypeClick(Sender: TObject); + procedure btnClearCirclesClick(Sender: TObject); + procedure btnClearPolylinesClick(Sender: TObject); + procedure btnClearPolygonsClick(Sender: TObject); + procedure EdgeGoogleMapViewerViewerReadyWait(ASender : TObject; var AWait : boolean); + private + EdgeGoogleMapViewer: TEdgeGoogleMapViewer; + FRighClickLatLng: TLatLng; + procedure OnMapClick( + ASender: TObject; + ALatLng: TLatLng); + procedure OnMapRightClick( + ASender: TObject; + ALatLng: TLatLng); + procedure OnMapZoom( + ASender: TObject; + AZoom: integer); + public + { Public declarations } + end; + +var + formMain: TformMain; + +implementation + +uses + System.IOUtils, Vcl.Dialogs, System.UITypes; + +{$R *.dfm} + +function B2S(value: Boolean): string; +begin + if value then + Result := 'true' + else + Result := 'false'; +end; + +procedure TformMain.FormCreate(Sender: TObject); +begin + EdgeGoogleMapViewer := TEdgeGoogleMapViewer.Create(Self); + EdgeGoogleMapViewer.Parent := Self; + EdgeGoogleMapViewer.Align := alClient; + EdgeGoogleMapViewer.OnContainsFullScreenElementChanged := + EdgeGoogleMapViewerContainsFullScreenElementChanged; + EdgeGoogleMapViewer.BeforeShowMap := EdgeGoogleMapViewerBeforeShowMap; + EdgeGoogleMapViewer.OnViewerReadyWait := EdgeGoogleMapViewerViewerReadyWait; + + Zoom.value := EdgeGoogleMapViewer.MapZoom; + + EdgeGoogleMapViewer.MapAddress := 'Via Santa Cecilia 4, Carugate, Milano'; + EdgeGoogleMapViewer.MapLatitude := 25.767314; + EdgeGoogleMapViewer.MapLongitude := -80.135694; + + // Init checkboxes based on Component Proprerties + CheckBoxTraffic.Checked := EdgeGoogleMapViewer.MapShowTrafficLayer; + CheckBoxBicycling.Checked := EdgeGoogleMapViewer.MapShowBicyclingLayer; + CheckBoxStreeView.Checked := EdgeGoogleMapViewer.MapShowStreetViewControl; + CheckBoxFullScreen.Checked := EdgeGoogleMapViewer.MapShowFullScreenControl; + CheckBoxZoom.Checked := EdgeGoogleMapViewer.MapShowZoomControl; + CheckBoxMapType.Checked := EdgeGoogleMapViewer.MapShowTypeControl; + + MemoAddress.Lines.Text := EdgeGoogleMapViewer.MapAddress; + Latitude.Text := TEdgeGoogleMapViewer.CoordToText + (EdgeGoogleMapViewer.MapLatitude); + Longitude.Text := TEdgeGoogleMapViewer.CoordToText + (EdgeGoogleMapViewer.MapLongitude); + MapTypeIdComboBox.ItemIndex := Ord(EdgeGoogleMapViewer.MapTypeId); + EdgeGoogleMapViewer.OnMapClick := OnMapClick; + EdgeGoogleMapViewer.OnMapRightClick := OnMapRightClick; + EdgeGoogleMapViewer.OnMapZoom := OnMapZoom; +end; + +procedure TformMain.OnMapClick( + ASender: TObject; + ALatLng: TLatLng); +begin + if cbCenterOnClick.Checked then + begin + EdgeGoogleMapViewer.GotoLocation(ALatLng, False) + end; +end; + +procedure TformMain.OnMapRightClick( + ASender: TObject; + ALatLng: TLatLng); +begin + FRighClickLatLng.Latitude := ALatLng.Latitude; + FRighClickLatLng.Longitude := ALatLng.Longitude; + PopupMenu.Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y); +end; + +procedure TformMain.OnMapZoom( + ASender: TObject; + AZoom: integer); +begin + Zoom.value := AZoom; +end; + +procedure TformMain.FormDestroy(Sender: TObject); +begin + activeoleControl := nil; +end; + +procedure TformMain.FormShow(Sender: TObject); +begin + ButtonGotoAddressClick(Sender); +end; + +procedure TformMain.HideMapButtonClick(Sender: TObject); +begin + EdgeGoogleMapViewer.HideMap; +end; + +procedure TformMain.MapTypeIdComboBoxChange(Sender: TObject); +begin + EdgeGoogleMapViewer.MapTypeId := + TGoogleMapTypeId(MapTypeIdComboBox.ItemIndex); +end; + +procedure TformMain.mnuAddMarkerClick(Sender: TObject); +begin + EdgeGoogleMapViewer.PutMarker(FRighClickLatLng, + 'Added from right click menu'); +end; + +procedure TformMain.ShowPrintUIButtonClick(Sender: TObject); +begin + EdgeGoogleMapViewer.ShowPrintUI; +end; + +procedure TformMain.ShowMapButtonClick(Sender: TObject); +begin + EdgeGoogleMapViewer.GotoAddress(MemoAddress.Lines.Text); +end; + +procedure TformMain.ZoomChange(Sender: TObject); +begin + EdgeGoogleMapViewer.MapZoom := Zoom.value; +end; + +procedure TformMain.ButtonGotoLocationClick(Sender: TObject); +var + Location: TLatLng; +begin + Location.Latitude := TEdgeGoogleMapViewer.TextToCoord(Latitude.Text); + Location.Longitude := TEdgeGoogleMapViewer.TextToCoord(Longitude.Text); + EdgeGoogleMapViewer.GotoLocation(Location); +end; + +procedure TformMain.CheckBoxFullScreenClick(Sender: TObject); +begin + EdgeGoogleMapViewer.MapShowFullScreenControl := CheckBoxFullScreen.Checked; +end; + +procedure TformMain.CheckBoxMapTypeClick(Sender: TObject); +begin + EdgeGoogleMapViewer.MapShowTypeControl := CheckBoxMapType.Checked; +end; + +procedure TformMain.CheckBoxZoomClick(Sender: TObject); +begin + EdgeGoogleMapViewer.MapShowZoomControl := CheckBoxZoom.Checked; +end; + +procedure TformMain.btnClearCirclesClick(Sender: TObject); +begin + EdgeGoogleMapViewer.ClearCircles; +end; + +procedure TformMain.btnClearPolygonsClick(Sender: TObject); +begin + EdgeGoogleMapViewer.ClearPolygons; +end; + +procedure TformMain.btnClearPolylinesClick(Sender: TObject); +begin + EdgeGoogleMapViewer.ClearPolylines; +end; + +procedure TformMain.ButtonClearMarkersClick(Sender: TObject); +begin + EdgeGoogleMapViewer.ClearMarkers; +end; + +procedure TformMain.ButtonGotoAddressClick(Sender: TObject); +begin + EdgeGoogleMapViewer.GotoAddress(MemoAddress.Lines.Text); +end; + +procedure TformMain.CheckBoxStreeViewClick(Sender: TObject); +begin + EdgeGoogleMapViewer.ShowStreetViewControl(CheckBoxStreeView.Checked); +end; + +procedure TformMain.CheckBoxBicyclingClick(Sender: TObject); +begin + EdgeGoogleMapViewer.ShowBicycling(CheckBoxBicycling.Checked); +end; + +procedure TformMain.CheckBoxTrafficClick(Sender: TObject); +begin + EdgeGoogleMapViewer.ShowTraffic(CheckBoxTraffic.Checked); +end; + +procedure TformMain.EdgeGoogleMapViewerBeforeShowMap(Sender: TObject); +begin + if TEdgeGoogleMapViewer.ApiKey = '' then + begin + MessageDlg + ('Error: you must put your Google API Key into TEdgeGoogleMapViewer: change initialization section!', + TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0); + end; +end; + +procedure TformMain.EdgeGoogleMapViewerContainsFullScreenElementChanged( + Sender: TCustomEdgeBrowser; + ContainsFullScreenElement: Boolean); +begin + PanelHeader.Visible := not ContainsFullScreenElement; + BottomPanel.Visible := not ContainsFullScreenElement; +end; + +procedure TformMain.EdgeGoogleMapViewerViewerReadyWait(ASender: TObject; + var AWait: boolean); +begin + AWait := MessageDlg('Edge browser is not ready, continue to wait.',TMsgDlgType.mtCustom,[TMsgDlgBtn.mbYes,TMsgDlgBtn.mbNo],0) = mrYes; +end; + +initialization + +// Setup UserDataFolder for Temp files +TEdgeGoogleMapViewer.RegisterUserDataFolder(System.IOUtils.TPath.GetTempPath + + ExtractFileName(ParamStr(0))); +// If you have a Google API Key it's time to setup +// TEdgeGoogleMapViewer.RegisterGoogleMapsApiKey('xyz'); + +{$WARN SYMBOL_PLATFORM OFF} +ReportMemoryLeaksOnShutdown := DebugHook <> 0; + +end. diff --git a/Source/Vcl.GoogleMap.pas b/Source/Vcl.GoogleMap.pas index 691111c..0b2d75e 100644 --- a/Source/Vcl.GoogleMap.pas +++ b/Source/Vcl.GoogleMap.pas @@ -96,6 +96,7 @@ TLatLng = record TEdgeGoogleMapViewJavascript = procedure(ASender : TObject; var AJavascript : string) of object; TEdgeGoogleMapViewMapClick = procedure(ASender : TObject; ALatLng : TLatLng) of object; TEdgeGoogleMapViewZoomChanged = procedure(ASender : TObject; AZoom : integer) of object; + TEdgeGoogleMapViewerReadyWait =procedure(ASender : TObject; var AWait : boolean) of object; { TEdgeGoogleMapViewer } [ComponentPlatforms(pidWin32 or pidWin64)] @@ -105,6 +106,7 @@ TEdgeGoogleMapViewer = class(TCustomEdgeBrowser) class var FUserDataFolder: string; private FMapIsBusy: boolean; + FInitComplete : boolean; FViewerReady: boolean; FAddress: string; FOverviewMapControl: boolean; @@ -137,7 +139,7 @@ TEdgeGoogleMapViewer = class(TCustomEdgeBrowser) FOnMapClick: TEdgeGoogleMapViewMapClick; FOnMapRightClick: TEdgeGoogleMapViewMapClick; FOnMapZoom: TEdgeGoogleMapViewZoomChanged; - + FOnViewerReadyWait: TEdgeGoogleMapViewerReadyWait; //variables for result functions FDistance: Variant; @@ -185,6 +187,8 @@ TEdgeGoogleMapViewer = class(TCustomEdgeBrowser) procedure SetOnMapClick(const Value: TEdgeGoogleMapViewMapClick); procedure SetOnMapRightClick(const Value: TEdgeGoogleMapViewMapClick); procedure SetOnMapZoom(const Value: TEdgeGoogleMapViewZoomChanged); + procedure WaitUntilInitialized; + procedure SetOnViewerReadyWait(const Value: TEdgeGoogleMapViewerReadyWait); protected procedure Loaded; override; procedure ShowMap(AMapCenter: TLatLng; const AAddress: string = ''); overload; @@ -338,6 +342,7 @@ TEdgeGoogleMapViewer = class(TCustomEdgeBrowser) property OnMapClick : TEdgeGoogleMapViewMapClick read FOnMapClick write SetOnMapClick; property OnMapRightClick : TEdgeGoogleMapViewMapClick read FOnMapRightClick write SetOnMapRightClick; property OnMapZoom : TEdgeGoogleMapViewZoomChanged read FOnMapZoom write SetOnMapZoom; + property OnViewerReadyWait : TEdgeGoogleMapViewerReadyWait read FOnViewerReadyWait write SetOnViewerReadyWait; end; implementation @@ -492,6 +497,7 @@ constructor TEdgeGoogleMapViewer.Create(AOwner: TComponent); Self.UserDataFolder := FUserDataFolder; if WebViewCreated then DefaultScriptDialogsEnabled := False; + FInitComplete := false; FMapVisible := false; FPanControl := true; FZoomControl := true; @@ -871,7 +877,33 @@ function TEdgeGoogleMapViewer.GetHTMLScript : string; end; +procedure TEdgeGoogleMapViewer.WaitUntilInitialized; +var + LLoop: integer; + LWait : boolean; +begin + Sleep(1000); + LLoop := 0; + while (not FViewerReady) and (LLoop < 1000) do + begin + sleep(10); + Application.ProcessMessages; + Inc(LLoop); + end; + if not FViewerReady then + begin + LWait := False; + if Assigned(FOnViewerReadyWait) then + begin + FOnViewerReadyWait(Self,LWait) + end; + if LWait then + begin + WaitUntilInitialized; + end; + end; +end; procedure TEdgeGoogleMapViewer.ShowMap(AMapCenter: TLatLng; const AAddress: string = ''); var @@ -882,11 +914,10 @@ procedure TEdgeGoogleMapViewer.ShowMap(AMapCenter: TLatLng; const AAddress: stri if csDesigning in ComponentState then Exit; - while not FViewerReady do - begin - application.ProcessMessages; - Sleep(10); - end; + if not FInitComplete then + InitMap; + + WaitUntilInitialized; if Assigned(FBeforeShowMap) then FBeforeShowMap(Self); @@ -1064,6 +1095,7 @@ procedure TEdgeGoogleMapViewer.InitMap; Self.UserDataFolder := FUserDataFolder; Self.Navigate(ABOUT_BLANK_PAGE); + FInitComplete := True; end; procedure TEdgeGoogleMapViewer.Loaded; @@ -1226,6 +1258,12 @@ procedure TEdgeGoogleMapViewer.SetOnMapZoom( FOnMapZoom := Value; end; +procedure TEdgeGoogleMapViewer.SetOnViewerReadyWait( + const Value: TEdgeGoogleMapViewerReadyWait); +begin + FOnViewerReadyWait := Value; +end; + procedure TEdgeGoogleMapViewer.SetOnWebUnhandledMessageReceived( const Value: TWebMessageReceivedEvent); begin