日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

【转】ArcGIS API for Silverlight/WPF 2.1学习笔记(二)

發布時間:2025/4/16 asp.net 57 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【转】ArcGIS API for Silverlight/WPF 2.1学习笔记(二) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

五、Graphics layer

1、新增Graphics layer

Graphics layer用于顯示用戶自定義繪制的點、線、面圖形。使用時確保xaml文件中Graphics layer定義在其它圖層的下面,以確保它能顯示在其它圖層的上面。

<esri:Map x:Name="MyMap" Extent=", , , " >

?????? <esri:Map.Layers>???????? ?????????????

<esri:ArcGISTiledMapServiceLayerID="."Url="http://../rest/./MapServer"/>

????????????? <esri:GraphicsLayer ID=”.” />

?????? </esri:Map.Layers>

</esri:Map>

?

2、管理Graphics features

Graphics layer上創建Graphics的步驟一般如下:

1)獲取Graphics layer

2)創建或獲取Graphic

3)設置GraphicGeometry

4)應用GraphicSymbol

5)將Graphic添加到Graphics layers

代碼如下:

GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

foreach (Graphic graphic in graphicsList)

{

??? graphic.Symbol = MySymbol;

??? graphicsLayer.Graphics.Add(graphic);

}

?

3、使用Draw surface

Draw surface用于獲取GeometriesGeometries可添加到Graphics Layer或用作identifybuffer操作。

?????? 使用Draw surface,你必須

1)設置繪圖操作的Symbols

2)設置Draw surface的地圖

3)執行邏輯以激活|解除surface

4)處理Geometries,以在surface上繪圖

示例代碼如下:

xaml文件:

<Grid x:Name="LayoutRoot" Background="White">

????????????? <Grid.Resources>

???????????????????? <esriSymbols:SimpleFillSymbol x:Name="RedFillSymbol" Fill="#66FF0000" BorderBrush="Red" BorderThickness="2" />

????????????? </Grid.Resources>

????????????? <esri:Map …>

cs文件:

MyDrawObject = new Draw(MyMap)

{ LineSymbol =LayoutRoot.Resources["DrawLineSymbol"] as LineSymbol,

FillSymbol =LayoutRoot.Resources["DrawFillSymbol"] as FillSymbol };

MyDrawObject.DrawComplete += MyDrawObject_DrawComplete;

MyDrawObject.DrawMode = DrawMode.Polygon;

MyDrawObject.IsEnabled = true;

private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args)

{

??? Graphic graphic = new Graphic() { Geometry = args.Geometry, Symbol = RedFillSymbol };

GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

graphicsLayer.Graphics.Add(graphic);

}

?

4SymbolsRenderers

?????? Symbols定義了Graphic的非幾何學方面的顯示特性,如顏色、邊框寬度、透明度等。

?????? Renderers定義了一個或多個應用于Graphics layerSymbols,指定哪些Graphics屬性與哪個Symbol相符。

SymbolsGeometries類型:

Symbol

Geometry

描述

SimpleMarkerSymbol

Point

用簡單形狀來表現點

PictureMarkerSymbol

Point

images來表現點

SimpleLineSymbol

Polyline

用預定義的風格來表現線

CartographicLineSymbol

Polyline

用定制的風格來表現線

SimpleFillSymbol

Polygon

Silverlight Brush來填充多邊形

PictureFillSymbol

Polygon

images填充多邊形

?

?

通常,視覺定義在xaml文件中,行為邏輯定義在.cs文件中,讓表現層和業務邏輯層分開,使得應用程序更容易開發、維護和擴展。

?

Symbol的使用:

1)添加命名空間:symbol類定義在ESRI.ArcGIS.Client.Symbols命名空間中(ESRI.ArcGIS.Client集)

xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client"

2xaml文件中定義Symbol

<Grid.Resources>

<esriSymbols:SimpleFillSymbol x:Name="MyRedFillSymbol" Fill="#66FF0000" BorderBrush="Red" BorderThickness="2" />

</Grid.Resources>

//Symbol運用于FeatureLayer

<esri:FeatureLayer ID="." Where="1=1" FeatureSymbol="{StaticResource MyRedFillSymbol}"

Url="http://./ArcGIS/rest/services/./MapServer/5" >

<esri:FeatureLayer.OutFields>

<sys:String>POP07_SQMI</sys:String>

?????? </esri:FeatureLayer.OutFields>

</esri:FeatureLayer>

3cs文件中動態生成

SimpleFillSymbol fillSymbol = new SimpleFillSymbol()

? {

???? BorderBrush = new SolidColorBrush(Color.FromArgb(0, 255, 0, 0)),

???? BorderThickness = 2,

???? Fill = new SolidColorBrush(Color.FromArgb(alphaVal, redVal, greenVal, blueVal))

? };

//Symbol運用于GraphicsLayer的每一個graphic

GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

foreach (Graphic graphic in graphicsLayer.Graphics)

graphic.Symbol = fillSymbol;

?

創建Unique Value Renderer

<Grid.Resources>

<esriSymbols:SimpleFillSymbol x:Name="a" Fill=""BorderBrush=""BorderThickness="" />

<esriSymbols:SimpleFillSymbol x:Name="b" Fill=""BorderBrush=""BorderThickness="" />

<esriSymbols:SimpleFillSymbol x:Name="c" Fill=""BorderBrush=""BorderThickness="" />

?????? <esri:UniqueValueRenderer x:Name="abcRenderer" Attribute="STATE_NAME" >

?????? ?????? <esri:UniqueValueRenderer.Infos>

????????????? ?????? <esri:UniqueValueInfo Value="California" Symbol="{StaticResource ?a}" />

???????????????????? <esri:UniqueValueInfo Value="New York" Symbol="{StaticResource ?b}" />

???????????????????? <esri:UniqueValueInfo Value="Kansas" Symbol="{StaticResource ???c}" />

????????????? </esri:UniqueValueRenderer.Infos>

?????? </esri:UniqueValueRenderer>

</Grid.Resources>

// FeatureLayer中,指定一個過濾,僅僅CaliforniaNew YorkKansas被繪制

//并且將其STATE_NAME字段的值顯示在layerGraphics

<esri:FeatureLayer ID=""

Where="(STATE_NAME='California') OR (STATE_NAME='New York') OR (STATE_NAME = 'Kansas')"

Renderer="{StaticResource ?abcRenderer}"

?????? Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5" >

?????? <esri:FeatureLayer.OutFields>

?????? ?????? <sys:String>STATE_NAME</sys:String>

?????? </esri:FeatureLayer.OutFields>

</esri:FeatureLayer>

?

創建Class Breaks Renderer:即將symbol應用于一組指定范圍的graphics中。

<Grid.Resources>

<esriSymbols:SimpleFillSymbol x:Name="a" Fill="" BorderBrush=""BorderThickness="" />

<esriSymbols:SimpleFillSymbol x:Name="b" Fill="" BorderBrush=""BorderThickness="" />

<esriSymbols:SimpleFillSymbol x:Name="c" Fill="" BorderBrush=""BorderThickness="" />

?????? <esri:ClassBreaksRenderer x:Name="abcRenderer" Attribute="POP07_SQMI" >

????????????? <esri:ClassBreaksRenderer.Classes>

???????????????????? <esri:ClassBreakInfo MinimumValue="0" MaximumValue="50" Symbol="{StaticResource ?a}" />

???????????????????? <esri:ClassBreakInfo MinimumValue="51" MaximumValue="125" Symbol="{StaticResource ?b}" />

???????????????????? <esri:ClassBreakInfo MinimumValue="125" MaximumValue="2000" Symbol="{StaticResource ?c}" />

????????????? </esri:ClassBreaksRenderer.Classes>

?????? </esri:ClassBreaksRenderer>

</Grid.Resources>

// FeatureLayer中,將rendererFeature layer聯系起來,進行地圖繪制

//并且將其POP07_SQMI字段的值顯示在layerGraphics

<esri:FeatureLayer ID="" Where="1=1" Renderer="{StaticResource abcRenderer}"

Url="http://./ArcGIS/rest/services/./MapServer/5" >

?????? <esri:FeatureLayer.OutFields>

????????????? <sys:String>POP07_SQMI</sys:String>

?????? </esri:FeatureLayer.OutFields>

</esri:FeatureLayer>

?

5、使用Clustering(聚類分組,用于render的數量很大時)

當點很多和密集時,使用Clustering將點分組,使得在cluster distance內的多個點用一個點代替。Clustering可用于GraphicsLayerFeature Layer

1)使用FlareClusterer

FlareClusterer可按如下方式添加到GraphicsLayerFeatureLayer中:

<esri:GraphicsLayer ID="MyGraphicsLayer">

?? <esri:GraphicsLayer.Clusterer>

????? <esri:FlareClusterer />

?? </esri:GraphicsLayer.Clusterer>

</esri:GraphicsLayer>

效果如下圖:


FlareClusterer的屬性如下表:

FlareClusterer屬性

描述

FlareBackground

填充的背景顏色(默認紅色)

FlareForeground

邊界和文字顏色(默認白色)

MaximumFlareCount

當鼠標移動到cluster時,各小點是否展開的最大數量界限

小于此值時,鼠標移上去會展開各小點;大于此值時,稱為large clusters,其顏色和大小會根據點多少變化。(默認=10

Radius

cluster的半徑,單位pixels(默認20

Gradient

LinearGradientBrush線性漸變刷用于large clusters

(默認:Default = LinearGradientBrush; MappingMode = RelativeToBoundingBox; GradientStop1: Offset = 0, Argb = 127,255,255,0, GradientStop2: Offset = 1, Argb = 127,255,0,0)

示例:修改FlareClusterer的默認屬性

<Grid.Resources>

<LinearGradientBrush x:Name="aGradient" MappingMode="RelativeToBoundingBox" >

????????????? <GradientStop Color="#990011FF" Offset="0"/>

????????????? <GradientStop Color="#990055FF" Offset="0.25"/>

????????????? <GradientStop Color="#990099FF" Offset="0.5"/>

????????????? <GradientStop Color="#9900CCFF" Offset="0.75"/>

????????????? <GradientStop Color="#9900FFFF" Offset="1"/>

??? </LinearGradientBrush>

</Grid.Resources>

<esri:Map x:Name="MyMap">

??? <esri:Map.Layers>

?????? ?? <esri:GraphicsLayer ID="MyGraphicsLayer">

?????? ??? <esri:GraphicsLayer.Clusterer>

????????????? ?????? <esri:FlareClusterer FlareBackground="Yellow" FlareForeground="#99000000"

????????????? MaximumFlareCount="5" Radius="15" Gradient="{StaticResource aGradient}" />

?????? ??? </esri:GraphicsLayer.Clusterer>

?????? ?? </esri:GraphicsLayer>

??? </esri:Map.Layers>

</esri:Map>

?

2)擴展GraphicsClusterer

為了定制cluster的外觀,你可以創建一個繼承自ESRI.ArcGIS.Client.GraphicsClusterer的類,并重寫OnCreateGraphic()方法來定義cluster graphic。示例代碼如下:

public class SumClusterer : GraphicsClusterer

{

??? public SumClusterer()

??? {

??????? MinimumColor = Colors.Red;

??????? MaximumColor = Colors.Yellow;

??????? SymbolScale = 1;

??????? base.Radius = 50;

??? }

??? 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]); }}

??????? }

??????? 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));

??? }

}



轉載于:https://www.cnblogs.com/changbaishan/p/3305961.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的【转】ArcGIS API for Silverlight/WPF 2.1学习笔记(二)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。