
1、通用类
#region 多点的簇显示 public class SumClusterer : GraphicsClusterer { public SumClusterer() { Minimumcolor = colors.Red; Maximumcolor = colors.Yellow; SymbolScale = 2; base.Radius = 100; } public string AggregateColumn { get; set; } public double SymbolScale { get; set; } public color Minimumcolor { get; set; } public color Maximumcolor { get; set; } protected overrIDe Graphic OnCreateGraphic(GraphicCollection cluster,MapPoint point,int maxClusterCount) { if (cluster.Count == 1) return cluster[0]; Graphic graphic = null; double sum = 0; foreach (Graphic g in cluster) { if (g.Attributes.ContainsKey(AggregateColumn)) { try { sum += Convert.Todouble(g.Attributes[AggregateColumn]); } catch { } } } double size = (sum + 450) / 30; size = (Math.Log(sum * SymbolScale / 10) * 10 + 20); if (size < 12) size = 12; graphic = new Graphic() { Symbol = new ClusterSymbol() { Size = size },Geometry = point }; graphic.Attributes.Add("Count",sum); graphic.Attributes.Add("Size",size); graphic.Attributes.Add("color",Interpolatecolor(size - 12,100)); return graphic; } private static Brush Interpolatecolor(double value,double max) { value = (int)Math.Round(value * 255.0 / max); if (value > 255) value = 255; else if (value < 0) value = 0; return new SolIDcolorBrush(color.FromArgb(127,255,(byte)value,0)); } } internal class ClusterSymbol : ESRI.ArcGIS.ClIEnt.Symbols.MarkerSymbol { public ClusterSymbol() { string template = @" <ControlTemplate xmlns=""http://schemas.microsoft.com/clIEnt/2007"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" > <GrID IsHitTestVisible=""False""> <Ellipse Fill=""{Binding Attributes[color]}"" WIDth=""{Binding Attributes[Size]}"" Height=""{Binding Attributes[Size]}"" /> <GrID HorizontalAlignment=""Center"" VerticalAlignment=""Center""> <TextBlock Text=""{Binding Attributes[Count]}"" FontSize=""9"" margin=""1,1,0"" FontWeight=""Bold"" Foreground=""#99000000"" /> <TextBlock Text=""{Binding Attributes[Count]}"" FontSize=""9"" margin=""0,1"" FontWeight=""Bold"" Foreground=""White"" /> </GrID> </GrID> </ControlTemplate>"; this.ControlTemplate = System.windows.Markup.XamlReader.Load(template) as ControlTemplate; } public double Size { get; set; } public overrIDe double OffsetX { get { return Size / 2; } set { throw new NotSupportedException(); } } public overrIDe double OffsetY { get { return Size / 2; } set { throw new NotSupportedException(); } } } #endregion voID clIEnt_GetMonitorInfoCompleted(object sender,GetMonitorInfoCompletedEventArgs e) { ObservableCollection<MonitorInfo> List = e.Result; ESRI.ArcGIS.ClIEnt.Projection.WebMercator mercator = new ESRI.ArcGIS.ClIEnt.Projection.WebMercator(); Graphicslayer graphicslayer = myMap.Layers["MyGraphicslayer"] as Graphicslayer; //每次加载时先清空地图上数据 graphicslayer.Cleargraphics(); Uri uri = null; Graphic graphic = null; foreach (MonitorInfo item in List) { if (!string.IsNullOrEmpty(item.Latitute.ToString()) && !string.IsNullOrEmpty(item.Longitute.ToString())) { //有坐标值时,将该监测点添加到地图上去 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,}; //手动为graphic添加属性(需要用到的和数据库表之间的关联) graphic.Attributes["ID"] = item.ID; graphic.Attributes["name"] = item.name; graphic.Attributes["AreaID"] = item.CountyAreaID; for (int i = 0; i < areaID.Length; i++) { if (areaID[i] == item.ID.ToString()) { switch (seedlingType[i]) { case "1": uri = new Uri("Images/red.png",UriKind.relative); break; case "2": uri = new Uri("Images/yellow.png",UriKind.relative); break; case "3": uri = new Uri("Images/green.png",UriKind.relative); break; case "4": uri = new Uri("Images/red.png",UriKind.relative); break; default: break; } } } BitmAPImage image = new BitmAPImage(uri); //定义Symbol样式,包括填充颜色 Symbol symbol = new PictureMarkerSymbol() { OffsetX = 8,OffsetY = 8,Source = image }; graphic.Symbol = symbol; //将该Graphics添加到Graphicslayer中去 graphicslayer.Graphics.Add(graphic); //为众多的监测点提供簇聚合功能 graphicslayer.Clusterer = new SumClusterer() { AggregateColumn = "AreaID",SymbolScale = 0.008 }; //左键菜单 graphic.MouseleftbuttonDown += new MousebuttonEventHandler(Feature_MouseleftbuttonDown); graphic.MouseleftbuttonUp += new MousebuttonEventHandler(Feature_MouseleftbuttonUp); //右键菜单 graphic.MouseRightbuttonDown += new MousebuttonEventHandler(Feature_MouseRightbuttonDown); graphic.MouseRightbuttonUp += new MousebuttonEventHandler(Feature_MouseRightbuttonUp); } else { //不做任何处理,不添加任何点信息 } //坐标点聚焦 ESRI.ArcGIS.ClIEnt.Geometry.Envelope selectedFeatureExtent = graphic.Geometry.Extent; //最后一个点的位置 double expandPercentage = 30; double wIDthExpand = selectedFeatureExtent.WIDth * (expandPercentage / 100); double heightExpand = selectedFeatureExtent.Height * (expandPercentage / 100); ESRI.ArcGIS.ClIEnt.Geometry.Envelope displayExtent = new ESRI.ArcGIS.ClIEnt.Geometry.Envelope( selectedFeatureExtent.XMin - (wIDthExpand / 2),selectedFeatureExtent.YMin - (heightExpand / 2),selectedFeatureExtent.XMax + (wIDthExpand / 2),selectedFeatureExtent.YMax + (heightExpand / 2)); myMap.ZoomTo(displayExtent); } } 总结 以上是内存溢出为你收集整理的ArcGIS API for Silverlight 地图中解决点众多的簇解决方法全部内容,希望文章能够帮你解决ArcGIS API for Silverlight 地图中解决点众多的簇解决方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)