From c0be7c001375f73e2c3b49a1b1d447b6fc297bdd Mon Sep 17 00:00:00 2001 From: duheng <2286773002@qq.com> Date: 星期五, 21 三月 2025 13:43:00 +0800 Subject: [PATCH] Merge branch 'master' of http://47.103.154.90:83/r/HStation/XHS.V1.0 --- WinFrmUI/PBS.WinFrmUI.Hydro/02-quick-modeling/02-place/QuickModelingPlaceWizardPage.cs | 238 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 221 insertions(+), 17 deletions(-) diff --git a/WinFrmUI/PBS.WinFrmUI.Hydro/02-quick-modeling/02-place/QuickModelingPlaceWizardPage.cs b/WinFrmUI/PBS.WinFrmUI.Hydro/02-quick-modeling/02-place/QuickModelingPlaceWizardPage.cs index 5aab912..1406762 100644 --- a/WinFrmUI/PBS.WinFrmUI.Hydro/02-quick-modeling/02-place/QuickModelingPlaceWizardPage.cs +++ b/WinFrmUI/PBS.WinFrmUI.Hydro/02-quick-modeling/02-place/QuickModelingPlaceWizardPage.cs @@ -1,4 +1,6 @@ -锘縩amespace PBS.WinFrmUI.Hydro +锘縰sing Microsoft.Web.WebView2.Core; + +namespace PBS.WinFrmUI.Hydro { public partial class QuickModelingPlaceWizardPage : DevExpress.XtraEditors.XtraUserControl, IWizardPageAsync<QuickModelingViewModel> { @@ -6,9 +8,7 @@ { InitializeComponent(); this.layoutControl1.SetupLayoutControl(); - this.mapSetSimpleMarkerContainer1.LoadCompletedEvent += MapSetSimpleMarkerContainer1_LoadCompletedEvent; - this.mapSetSimpleMarkerContainer1.SetMarkerEvent += MapSetSimpleMarkerContainer1_SetMarkerEvent; - this.imgCmbPlaceType.Properties.AddEnum<PBS.ePlaceType>(); + this.imgCmbPlaceType.Properties.AddEnum<PBS.ePlaceType>(); } /// <summary> @@ -18,7 +18,7 @@ private QuickModelingViewModel _vm = null;//鎿嶄綔瀵硅薄 private bool _isCompleted = false;//鏄惁鍒涘缓瀹屾垚 - + private bool _isInitialMap = false;//鏄惁鍒濆鍖栧湴鍥� /// <summary> @@ -33,9 +33,10 @@ _vm = vm; _isCompleted = false; - if (!this.mapSetSimpleMarkerContainer1.IsInitialized) + if (!_isInitialMap) { - await this.mapSetSimpleMarkerContainer1.InitialContainer(); + this.webView.Source = new Uri(AppDomain.CurrentDomain.BaseDirectory + "/web/html/map_select.html"); + this.webView.WebMessageReceived += WebView_WebMessageReceived; } this.txtName.EditValue = _vm.Place.Name; @@ -51,22 +52,220 @@ this.PageStateChangedEvent?.Invoke(); } - - //鍔犺浇瀹屾垚浜嬩欢 - private async void MapSetSimpleMarkerContainer1_LoadCompletedEvent() + public class AmapLocationViewModel { - if (_vm.Marker != null) + public AmapLocationViewModel() { - await this.mapSetSimpleMarkerContainer1.LoadMarker(_vm.Marker); + location = new Location(); + } + public string id { get; set; } + public string name { get; set; } + public string address { get; set; } + public Location location { get; set; } + public long BuildTypeID { get; set; } + public string NorthEast { get; set; } + public string SouthWest { get; set; } + + } + public class FixationReceivedViewModel + { + public string Oper { get; set; } + + public string Json { get; set; } + } + + public new class Location + { + public float lng { get; set; } + public float lat { get; set; } + } + + public class Coordinate + { + public Coordinate(double lat, double lon) + { + this.lat = lat; + this.lon = lon; + } + /// <summary> + /// 绾害 + /// </summary> + public double lat { get; set; } + /// <summary> + /// 缁忓害 + /// </summary> + public double lon { get; set; } + } + + + public static class AmapBounds + { + public static double Distance(Coordinate coordinate1, Coordinate coordinate2) + { + var a = coordinate1; + var lat1 = a.lat; + var lon1 = a.lon; + var b = coordinate2; + var lat2 = b.lat; + var lon2 = b.lon; + + if (lat1 == lat2 && lon1 == lon2) + { + return 0; + } + + a.lon = VC(a.lon, -180, 180); + a.lat = aD(a.lat, -74, 74); + b.lon = VC(b.lon, -180, 180); + b.lat = aD(b.lat, -74, 74); + double ret; + ret = JF(JK(a.lon), JK(b.lon), JK(a.lat), JK(b.lat)); + return ret; + } + public static double aD(double a, double b, double c) + { + if (b != null) + { + a = Math.Max(a, b); + } + if (b != null) + { + a = Math.Min(a, c); + } + return a; + } + public static double VC(double a, double b, double c) + { + if (a > c) + { + a -= c - b; + } + if (a < b) + { + a += c - b; + } + return a; + } + public static double JK(double a) + { + double ret = Math.PI * a / 180.0; + return ret; + } + public static double JF(double a, double b, double c, double e) + { + const double Ou = 6370996.81; + return Ou * Math.Acos(Math.Sin(c) * Math.Sin(e) + Math.Cos(c) * Math.Cos(e) * Math.Cos(b - a)); } } - //璁剧疆 - private void MapSetSimpleMarkerContainer1_SetMarkerEvent(Yw.Model.Map.Marker obj) + private async void CaptureImage() { - _vm.Marker = obj; - this.txtAddress.EditValue = obj.Address; + await webView.EnsureCoreWebView2Async(); + CoreWebView2 coreWebView = webView.CoreWebView2; + int pageWidth = webView.ClientSize.Width; + int pageHeight = webView.ClientSize.Height; + webView.Width = pageWidth; + webView.Height = pageHeight; + + var directory = Path.GetDirectoryName(_vm.tempBackgroundImageUrl); + if (!Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } + var fileStream = new FileStream(_vm.tempBackgroundImageUrl + "_t.png", FileMode.Create); + await coreWebView.CapturePreviewAsync(CoreWebView2CapturePreviewImageFormat.Png, fileStream); + var bt = new Bitmap(fileStream); + var pWidth = pageWidth - 50; + var pHeight = pageHeight - 50; + try + { + bt.Clone(new Rectangle(50, 50, pWidth, pHeight), System.Drawing.Imaging.PixelFormat.DontCare).Save(_vm.tempBackgroundImageUrl); + } + catch (Exception ex) + { + } + fileStream.Close(); + var screen = Screen.PrimaryScreen; + var bound = screen.Bounds; + var bo = (double)bound.Height / bound.Width; + var dpi = Math.Round(bo, 3);//0.56 + fileStream.Dispose(); + + #region 闀垮璁$畻 + + double lat = Convert.ToDouble(_vm.NorthEast.Split(',')[1]); + double lon = Convert.ToDouble(_vm.NorthEast.Split(',')[0]); + //鍙充笂瑙掑潗鏍� + Coordinate coordinate1 = new Coordinate(lat, lon); + + double lat2 = Convert.ToDouble(_vm.SouthWest.Split(',')[1]); + double lon2 = Convert.ToDouble(_vm.SouthWest.Split(',')[0]); + //宸︿笅瑙掑潗鏍� + Coordinate coordinate2 = new Coordinate(lat2, lon2); + + //鍙充笅瑙掑潗鏍� + Coordinate coordinate3 = new Coordinate(coordinate1.lat, coordinate2.lon); + + //宸︿笂瑙掑潗鏍� + Coordinate coordinate4 = new Coordinate(coordinate2.lat, coordinate1.lon); + //璋冪敤Distance鏂规硶璁$畻涓ょ偣涔嬮棿鐨勮窛绂� + //甯垜璁$畻coordinate1鍜宑oordinate4涔嬮棿鐨勮窛绂� + + double distanceHeight = AmapBounds.Distance(coordinate1, coordinate4); + double distanceWidth = AmapBounds.Distance(coordinate1, coordinate3); + _vm.BackgroundWidth = distanceWidth; + _vm.BackgroundHeight = distanceHeight; + var w = pageWidth / _vm.BackgroundWidth; + var h = pageHeight / _vm.BackgroundHeight; + _vm.Zoom = w > h ? w : h; + + #endregion 闀垮璁$畻 + + _vm.IsCaptureImage = true; + File.Delete(_vm.tempBackgroundImageUrl + "_t.png"); } + + private void WebView_WebMessageReceived(object sender, Microsoft.Web.WebView2.Core.CoreWebView2WebMessageReceivedEventArgs e) + { + var j = JsonHelper.Json2Object<FixationReceivedViewModel>(e.WebMessageAsJson); + switch (j.Oper) + { + case "loadCompleted": + + var obl = JsonHelper.Json2Object<AmapLocationViewModel>(j.Json); + _vm.NorthEast = obl.NorthEast; + _vm.SouthWest = obl.SouthWest; + break; + + case "save": + if (string.IsNullOrEmpty(_vm.SouthWest)) + { + TipFormHelper.ShowWarn("鍏堣杈撳叆鍏抽敭瀛楁煡鎵惧埌寤虹瓚!"); + return; + } + + CaptureImage(); + + break; + case "getMapBounds": + var ob = JsonHelper.Json2Object<AmapLocationViewModel>(j.Json); + _vm.NorthEast = ob.NorthEast; + _vm.SouthWest = ob.SouthWest; + break; + + case "getLocation": + var o = JsonHelper.Json2Object<AmapLocationViewModel>(j.Json); + _vm.Marker = new Yw.Model.Map.Marker(); + _vm.Marker.Point = new Yw.Model.Map.Point(o.location.lng, o.location.lat); + _vm.Marker.Address = o.name + o.address; + this.txtAddress.Text = _vm.Marker.Address; + break; + case "showMessage": + TipFormHelper.ShowInfo(j.Json.ToString()); + break; + } + } + //鍦烘墍绫诲瀷鍙樻崲 @@ -93,11 +292,16 @@ { isExist = false; } - if (_vm.Marker==null) + if (!_vm.IsCaptureImage) { isExist = false; TipFormHelper.ShowWarn("璇疯缃湴鍥句俊鎭紒"); } + //if (_vm.Marker==null) + //{ + // isExist = false; + // TipFormHelper.ShowWarn("璇疯缃湴鍥句俊鎭紒"); + //} return isExist; }); } -- Gitblit v1.9.3