private void drawMOSTTyphoon() { Point point0 = new Point(); Point point1 = new Point(); Point point2 = new Point(); for (int i = 1; i < cTyphoon.mostPoints.Count; i += 2) { point0.X = (cTyphoon.mostPoints[i - 1].longitude - minLong) / (maxLong - minLong) * canvasShow.Width; point0.Y = canvasShow.Height - (cTyphoon.mostPoints[i - 1].latitude - minLat) / (maxLat - minLat) * canvasShow.Height; Ellipse tp = new Ellipse(); tp.Height = 10 / scale; tp.Width = 10 / scale; tp.Fill = typhSpeedColor(cTyphoon.mostPoints[i - 1].aveSpeed); tp.Stroke = Brushes.Black; tp.StrokeThickness = 1 / scale; Canvas.SetLeft(tp, point0.X - 5 / scale); Canvas.SetTop(tp, point0.Y - 5 / scale); Canvas.SetZIndex(tp, 2); canvasShow.Children.Add(tp); point1.Y = canvasShow.Height - (cTyphoon.mostPoints[i].latitude - minLat) / (maxLat - minLat) * canvasShow.Height; point1.X = (cTyphoon.mostPoints[i].longitude - minLong) / (maxLong - minLong) * canvasShow.Width; Line l = new Line(); l.Stroke = Brushes.DarkBlue; l.StrokeThickness = 2 / scale; l.X1 = point0.X; l.X2 = point1.X; l.Y1 = point0.Y; l.Y2 = point1.Y; Canvas.SetZIndex(l, 1); canvasShow.Children.Add(l); point2.Y = canvasShow.Height - (cTyphoon.mostPoints[i + 1].latitude - minLat) / (maxLat - minLat) * canvasShow.Height; point2.X = (cTyphoon.mostPoints[i + 1].longitude - minLong) / (maxLong - minLong) * canvasShow.Width; DoubleCollection dc = new DoubleCollection(); dc.Add(2); dc.Add(2); Line dl = new Line(); dl.Stroke = Brushes.DarkBlue; dl.StrokeThickness = 2 / scale; dl.X1 = point1.X; dl.X2 = point2.X; dl.Y1 = point1.Y; dl.Y2 = point2.Y; dl.StrokeDashArray = dc; canvasShow.Children.Add(dl); Canvas.SetZIndex(dl, 1); } #region 画预测轨迹 CMostTyphoonPoint p6h = cTyphoon.ShortTimePredict(6); point0.X = (cTyphoon.points[cTyphoon.POINTSNUM - 1].longitude - minLong) / (maxLong - minLong) * canvasShow.Width; point0.Y = canvasShow.Height - (cTyphoon.points[cTyphoon.POINTSNUM - 1].latitude - minLat) / (maxLat - minLat) * canvasShow.Height; point1.Y = canvasShow.Height - (p6h.latitude - minLat) / (maxLat - minLat) * canvasShow.Height; point1.X = (p6h.longitude - minLong) / (maxLong - minLong) * canvasShow.Width; Line lp = new Line(); lp.Stroke = Brushes.Red; lp.StrokeThickness = 2 / scale; lp.X1 = point0.X; lp.X2 = point1.X; lp.Y1 = point0.Y; lp.Y2 = point1.Y; Canvas.SetZIndex(lp, 1); DoubleCollection dcl = new DoubleCollection(); dcl.Add(2); dcl.Add(2); lp.StrokeDashArray = dcl; canvasShow.Children.Add(lp); #endregion }
/// <summary> /// 为一条台风赋值初始化 /// </summary> private void typhoonInitial() { CMostTyphoonPoint pt = cTyphoon.points[cTyphoon.POINTSNUM - 1]; lstboxAttri.Items.Clear(); for (int i = cTyphoon.POINTSNUM - 1; i > -1; i--)//显示台风点位数据 { ListBoxItem lbitem = new ListBoxItem(); lbitem.Content = cTyphoon.points[i].recordTime.ToString("MM/dd/HH") + " " + cTyphoon.points[i].latitude + "/" + cTyphoon.points[i].longitude + "\t" + cTyphoon.points[i].centerPress + "\t" + cTyphoon.points[i].aveSpeed; lstboxAttri.Items.Add(lbitem); } lblStateLabel.Content = cTyphoon.header.typhName + "(编号:" + cTyphoon.header.cycloneID + ") " + "已停编"; txtState.Text = "2015年第" + cTyphoon.header.cycloneID + "号热带低压," + cTyphoon.header.typhName + "于" + pt.recordTime + "时位于北纬" + pt.latitude + "°、东经" + pt.longitude + "°,最大风速" + pt.aveSpeed + "m/s,中心气压" + pt.centerPress + "hPa"; lblIdentify.Content = "名称:" + cTyphoon.header.typhName + " 编号:" + cTyphoon.header.cycloneID + "号"; txtCurrent.Text = "实况信息\n" + pt.recordTime; txtPredict.Text = "预报信息\n---"; lblLat.Content = pt.latitude.ToString(); lblLong.Content = pt.longitude.ToString(); lblSpeed.Content = pt.aveSpeed.ToString(); lblCenter.Content = pt.centerPress.ToString(); CMostTyphoonPoint p3h = cTyphoon.ShortTimePredict(3); lblLat3h.Content = p3h.latitude.ToString("F3"); lblLong3h.Content = p3h.longitude.ToString("F3"); CMostTyphoonPoint p6h = cTyphoon.ShortTimePredict(6); lblLat6h.Content = p6h.latitude.ToString("F3"); lblLong6h.Content = p6h.longitude.ToString("F3"); drawTyphoon(); drawMOSTTyphoon(); }
/// <summary> /// //根据数据库返回的数据行来生成台风数据点对象 /// </summary> public static CMostTyphoonPoint GetTyphoonPoint(DataRow row) { CMostTyphoonPoint tempPoint = new CMostTyphoonPoint(); tempPoint.SetPointMsg(Convert.ToDateTime(row["RECORDTIME"]), (int)row["STRENGTH"], (int)row["CENTERPRESS"], (int)row["AVESPEED"], (double)row["LATITUDE"], (double)row["LONGITUDE"], (double)row["LATSPEED"], (double)row["LONGSPEED"], (int)row["ISBURDEN"]); return(tempPoint); }
/// <summary> /// 为一条台风赋值初始化 /// </summary> private void typhoonInitial() { CMostTyphoonPoint pt = cTyphoon.points[cTyphoon.POINTSNUM - 1]; lstBoxAttrs.Items.Clear(); for (int i = cTyphoon.POINTSNUM - 1; i > -1; i--)//显示台风点位数据 { ListBoxItem lbitem = new ListBoxItem(); lbitem.Content = cTyphoon.points[i].recordTime.ToString("MM/dd/HH") + " " + cTyphoon.points[i].latitude + "/" + cTyphoon.points[i].longitude + "\t" + cTyphoon.points[i].centerPress + "\t" + cTyphoon.points[i].aveSpeed; lstBoxAttrs.Items.Add(lbitem); } drawtyphoon(); DrawMOSTTyphoon(); lblStateLabel.Content = cTyphoon.header + "(编号:" + cTyphoon.header.cycloneID + ") " + "已停编"; }
/// <summary> /// 所选台风更改 /// </summary> private void lstTyphoons_SelectionChanged(object sender, SelectionChangedEventArgs e) { pFTDQ = null; if (timer != null) { timer.Stop(); BtnSearch.IsEnabled = true; tm = 0; this.btnPlay.IsEnabled = true; } lstBoxTyphoons.Visibility = Visibility.Hidden; if (lstBoxTyphoons.SelectedIndex == -1) { return; } cTyphoon = ctyphoonlist[lstBoxTyphoons.SelectedIndex]; canvasShow.Children.Clear(); typhoonInitial(); }
/// <summary> /// //响应搜索台风按钮的事件 /// </summary> private void Search_Click(object sender, RoutedEventArgs e) { canvasShow.Children.Clear(); string reqMsg = MySearchControl.GetRequest(); if (reqMsg == "typhoon Wrong") { MessageBox.Show("查询请求不正确"); btnPlay.IsEnabled = false; return; } else if (reqMsg.Contains("search")) { string timeText = reqMsg.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries)[1]; DateTime datetime = DateTime.Parse(timeText); if (cTyphoon.POINTSNUM != 0) { typhoonInitial(); pFTDQ = cTyphoon.FullTimeDomainInquiry(datetime); if (pFTDQ == null) { MessageBox.Show("查询过程出错", "全时域查询结果", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show(datetime.ToString("yyyy-MM-dd HH:mm:ss") + ",台风位于(" + pFTDQ.latitude.ToString("F4") + "," + pFTDQ.longitude.ToString("F4") + ")", "全时域查询结果", MessageBoxButton.OK, MessageBoxImage.Information); Point point0 = new Point(); point0.X = (pFTDQ.longitude - minLong) / (maxLong - minLong) * canvasShow.Width; point0.Y = canvasShow.Height - (pFTDQ.latitude - minLat) / (maxLat - minLat) * canvasShow.Height; Ellipse tp = new Ellipse(); tp.Height = 10 / scale; tp.Width = 10 / scale; tp.Fill = Brushes.Red; tp.Stroke = Brushes.Black; tp.StrokeThickness = 1 / scale; Canvas.SetLeft(tp, point0.X - 5 / scale); Canvas.SetTop(tp, point0.Y - 5 / scale); Canvas.SetZIndex(tp, 2); canvasShow.Children.Add(tp); } } return; } TyphoonRequest request = new TyphoonRequest(reqMsg); ctyphoonlist = TyphServer.GetTyphoonData(request); lstBoxTyphoons.Items.Clear(); if (ctyphoonlist == null) { MessageBox.Show("没有符合查询条件的台风"); btnPlay.IsEnabled = false; return; } for (int i = 0; i < ctyphoonlist.Count; i++) { Label temp = new Label(); temp.Content = ctyphoonlist[i].header.typhName; lstBoxTyphoons.Items.Add(temp); } cTyphoon = ctyphoonlist[0]; btnPlay.IsEnabled = true; typhoonInitial(); }