ArcGIS API for Silverlight 绘制降雨路径动画

原文:ArcGIS API for Silverlight 绘制降雨路径动画

        #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, new MapPoint(Convert.ToDouble(tipGraphic.Attributes["LGTD"]),
                                         Convert.ToDouble(tipGraphic.Attributes["LTTD"])));
                }

                //第三步:绘制降雨圈
                this.DrawEllipse(myMap, circleCanvas, WKIDConvert.lonlat2mercator(new MapPoint(Convert.ToDouble(tipGraphic.Attributes["LGTD"]),
                    Convert.ToDouble(tipGraphic.Attributes["LTTD"]))), 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
时间: 2024-09-22 14:25:49

ArcGIS API for Silverlight 绘制降雨路径动画的相关文章

ArcGIS API for Silverlight 调用GP服务绘制等值面

原文:ArcGIS API for Silverlight 调用GP服务绘制等值面 GP服务模型如下图: 示例效果图片如下:

ArcGIS API for Silverlight开发入门

你用上3G手机了吗?你可能会说,我就是喜欢用nokia1100,ABCDEFG跟我 都没关系.但你不能否认3G是一种趋势,最终我们每个人都会被包裹在3G网络中.1100也不是一成不变,没准哪天为了打击犯罪,会在你的1100上强制 装上GPS.GIS工作既然建立在计算机的基础上,当然也得随着IT行业与时俱进.       看看现在计算机应用的趋势吧.云(计算),这个东西可讲不清楚,因为云嘛,飘忽不定的.不过可以这样来看它,以后计算机网络上就有一坨(或者几坨)万能的 云,有什么需求云都可以满足我们,

ArcGIS API for Silverlight 调用GP服务准备---GP模型建立、发布、测试

原文:ArcGIS API for Silverlight 调用GP服务准备---GP模型建立.发布.测试                                                                                                                      第一篇.GP降雨量等值线建模.发布及测试          在水利.气象等行业中,要在WebGIS中实现空间分析功能,如绘制等值线.等高线.等直面.缓冲区等都

使用Visifire+ArcGIS API for Silverlight实现Graphic信息的动态图表显示

原文:使用Visifire+ArcGIS API for Silverlight实现Graphic信息的动态图表显示   首先来看一看实现的效果: PS:原始的程序中更新曲线数据时添加了过渡的效果,具体可查看官网的示例: http://www.visifire.com/silverlight_spline_charts_gallery.php 点击其中的一个例子,然后点击Live Updates,就可看到数据更新时的过渡效果.但是蛋疼的博客园,不知道为什么,我插入了我原始的xap文件,过渡效果却

ArcGIS API for Silverlight 点沿着线流动

原文:ArcGIS API for Silverlight 点沿着线流动 概述 前段时间做了一个项目,要求是有一些电力输送线,电力输送线或者石油管道都是有流动方向的,用户想做一个动态效果来模拟电力的输送.其实做简单了只要在线上标识个箭头就可以了.但也要是做成动态的,至少ArcEngine实现起来是有点麻烦的.但ArcGIS API for Silverlight可以解决这个问题. 实现思路 在地图上展示输送电力的线和模拟电力输送方向的电都是ArcGIS  API中定义的对象,否者这些数据在地图上

ArcGIS API for Silverlight 调用GP服务加载等值线图层

原文:ArcGIS API for Silverlight 调用GP服务加载等值线图层                                                                                                    第二篇.Silverlight客户端调用GP服务          利用ArcGIS API for Silverlight实现GP服务调用,这里的雨量数据是通过一个WebService获取而来,主要信息是雨量站点

使用ArcGIS API for Silverlight实现地形坡度在线分析

原文:使用ArcGIS API for Silverlight实现地形坡度在线分析           苦逼的研究生课程终于在今天结束了,也许从今以后再也不会坐在大学的课堂上正式的听老师讲课了,接下来的时间就得开始找工作了.....前段时间一直比较忙,上课,考试,论文,以及联系实习单位...现在就差实习还没有着落了.           前些天帮一网友做了个在线坡度分析的例子,大概的功能就是勾选任意的地形区域,然后实现Web端的地形坡度分析和可视化显示,效果图如下:    实现的基本思路大致分为

arcgis api for silverlight

原文 http://blog.sina.com.cn/s/blog_4638cf7b0100wntt.html arcgis api for silverlight(1) (2011-09-21 09:09:26) 转载▼ 标签: 杂谈 分类: 技术 发现了一个很好的学习工具,就是Esri的在线帮助,包括概念,例子,API介绍等等.接下来的学习基本上就是按照例子结合开发方案进行实践学习. http://help.arcgis.com/en/webapi/silverlight/samples/s

ArcGIS API for Silverlight 使用GP服务实现要素裁剪功能

原文:ArcGIS API for Silverlight 使用GP服务实现要素裁剪功能      昨天一QQ好友问了一个关于裁剪的问题,感觉自己也没有帮上什么忙,之后自己做了一个裁剪的例子,不过在做这个例子的时候还遇到了不少的问题,在此和大家分享一下. 1.裁剪功能的实现过程 这里的裁剪功能很简单,只需要一个Clip(裁剪)工具即可. 但是这里需要注意的问题是裁剪工具的参数: 裁剪工具有两个输入参数: a.输入要素:这里指的是你用什么来裁剪目标要素,也就是你用什么裁剪 b.裁剪要素:这里指的被