欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

ArcGIS Server for Silverlight 之集群(Simple Clusterer)

发布时间:2025/5/22 编程问答 34 豆豆
生活随笔 收集整理的这篇文章主要介绍了 ArcGIS Server for Silverlight 之集群(Simple Clusterer) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
前台代码:
Code
<UserControl x:Class="SimpleClusterer.MainPage"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d
="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:esri
="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client"
             xmlns:esriSymbols
="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client"
             xmlns:esriGeometry 
="clr-namespace:ESRI.ArcGIS.Client.Geometry;assembly=ESRI.ArcGIS.Client"
             mc:Ignorable
="d" d:DesignWidth="640" d:DesignHeight="480">
  
<Grid x:Name="LayoutRoot">
            
<esri:Map x:Name="myMap" ExtentChanged="myMap_ExtentChanged">
            
<esri:ArcGISTiledMapServiceLayer x:Name="myTiledMapServiceLayer"
                                             Url
="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
            
<esri:GraphicsLayer  ID="mygraphicslayer">
            
</esri:GraphicsLayer>
        
</esri:Map>
    
</Grid>
</UserControl>

Code Behind C#
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Symbols;
using ESRI.ArcGIS.Client.Tasks;

namespace SimpleClusterer
{
    
public partial class MainPage : UserControl
    {
        GraphicsLayer graphicslayer 
= null;
        SimpleMarkerSymbol simpleMarkerSymbol;
        
public MainPage()
        {
            InitializeComponent();
            Init();
        }
        
void Init()
        {
           
            
//获取Graphicslayer
            graphicslayer = myMap.Layers["mygraphicslayer"as GraphicsLayer;

            GradientStopCollection gradientStopColl 
= new GradientStopCollection();
            GradientStop gstop1 
= new GradientStop();
            gstop1.Color 
= Colors.Red;
            gstop1.Offset 
= 0;
            GradientStop gstop2 
= new GradientStop();
            gstop2.Color 
= Colors.Gray;
            gstop2.Offset 
= 0.25;
            GradientStop gstop3 
= new GradientStop();
            gstop3.Color 
= Colors.Black;
            gstop3.Offset 
= 0.5;
            GradientStop gstop4 
= new GradientStop();
            gstop4.Color 
= Colors.Blue;
            gstop4.Offset 
= 0.75;
            GradientStop gstop5 
= new GradientStop();
            gstop5.Color 
= Colors.Green;
            gstop5.Offset 
= 1;

            gradientStopColl.Add(gstop1);
            gradientStopColl.Add(gstop2);
            gradientStopColl.Add(gstop3);
            gradientStopColl.Add(gstop4);
            gradientStopColl.Add(gstop5);

            LinearGradientBrush mylinearGradientBrush 
= new LinearGradientBrush(gradientStopColl,0);
            mylinearGradientBrush.MappingMode 
= BrushMappingMode.RelativeToBoundingBox;

            
//初始化simpleMarkerSymbol
            SolidColorBrush symbolBrush = new SolidColorBrush(Colors.Purple);
            simpleMarkerSymbol 
= new SimpleMarkerSymbol();
            simpleMarkerSymbol.Size 
= 12;
            simpleMarkerSymbol.Style 
= SimpleMarkerSymbol.SimpleMarkerStyle.Circle;
            simpleMarkerSymbol.Color 
= symbolBrush;

            
//设置背景色
            SolidColorBrush backbrush = new SolidColorBrush(Colors.Yellow);
            
//设置前景色
            SolidColorBrush forebrush = new SolidColorBrush();
            forebrush.Color 
= Color.FromArgb(99000);
            
//设置集群
            FlareClusterer myflareClusterer = new FlareClusterer();
            myflareClusterer.FlareBackground 
= backbrush;
            myflareClusterer.FlareForeground 
= forebrush;

            myflareClusterer.Radius 
= 10;
            myflareClusterer.MaximumFlareCount 
= 20//最大个数
            myflareClusterer.Gradient = mylinearGradientBrush;

            graphicslayer.Clusterer 
= myflareClusterer; 
        }

        
void LoadGraphic()
        {
            QueryTask querytask 
= new QueryTask();
            querytask.Url 
= "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0";
            querytask.ExecuteCompleted 
+= new EventHandler<QueryEventArgs>(querytask_ExecuteCompleted);

            Query query 
= new Query();
            query.OutSpatialReferenceWKID 
= myMap.SpatialReference.WKID;
            query.ReturnGeometry 
= true;
            query.Where 
= "1=1";

            querytask.ExecuteAsync(query);
        }

        
void querytask_ExecuteCompleted(object sender, QueryEventArgs e)
        {
            FeatureSet featureset 
= e.FeatureSet;
            
if (featureset == null || featureset.Features.Count < 1)
            {
                MessageBox.Show(
"No features retured from query");
                
return;
            }
            
foreach (Graphic g in featureset.Features)
            {
                g.Symbol 
= simpleMarkerSymbol;
                graphicslayer.Graphics.Add(g);
            }
        }

        
private void myMap_ExtentChanged(object sender, ExtentEventArgs e)
        {
            
if (e.OldExtent == null)
                LoadGraphic();
        }

    }
}

效果图:

转载于:https://www.cnblogs.com/JinDin/archive/2009/09/29/1576556.html

《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读

总结

以上是生活随笔为你收集整理的ArcGIS Server for Silverlight 之集群(Simple Clusterer)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。