#region 降雨动画演示 2014-04-16 List<Graphic> graphics = new List<Graphic>(); int INDEX = 0; MapPoint GLOBAL = new MapPoint(); //保存上一次绘制降雨圈的点信息 2014-04-16 int INDEX_2 = 0; //控制是否是第一次绘制降雨圈 /// <summary> /// 从数据库获取数据,并绘制圆 /// </summary> public voID DrawRainEllipseFromDatabase() { getMapDataSoapClIEnt clIEnt = new getMapDataSoapClIEnt(); clIEnt.getJYDataByTimeSpanCompleted += new EventHandler<getJYDataByTimeSpanCompletedEventArgs>(clIEnt_getJYDataByTimeSpanCompleted); clIEnt.getJYDataByTimeSpanAsync("2014-04-08","2014-04-11"); } voID clIEnt_getJYDataByTimeSpanCompleted(object sender,getJYDataByTimeSpanCompletedEventArgs e) { //Graphicslayer graphicslayer = myMap.Layers["YLPointsLayer"] as Graphicslayer; //graphicslayer.Cleargraphics(); ObservableCollection<JYDW> rets = e.Result; Graphic graphic; foreach (JYDW item in rets) { graphic = new Graphic() { Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.LGTD.ToString().Trim()),double.Parse(item.LTTD.ToString().Trim()))),Symbol = LayoutRoot.Resources["BlueMarkerSymbol"] as Symbol }; //保存属性 graphic.Attributes["STCD"] = item.CMAXSTCD; //雨量站编码 graphic.Attributes["TM"] = item.TM; //时间 graphic.Attributes["RainV"] = item.CDRP; //雨量站名称 graphic.Attributes["CDNUM"] = item.CDNUM; //降雨站数 graphic.Attributes["LGTD"] = item.LGTD; //经度 graphic.Attributes["LTTD"] = item.LTTD; //纬度 graphics.Add(graphic); //graphicslayer.Graphics.Add(graphic); } } /// <summary> /// 在地图上绘制圆 /// </summary> /// <param name="myMap">地图</param> /// <param name="container">绘制容器</param> /// <param name="pt">要绘制的点</param> /// <param name="drawCircleLayer"></param> /// <param name="circleKm">直径</param> /// <param name="color">填充色</param> /// <param name="ellipsestroke">边框色</param> public voID DrawEllipse(Map myMap,Canvas container,MapPoint pt,ref ElementLayer drawCircleLayer,double circleKm,color color,color ellipsestroke) { if (!drawCircleLayer.Children.Contains(container)) { drawCircleLayer.Children.Add(container); container.Opacity = 0.7; container.SetValue(ElementLayer.EnvelopeProperty,new Envelope(myMap.Extent.XMax,myMap.Extent.YMax,myMap.Extent.XMin,myMap.Extent.YMin)); } Point ptFirst = myMap.MapToScreen(new MapPoint(Convert.Todouble(pt.X),Convert.Todouble(pt.Y))); Point pt7 = myMap.MapToScreen(new MapPoint((Convert.Todouble(pt.X) + (circleKm * 1000)),Convert.Todouble(pt.Y))); Ellipse ellipse7 = new Ellipse(); ellipse7.WIDth = (pt7.X - ptFirst.X)*2; ellipse7.Height = ellipse7.WIDth; ellipse7.strokeThickness = 1; ellipse7.stroke = new SolIDcolorBrush(ellipsestroke); ellipse7.Fill = new SolIDcolorBrush(color); Canvas.Setleft(ellipse7,ptFirst.X - ellipse7.WIDth / 2); Canvas.Settop(ellipse7,ptFirst.Y - ellipse7.WIDth / 2); ellipse7.Opacity = 0.7; container.Children.Add(ellipse7); container.IsHitTestVisible = false; container.SetValue(Canvas.ZIndexProperty,1); GLOBAL = WKIDConvert.mercator2lonlat(ESRI.ArcGIS.ClIEnt.Geometry.Geometry.normalizeCentralMerIDian(pt) as ESRI.ArcGIS.ClIEnt.Geometry.MapPoint);//每次绘制降雨圈后,将值保存起来 } /// <summary> /// 绘制点 /// </summary> public voID DrawPoint(MapPoint mp,Graphic g) { Graphicslayer graphicslayer = myMap.Layers["YLPointsLayer"] as Graphicslayer; Graphicslayer graphicslayerText = myMap.Layers["GraphicslayerRed"] as Graphicslayer; //动态标记点元素 Graphic graphic = new Graphic() { Geometry = mp,Symbol = LayoutRoot.Resources["BlueMarkerSymbol"] as Symbol }; graphicslayer.Graphics.Add(graphic); //动态标记数值 TextSymbol textSymbol = new TextSymbol() { FontFamily = new System.windows.Media.FontFamily("Microsoft YaHei"),Foreground = new System.windows.Media.solIDcolorBrush(colorRevert.Tocolor(tip_Base.DXT_color)),FontSize = 16,Text = g.Attributes["RainV"].ToString(),OffsetX = 10,OffsetY = 23 }; Graphic graphicText = new Graphic() { Geometry = mp,Symbol = textSymbol }; graphicslayerText.Graphics.Add(graphicText); } /// <summary> /// 绘制连接线 /// </summary> public voID Drawline(MapPoint gS,MapPoint gE) { List<ESRI.ArcGIS.ClIEnt.Geometry.polyline> polylineList = new List<ESRI.ArcGIS.ClIEnt.Geometry.polyline>(); ESRI.ArcGIS.ClIEnt.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.ClIEnt.Geometry.PointCollection(); pointCollection.Add(gS); pointCollection.Add(gE); ESRI.ArcGIS.ClIEnt.Geometry.polyline polyline = new ESRI.ArcGIS.ClIEnt.Geometry.polyline(); polyline.Paths.Add(pointCollection); polylineList.Add(polyline); Graphicslayer graphicslayer = myMap.Layers["GraphicsDWline"] as Graphicslayer; foreach (ESRI.ArcGIS.ClIEnt.Geometry.polyline pl in polylineList) { Graphic graphic = new Graphic() { Symbol = LayoutRoot.Resources["Defaultlinesymbol"] as Symbol,Geometry = mercator.FromGeographic(pl) }; graphicslayer.Graphics.Add(graphic); } } /// <summary> /// 绘制每小时降雨圈 /// </summary> /// <param name="myMap"></param> /// <param name="sender"></param> public voID DrawEllipseHourRainCircle(Map myMap,object sender) { INDEX_2++; if (GisMap.LayerExist(myMap,"RainAnimationLayer")) { GisMap.DeleteLayersToMap(myMap,"RainAnimationLayer"); } ElementLayer circleLayer = new ElementLayer(); circleLayer.ID = "RainAnimationLayer"; Canvas circleCanvas = new Canvas(); Graphic tipGraphic = sender as Graphic; //通过过滤为0的值,这样经纬度坐标没有值的也被过滤掉 if (Convert.Todouble(tipGraphic.Attributes["RainV"]) != 0) { color color = new color(); double V = double.Parse(tipGraphic.Attributes["RainV"].ToString()); if (V < 10) { color = colorRevert.Tocolor("#FF3FC816"); } else if (V >= 10 && V < 25) { color = colorRevert.Tocolor("#FF1016FE"); } else if (V >= 25 && V < 50) { color = colorRevert.Tocolor("#FFFFEB00"); } else if (V >= 50 && V < 100) { color = colorRevert.Tocolor("#FFFF871C"); } else if (V >= 100 && V < 200) { color = colorRevert.Tocolor("#FFEB27A5"); } else if (V >= 200) { color = colorRevert.Tocolor("#FFE8353B"); } //第一步:绘制降雨点 DrawPoint(WKIDConvert.lonlat2mercator(new MapPoint(Convert.Todouble(tipGraphic.Attributes["LGTD"]),Convert.Todouble(tipGraphic.Attributes["LTTD"]))),tipGraphic); //第二步:绘制站点连接线 if (INDEX_2 == 1) { Drawline(new MapPoint(Convert.Todouble(tipGraphic.Attributes["LGTD"]),Convert.Todouble(tipGraphic.Attributes["LTTD"])),new MapPoint(Convert.Todouble(tipGraphic.Attributes["LGTD"]),Convert.Todouble(tipGraphic.Attributes["LTTD"]))); } else { Drawline(GLOBAL,Convert.Todouble(tipGraphic.Attributes["LTTD"]))); } //第三步:绘制降雨圈 this.DrawEllipse(myMap,circleCanvas,WKIDConvert.lonlat2mercator(new MapPoint(Convert.Todouble(tipGraphic.Attributes["LGTD"]),ref circleLayer,Convert.Todouble(tipGraphic.Attributes["CDNUM"]),color,color); } GisMap.AddLayersToMap(myMap,new ElementLayer[] { circleLayer }); } dispatcherTimer timer = new dispatcherTimer(); private voID btnDW_Click(object sender,System.windows.RoutedEventArgs e) { DrawRainEllipseFromDatabase(); // 先绘点并保存数据 double d = 1; try { d = double.Parse(this.tbSecond.Text.Trim()); } catch (Exception) { MessageBox.Show("请输入数字!"); } timer.Interval = TimeSpan.FromSeconds(d); timer.Tick += new EventHandler(timer_Tick); timer.Start(); } voID timer_Tick(object sender,EventArgs e) { try { if (INDEX < graphics.Count) { DrawEllipseHourRainCircle(myMap,graphics[INDEX]); this.tb_SJ.Text = ""; this.tb_ZM.Text = ""; this.tb_YL.Text = ""; this.tb_SJ.Text = DateTime.Parse(graphics[INDEX].Attributes["TM"].ToString()).ToString("yyyy-MM-dd HH:mm"); this.tb_ZM.Text = graphics[INDEX].Attributes["STCD"].ToString().Trim(); this.tb_YL.Text = graphics[INDEX].Attributes["RainV"].ToString().Trim(); INDEX++; //自增 } else { //INDEX = 0; timer.Stop(); //动画过程停止 } } catch (Exception ex) { return; } } #endregion总结
以上是内存溢出为你收集整理的ArcGIS API for Silverlight 绘制降雨路径动画全部内容,希望文章能够帮你解决ArcGIS API for Silverlight 绘制降雨路径动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)