五、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)设置Graphic的Geometry

(4)应用Graphic的Symbol

(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用于获取Geometries,Geometries可添加到Graphics Layer或用作identify和buffer操作。

使用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);

}

4、Symbols和Renderers

Symbols定义了Graphic的非几何学方面的显示特性,如颜色、边框宽度、透明度等。

Renderers定义了一个或多个应用于Graphics layer的Symbols,指定哪些Graphics属性与哪个Symbol相符。

Symbols和Geometries类型:

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"

(2)xaml文件中定义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>

(3)cs文件中动态生成

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中,指定一个过滤,仅仅California、New York、Kansas被绘制

//并且将其STATE_NAME字段的值显示在layer的Graphics中

<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中,将renderer和Feature layer联系起来,进行地图绘制

//并且将其POP07_SQMI字段的值显示在layer的Graphics中

<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可用于GraphicsLayer和Feature Layer。

(1)使用FlareClusterer

FlareClusterer可按如下方式添加到GraphicsLayer和FeatureLayer中:

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

}

}

【转】ArcGIS API for Silverlight/WPF 2.1学习笔记(二)的更多相关文章

  1. ArcGIS API for Silverlight/WPF 2.1学习笔记(一)——精简版

    一.安装 1.Visual Studio: (1)Visual Studio 2010或Visual Web Developer Express 2010 (2)Silverlight 4 Tools ...

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

    源自:http://blog.163.com/zwx_gis/blog/static/32434435201122193611576/ (主页:http://blog.163.com/zwx_gis/ ...

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

      七.Editing ArcGIS Server 10提供了: 通过feature service,在Web上编辑Feature layers的geographic data的功能. 通过geome ...

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

    2.Find示例代码 (1)xaml文件: //添加Symbol命名空间 xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbol ...

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

    六.Feature Layer Feature Layer是一种特殊的Graphics layer(继承自Graphics layer),除了像Graphics layer一样包含和显示Graphic ...

  6. 扩展ArcGIS API for Silverlight/WPF 中的TextSymbol支持角度标注

    原文 http://blog.csdn.net/esricd/article/details/7587136 在ArcGIS API for Silverlight/WPF中原版的TextSymbol ...

  7. WPF的Binding学习笔记(二)

    原文: http://www.cnblogs.com/pasoraku/archive/2012/10/25/2738428.htmlWPF的Binding学习笔记(二) 上次学了点点Binding的 ...

  8. ArcGIS API for Silverlight学习笔记

    ArcGIS API for Silverlight学习笔记(一):为什么要用Silverlight API(转) 你用上3G手机了吗?你可能会说,我就是喜欢用nokia1100,ABCDEFG跟我都 ...

  9. ArcGIS API for Silverlight开发入门

    你用上3G手机了吗?你可能会说,我就是喜欢用nokia1100,ABCDEFG跟我 都没关系.但你不能否认3G是一种趋势,最终我们每个人都会被包裹在3G网络中.1100也不是一成不变,没准哪天为了打击 ...

随机推荐

  1. python 读取二进制数据到可变缓冲区中

    想直接读取二进制数据到一个可变缓冲区中,而不需要做任何的中间复制操作.或者你想原地修改数据并将它写回到一个文件中去. 为了读取数据到一个可变数组中,使用文件对象的readinto() 方法.比如 im ...

  2. LoadRunner 自动关联、手动关联的帖子

    https://www.guru99.com/correlation-in-loadrunner-ultimate-guide.html 这个网页里介绍了关联的概念,自动关联和手动关联的知识...

  3. Linux基础命令---gzexe

    gzexe 压缩可执行文件,在执行程序的时候可以自动实现解压.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1.语法       g ...

  4. Kotlin新语言简介和快速入门知识点

    Kotlin新语言简介和快速入门知识点 简介:Kotlin是最近由JetBrains发布的一种基于JVM的编程语言,已经被Google宣布为开发Android App的一级语言Kotlin有着与Jav ...

  5. [转载]onclientclick和onclick区别

    OnClientClick是客户端脚本,一般使用javascript,在客户端,也就是IE中运行,点击后马上执行OnClick是服务器端事件处理函数,使用C#或者vb.net,在服务器端,也就是IIS ...

  6. 将图片文件转化为字节数组字符串,并对其进行Base64编码处理,以及对字节数组字符串进行Base64解码并生成图片

    实际开发中涉及图片上传并且量比较大的时候一般处理方式有三种 1.直接保存到项目中 最老土直接方法,也是最不适用的方法,量大对后期部署很不方便 2.直接保存到指定路径的服务器上.需要时候在获取,这种方式 ...

  7. Python Web学习笔记之IGMP和ICMP的差别

    理论技术:TCP/IP协议族(四)ICMP和IGMP协议! 应该先说IP协议的,后来考虑到层次性,还是先把支撑协议介绍完在细说IP!因为IP是我的最爱也是我的痛!呵呵! 一.ICMP协议 为什么要使用 ...

  8. python文件操作-r、w、a、r+、w+、a+和b模式

    对文件操作的基本步骤 f=open('a.txt','r',encoding='utf-8') data=f.read() print(data) f.close() 文件的打开和关闭使用open() ...

  9. linux系统启动顺序及init模式

    磁盘的第一个扇区(512bytes)主要记录了两个重要信息: 主引导分区MBR:master boot record,安装引导加载程序的地方,446bytes 分区表:partition table: ...

  10. 03: zabbix API接口 对 主机、主机组、模板、应用集、监控项、触发器等增删改查

    目录:Django其他篇 01: 安装zabbix server 02:zabbix-agent安装配置 及 web界面管理 03: zabbix API接口 对 主机.主机组.模板.应用集.监控项. ...