ArcGIS Server for Silverlight 之叢集(Simple Clusterer)

來源:互聯網
上載者:User
前台代碼: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(99, 0, 0, 0);
            //設定叢集
            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();
        }

    }
}

:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.