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

简介: 原文:ArcGIS API for Silverlight 绘制降雨路径动画 #region 降雨动画演示 2014-04-16 List graphics = new List(); int INDEX = 0; M...
原文: 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


目录
相关文章
|
3月前
|
缓存 API 网络架构
Nuxt Kit API :路径解析工具
【9月更文挑战第20天】在 Nuxt Kit API 中,路径解析工具如 `resolvePath()`、`joinPaths()` 和 `relativePath()` 帮助开发者高效处理应用路径,确保资源准确加载,并支持动态路由与组件导入。这些工具提升了应用的灵活性和可扩展性,同时需注意路径准确性、跨平台兼容性和性能优化,以提升用户体验。
37 12
|
5月前
|
文字识别 小程序 安全
印刷文字识别操作报错合集之微信小程序调用API时路径总是返回不对,该如何处理
在使用印刷文字识别(OCR)服务时,可能会遇到各种错误。例如:1.Java异常、2.配置文件错误、3.服务未开通、4.HTTP错误码、5.权限问题(403 Forbidden)、6.调用拒绝(Refused)、7.智能纠错问题、8.图片质量或格式问题,以下是一些常见错误及其可能的原因和解决方案的合集。
|
4月前
|
前端开发 API
【API管理 APIM】APIM中如何配置使用URL路径的方式传递参数(如由test.htm?name=xxx 变为test\xxx)
【API管理 APIM】APIM中如何配置使用URL路径的方式传递参数(如由test.htm?name=xxx 变为test\xxx)
|
6月前
|
前端开发 Java 数据库连接
项目API借口的根路径怎样设置
项目API借口的根路径怎样设置
|
7月前
|
API
QT中使用 WinExec API 参数不支持中文路径的解决办法
在QT中使用WinExec时,发现如果调用外部程序,如果路径或者参数含有中文路径,可能导致无法打开应用程序或者无法使用参数,解决办法,下面是简单的解决办法
201 0
|
Cloud Native Java API
Java Spring拦截器优化实践: 专注于API路径拦截
Java Spring拦截器优化实践: 专注于API路径拦截
100 0
|
人工智能 数据可视化 API
ArcGIS API for Python
ArcGIS API for Python
71 0
ArcGIS:如何利用栅格数据进行路径网络分析-可达性分析?
ArcGIS:如何利用栅格数据进行路径网络分析-可达性分析?
405 0
|
JavaScript 前端开发 应用服务中间件
Arcgis api for javascript 详细部署
Arcgis api for javascript 详细部署
|
人工智能 数据可视化 数据管理
ArcGIS API for Python
ArcGIS API for Python
116 0