ArcGIS API for Silverlight 解决众多密集点分层显示

ArcGIS API for Silverlight 解决众多密集点分层显示,第1张

概述问题提出:         在实际中通常会遇到这样的情况,如果地图范围小,而且需要在地图上展示的元素又比较多的时候(在展现元素符号的同时,还展示元素名称或其他属性值等),这样如果在首次加载地图的时候一次性全部显示,必然会出现严重的重叠现象,怎么解决? 解决思路:       我想大家首先想到的就是分层显示,不错,其实这就是一个方便可行的思路。为数据库表中增加一个显示层次的字段,比如叫ShowLev

问题提出:

        在实际中通常会遇到这样的情况,如果地图范围小,而且需要在地图上展示的元素又比较多的时候(在展现元素符号的同时,还展示元素名称或其他属性值等),这样如果在首次加载地图的时候一次性全部显示,必然会出现严重的重叠现象,怎么解决?


解决思路:

      我想大家首先想到的就是分层显示,不错,其实这就是一个方便可行的思路。为数据库表中增加一个显示层次的字段,比如叫ShowLevel,默认是0-第一层显示,1-第二层显示...,然后在Map的Layers中添加多个Graphics,有几层就设置多少个,然后在后台程序中通过判断元素是ShowLevel属性,将元素添加到各自不同的Graphics当中去,最后处理Map的ExtendChanged事件,找到一个显示的边界值,然后通过判断当前的缩放比例是否达到了这个边界值,如果达到了,就显示第二层,如果没有达到就隐藏。


具体实现及部分代码如下:

 1、首先数据库中增加一个字段,ShowLevel,默认值为0

     

2、在MainPage.xaml中多增加几个Graphics

       

  <esri:Map.Layers>                <esri:Graphicslayer ID="MyGraphicslayer">                </esri:Graphicslayer>                <esri:Graphicslayer ID="MyGraphicslayer3">                </esri:Graphicslayer>                <!--站点名称-->                <esri:Graphicslayer ID="Graphicslayer1">                </esri:Graphicslayer>                <esri:Graphicslayer ID="Graphicslayer11">                </esri:Graphicslayer>                <!--站点数据-->                <esri:Graphicslayer ID="Graphicslayer2">                </esri:Graphicslayer>                <esri:Graphicslayer ID="Graphicslayer22">                </esri:Graphicslayer>                <!--站点编码-->                <esri:Graphicslayer ID="Graphicslayer3">                </esri:Graphicslayer>                <esri:Graphicslayer ID="Graphicslayer33">   </esri:Map.Layers>


3、MainPage.xaml.cs中根据ShowLevel字段值,分别添加到各自的Graphics中

            ESRI.ArcGIS.ClIEnt.Projection.WebMercator mercator = new ESRI.ArcGIS.ClIEnt.Projection.WebMercator();            //每次加载时先清空地图上数据            Graphicslayer graphicslayer = myMap.Layers["MyGraphicslayer"] as Graphicslayer;            graphicslayer.Cleargraphics();            Graphicslayer graphicslayer0 = myMap.Layers["MyGraphicslayer3"] as Graphicslayer;            graphicslayer0.Cleargraphics();            Graphicslayer graphicslayer1 = myMap.Layers["Graphicslayer1"] as Graphicslayer;            graphicslayer1.Cleargraphics();            Graphicslayer graphicslayer2 = myMap.Layers["Graphicslayer2"] as Graphicslayer;            graphicslayer2.Cleargraphics();            Graphicslayer graphicslayer3 = myMap.Layers["Graphicslayer3"] as Graphicslayer;            graphicslayer3.Cleargraphics();            Graphicslayer graphicslayer11 = myMap.Layers["Graphicslayer11"] as Graphicslayer;            graphicslayer11.Cleargraphics();            Graphicslayer graphicslayer22 = myMap.Layers["Graphicslayer22"] as Graphicslayer;            graphicslayer22.Cleargraphics();            Graphicslayer graphicslayer33 = myMap.Layers["Graphicslayer33"] as Graphicslayer;            graphicslayer33.Cleargraphics();            //获取到所有的山洪雨量点            ObservableCollection<RainFall> Lists = e.Result;            //从集合中找出最大值对应的经纬度坐标            RainFall max = Lists.OrderByDescending(s => s.YL24).FirstOrDefault();            //动态添加点到地图上            Graphic graphic = null; //第一层            Graphic graphic2 = null; //第二层            foreach (RainFall item in Lists)            {                if (!string.IsNullOrEmpty(item.Latitute.ToString()) && !string.IsNullOrEmpty(item.Longitute.ToString()))                {                    //有坐标值时,将该监测点添加到地图上去                    if (max.YLZBM == item.YLZBM)                    {                        if (max.YL24 != 0)                        {                            //最大值不为0,红点闪烁                            graphic = new Graphic()                            {                                Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim()),double.Parse(item.Longitute.ToString().Trim()))),Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as Symbol                            };                        }                        else                        {                            //保持原来的蓝色标记点符号                            graphic = new Graphic()                            {                                Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim()),Symbol = LayoutRoot.Resources["BlueMarkerSymbol"] as Symbol                            };                        }                        //保存属性                        graphic.Attributes["YLZBM"] = item.YLZBM; //雨量站编码                        graphic.Attributes["YLZMC"] = item.ZDMC; //雨量站名称                        graphic.Attributes["YL24"] = item.YL24; //24小时雨量                        graphic.Attributes["DTNow"] = item.DTNow; //当前时间                        graphic.Attributes["Latitute"] = item.Latitute; //纬度                        graphic.Attributes["Longitute"] = item.Longitute; //经度                        //将该Graphics添加到Graphicslayer中去                        graphicslayer.Graphics.Add(graphic);                        graphicslayer.Opacity = 1;                        //鼠标移入事件                        graphic.MouseEnter += new MouseEventHandler(sh_graphic_MouseEnter);                        graphic.MouseLeave += new MouseEventHandler(sh_graphic_MouseLeave);                        //鼠标点击事件                        #region 站点名称                        //动态添加文本                        TextSymbol textSymbol = new TextSymbol()                        {                            FontFamily = new System.windows.Media.FontFamily("Microsoft YaHei"),Foreground = new System.windows.Media.solIDcolorBrush(color.FromArgb(255,117,20,99)),FontSize = 12,Text = item.ZDMC,OffsetX = 12,OffsetY = -5                        };                        Graphic graphicText1 = new Graphic()                        {                            Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim(),System.Globalization.CultureInfo.InvariantCulture),double.Parse(item.Longitute.ToString().Trim(),System.Globalization.CultureInfo.InvariantCulture))),Symbol = textSymbol                        };                        graphicText1.Attributes["TextYLZMC"] = item.ZDMC;                        graphicslayer1.Graphics.Add(graphicText1);                        #endregion                        #region 水位/雨量 数值                        if (item.YL24 != 0)                        {                            TextSymbol textSymbol2 = new TextSymbol()                            {                                FontFamily = new System.windows.Media.FontFamily("Microsoft YaHei"),255,0)),FontSize = 14,Text = item.YL24.ToString(),OffsetX = 10,OffsetY = 23                            };                            Graphic graphicText2 = new Graphic()                            {                                Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim(),Symbol = textSymbol2                            };                            graphicText2.Attributes["TextYL"] = item.YL24;                            graphicslayer2.Graphics.Add(graphicText2);                        }                        #endregion                        #region 站点编码                        //动态添加站点编码                        TextSymbol textSymbol3 = new TextSymbol()                        {                            FontFamily = new System.windows.Media.FontFamily("Microsoft YaHei"),Text = item.YLZBM,OffsetX = 27,OffsetY = 23                        };                        Graphic graphicText3 = new Graphic()                        {                            Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim(),Symbol = textSymbol3                        };                        graphicText3.Attributes["TextYLZBM"] = item.YLZBM;                        graphicslayer3.Graphics.Add(graphicText3);                        graphicslayer3.Visible = false;                        #endregion                        //左键点击事件                        graphic.MouseleftbuttonDown += new MousebuttonEventHandler(sh_graphic_MouseleftbuttonDown);                        graphic.MouseleftbuttonUp += new MousebuttonEventHandler(sh_graphic_MouseleftbuttonUp);                    }                    else                    {                        //这里判断显示层数                        if (item.ShowLevel == 0)                        {                            #region 显示第一层数据                            graphic = new Graphic()                            {                                Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim()),Symbol = LayoutRoot.Resources["BlueMarkerSymbol"] as Symbol                            };                            //保存属性                            graphic.Attributes["YLZBM"] = item.YLZBM; //雨量站编码                            graphic.Attributes["YLZMC"] = item.ZDMC; //雨量站名称                            graphic.Attributes["YL24"] = item.YL24; //24小时雨量                            graphic.Attributes["DTNow"] = item.DTNow; //当前时间                            graphic.Attributes["Latitute"] = item.Latitute; //纬度                            graphic.Attributes["Longitute"] = item.Longitute; //经度                            //将该Graphics添加到Graphicslayer中去                            graphicslayer.Graphics.Add(graphic);                            graphicslayer.Opacity = 1;                            //鼠标移入事件                            graphic.MouseEnter += new MouseEventHandler(sh_graphic_MouseEnter);                            graphic.MouseLeave += new MouseEventHandler(sh_graphic_MouseLeave);                            //鼠标点击事件                            #region 站点名称                            //动态添加文本                            TextSymbol textSymbol = new TextSymbol()                            {                                FontFamily = new System.windows.Media.FontFamily("Microsoft YaHei"),OffsetY = -5                            };                            Graphic graphicText1 = new Graphic()                            {                                Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim(),Symbol = textSymbol                            };                            graphicText1.Attributes["TextYLZMC"] = item.ZDMC;                            graphicslayer1.Graphics.Add(graphicText1);                            #endregion                            #region 水位/雨量 数值                            if (item.YL24 != 0)                            {                                TextSymbol textSymbol2 = new TextSymbol()                                {                                    FontFamily = new System.windows.Media.FontFamily("Microsoft YaHei"),OffsetY = 23                                };                                Graphic graphicText2 = new Graphic()                                {                                    Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim(),Symbol = textSymbol2                                };                                graphicText2.Attributes["TextYL"] = item.YL24;                                graphicslayer2.Graphics.Add(graphicText2);                            }                            #endregion                            #region 站点编码                            //动态添加站点编码                            TextSymbol textSymbol3 = new TextSymbol()                            {                                FontFamily = new System.windows.Media.FontFamily("Microsoft YaHei"),OffsetY = 23                            };                            Graphic graphicText3 = new Graphic()                            {                                Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim(),Symbol = textSymbol3                            };                            graphicText3.Attributes["TextYLZBM"] = item.YLZBM;                            graphicslayer3.Graphics.Add(graphicText3);                            graphicslayer3.Visible = false;                            #endregion                            //左键点击事件                            graphic.MouseleftbuttonDown += new MousebuttonEventHandler(sh_graphic_MouseleftbuttonDown);                            graphic.MouseleftbuttonUp += new MousebuttonEventHandler(sh_graphic_MouseleftbuttonUp);                            #endregion                        }                        else                        {                            #region 显示第二层数据                            graphic2 = new Graphic()                            {                                Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim()),Symbol = LayoutRoot.Resources["BlueMarkerSymbol"] as Symbol                            };                            //保存属性                            graphic2.Attributes["YLZBM"] = item.YLZBM; //雨量站编码                            graphic2.Attributes["YLZMC"] = item.ZDMC; //雨量站名称                            graphic2.Attributes["YL24"] = item.YL24; //24小时雨量                            graphic2.Attributes["DTNow"] = item.DTNow; //当前时间                            graphic2.Attributes["Latitute"] = item.Latitute; //纬度                            graphic2.Attributes["Longitute"] = item.Longitute; //经度                            //将该Graphics添加到Graphicslayer中去                            graphicslayer0.Graphics.Add(graphic2);                            graphicslayer0.Opacity = 1;                            if (currentValue > tip_Base.sIDeValue)                            {                                graphicslayer0.Visible = false;                            }                            else                            {                                graphicslayer0.Visible = true;                            }                            //鼠标移入事件                            graphic2.MouseEnter += new MouseEventHandler(sh_graphic_MouseEnter);                            graphic2.MouseLeave += new MouseEventHandler(sh_graphic_MouseLeave);                            //鼠标点击事件                            #region 站点名称                            //动态添加文本                            TextSymbol textSymbol = new TextSymbol()                            {                                FontFamily = new System.windows.Media.FontFamily("Microsoft YaHei"),Symbol = textSymbol                            };                            graphicText1.Attributes["TextYLZMC"] = item.ZDMC;                            graphicslayer11.Graphics.Add(graphicText1);                            if (currentValue > tip_Base.sIDeValue)                            {                                graphicslayer11.Visible = false;                            }                            else                            {                                graphicslayer11.Visible = true;                            }                            #endregion                            #region 水位/雨量 数值                            if (item.YL24 != 0)                            {                                TextSymbol textSymbol2 = new TextSymbol()                                {                                    FontFamily = new System.windows.Media.FontFamily("Microsoft YaHei"),Symbol = textSymbol2                                };                                graphicText2.Attributes["TextYL"] = item.YL24;                                graphicslayer22.Graphics.Add(graphicText2);                                if (currentValue > tip_Base.sIDeValue)                                {                                    graphicslayer22.Visible = false;                                }                                else                                {                                    graphicslayer22.Visible = true;                                }                            }                            #endregion                            #region 站点编码                            //动态添加站点编码                            TextSymbol textSymbol3 = new TextSymbol()                            {                                FontFamily = new System.windows.Media.FontFamily("Microsoft YaHei"),Symbol = textSymbol3                            };                            graphicText3.Attributes["TextYLZBM"] = item.YLZBM;                            graphicslayer33.Graphics.Add(graphicText3);                            graphicslayer33.Visible = false;                            #endregion                            //左键点击事件                            graphic2.MouseleftbuttonDown += new MousebuttonEventHandler(sh_graphic_MouseleftbuttonDown);                            graphic2.MouseleftbuttonUp += new MousebuttonEventHandler(sh_graphic_MouseleftbuttonUp);                            #endregion                        }                    }                }                else                {                    //不做任何处理,不添加任何点信息                }            }


4、在Map的ExtendChanged事件中处理

      

 private voID myMap_ExtentChanged(object sender,ExtentEventArgs e){      currentValue = (e.NewExtent.XMax - e.NewExtent.XMin) / (myMap.Layers.GetFullExtent().XMax - myMap.Layers.GetFullExtent().XMin);      ShowSiteByGrade();}        /// <summary>        /// 判断是在第一层还是第二层显示        /// </summary>        private voID ShowSiteByGrade()        {            if (currentValue >= tip_Base.sIDeValue)            {                Graphicslayer graphicslayer0 = myMap.Layers["MyGraphicslayer3"] as Graphicslayer;                graphicslayer0.Visible = false;                Graphicslayer graphicslayer2 = myMap.Layers["Graphicslayer11"] as Graphicslayer;                graphicslayer2.Visible = false;                Graphicslayer graphicslayer3 = myMap.Layers["Graphicslayer22"] as Graphicslayer;                graphicslayer3.Visible = false;                Graphicslayer graphicslayer4 = myMap.Layers["Graphicslayer33"] as Graphicslayer;                graphicslayer4.Visible = false;            }            else            {                Graphicslayer graphicslayer = myMap.Layers["MyGraphicslayer3"] as Graphicslayer;                graphicslayer.Visible = true;                Graphicslayer graphicslayer2 = myMap.Layers["Graphicslayer11"] as Graphicslayer;                graphicslayer2.Visible = true;                Graphicslayer graphicslayer3 = myMap.Layers["Graphicslayer22"] as Graphicslayer;                graphicslayer3.Visible = true;                Graphicslayer graphicslayer4 = myMap.Layers["Graphicslayer33"] as Graphicslayer;                graphicslayer4.Visible = false;            }        }     
总结

以上是内存溢出为你收集整理的ArcGIS API for Silverlight 解决众多密集点分层显示全部内容,希望文章能够帮你解决ArcGIS API for Silverlight 解决众多密集点分层显示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1067542.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存