ArcGIS Server for Silverlight 之集群(Simple Clusterer)
生活随笔
收集整理的這篇文章主要介紹了
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(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();
????????}
????}
}
效果圖:
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();
????????}
????}
}
效果圖:
轉載于:https://www.cnblogs.com/JinDin/archive/2009/09/29/1576556.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的ArcGIS Server for Silverlight 之集群(Simple Clusterer)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 澎湖县地产泡沫的破灭
- 下一篇: 通过特殊字符查询所在表 或 存储过程