| | |
| | | namespace PBS.WinFrmUI.Hydro |
| | | using Microsoft.Web.WebView2.Core; |
| | | |
| | | namespace PBS.WinFrmUI.Hydro |
| | | { |
| | | public partial class QuickModelingPlaceWizardPage : DevExpress.XtraEditors.XtraUserControl, IWizardPageAsync<QuickModelingViewModel> |
| | | { |
| | |
| | | { |
| | | InitializeComponent(); |
| | | this.layoutControl1.SetupLayoutControl(); |
| | | this.mapSetSimpleMarkerContainer1.LoadCompletedEvent += MapSetSimpleMarkerContainer1_LoadCompletedEvent; |
| | | this.mapSetSimpleMarkerContainer1.SetMarkerEvent += MapSetSimpleMarkerContainer1_SetMarkerEvent; |
| | | |
| | | this.imgCmbPlaceType.Properties.AddEnum<PBS.ePlaceType>(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | public event Action PageStateChangedEvent; |
| | | |
| | | private QuickModelingViewModel _vm = null;//操作对象 |
| | | private bool _isCompleted = false;//是否创建完成 |
| | | private bool _createResult = false;//创建结果 |
| | | private bool _isCompleted = false;//是否创建完成 |
| | | private bool _isInitialMap = false;//是否初始化地图 |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 初始化页面 |
| | |
| | | { |
| | | return; |
| | | } |
| | | _vm = vm; |
| | | _vm = vm; |
| | | _isCompleted = false; |
| | | _createResult = false; |
| | | |
| | | //_createResult = await QuickModelingHelper.Create(vm, (msg, color) => |
| | | // { |
| | | // var drawItem = new DrawItemViewModel |
| | | // { |
| | | // Text = msg, |
| | | // Color = color |
| | | // }; |
| | | // this.listBoxControl1.Items.Add(drawItem); |
| | | // }, (max, current) => |
| | | // { |
| | | // this.progressBarControl1.Properties.Maximum = max; |
| | | // this.progressBarControl1.Position = current; |
| | | // //替代方案 |
| | | // // this.progressBarControl1.Properties.Step = current; |
| | | // // this.progressBarControl1.PerformStep(); |
| | | // }); |
| | | _isCompleted = true; |
| | | if (!_createResult) |
| | | |
| | | if (!_isInitialMap) |
| | | { |
| | | //this.progressBarControl1.Position = 0; |
| | | //this.itemForProgress.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
| | | } |
| | | this.webView.Source = new Uri(AppDomain.CurrentDomain.BaseDirectory + "/web/html/map_select.html"); |
| | | this.webView.WebMessageReceived += WebView_WebMessageReceived; |
| | | } |
| | | |
| | | this.txtName.EditValue = _vm.Place.Name; |
| | | this.txtTagName.EditValue = _vm.Place.TagName; |
| | | this.txtAddress.EditValue = _vm.Place.Address; |
| | | this.txtDescription.EditValue = _vm.Place.Description; |
| | | this.placeInfoCtrl1.Set(_vm.Place.PlaceType, _vm.Place.PlaceInfo); |
| | | var allFlagsList = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(DataType.PBSPlace); |
| | | this.setFlagsEditCtrl1.SetBindingData(allFlagsList?.Select(x => x.Name).Distinct().ToList(), _vm.Place.Flags); |
| | | this.imgCmbPlaceType.EditValue = _vm.Place.PlaceType; |
| | | |
| | | _isCompleted = true; |
| | | 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; |
| | | if (string.IsNullOrEmpty(this.txtAddress.Text.Trim())) |
| | | 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)) |
| | | { |
| | | this.txtAddress.EditValue = obj.Address; |
| | | 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和coordinate4之间的距离 |
| | | |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //场所类型变换 |
| | | private void imgCmbPlaceType_EditValueChanged(object sender, EventArgs e) |
| | | { |
| | | var placeType = (PBS.ePlaceType)this.imgCmbPlaceType.EditValue; |
| | | this.placeInfoCtrl1.Set(placeType); |
| | | } |
| | | |
| | | //验证 |
| | | private bool Verify() |
| | | { |
| | | return this.Invoke(() => |
| | | { |
| | | var isExist = true; |
| | | this.dxErrorProvider1.ClearErrors(); |
| | | var name = this.txtName.Text.Trim(); |
| | | if (string.IsNullOrEmpty(name)) |
| | | { |
| | | this.dxErrorProvider1.SetError(this.txtName, "必填项"); |
| | | isExist= false; |
| | | } |
| | | if (!this.placeInfoCtrl1.Verify()) |
| | | { |
| | | isExist = false; |
| | | } |
| | | if (!_vm.IsCaptureImage) |
| | | { |
| | | isExist = false; |
| | | TipFormHelper.ShowWarn("请设置地图信息!"); |
| | | } |
| | | //if (_vm.Marker==null) |
| | | //{ |
| | | // isExist = false; |
| | | // TipFormHelper.ShowWarn("请设置地图信息!"); |
| | | //} |
| | | return isExist; |
| | | }); |
| | | } |
| | | |
| | | //保存 |
| | | private bool Save() |
| | | { |
| | | if (!Verify()) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | _vm.Place.Name = this.txtName.Text.Trim(); |
| | | _vm.Place.PlaceType = (ePlaceType)this.imgCmbPlaceType.EditValue; |
| | | _vm.Place.Flags = this.setFlagsEditCtrl1.SelectedFlagList; |
| | | _vm.Place.TagName = this.txtTagName.Text.Trim(); |
| | | _vm.Place.Address = this.txtAddress.Text.Trim(); |
| | | _vm.Place.Description = this.txtDescription.Text.Trim(); |
| | | _vm.Place.PlaceInfo=this.placeInfoCtrl1.Get(); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | |
| | |
| | | public bool AllowPrev |
| | | { |
| | | get |
| | | { |
| | | if (!_isCompleted) |
| | | { |
| | | return false; |
| | | } |
| | | if (!_createResult) |
| | | { |
| | | return true; |
| | | } |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | |
| | | { |
| | | get |
| | | { |
| | | if (_createResult) |
| | | if (!_isCompleted) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | } |
| | | |
| | |
| | | public bool AllowCancel |
| | | { |
| | | get |
| | | { |
| | | if (!_createResult) |
| | | { |
| | | return true; |
| | | } |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | |
| | | /// </summary> |
| | | public Task<bool> CanNext() |
| | | { |
| | | return Task.Run(() => this.AllowNext); |
| | | return Task.Run(() => Save()); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | return Task.Run(() => this.AllowComplete); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |