五、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. 【week6】团队贡献分

    小组名称:nice! 小组成员:李权 于淼 杨柳 刘芳芳 项目内容:约跑app 完成任务:   10% 20% 70% 好   于淼 李权 中   刘芳芳 杨柳 差       1.李权8.4 2.于 ...

  2. Trove系列(五)—Trove的数据存储管理程序类型和版本管理功能介绍

    功能描述数据存储管理程序(Datastore)类型管理允许Trove的用户从操作者列出的名单中选择数据库存储管理程序和版本.操作者将可以控制数据库存储管理程序的类型,添加一个新的版本并去活一个老版本. ...

  3. 【tensorflow】pip 安装失败的原因

    linux系统旧版本:   pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27- ...

  4. java,swift,oc互相转换,html5 web开发跨平台

    java,swift,oc互相转换,html5 web开发跨平台 写一个java->swift的程序,这个程序是做跨平台系统的核心部分swift和oc到java也在考虑之列Swift->J ...

  5. 【运维技术】Maven + Gogs + Nexus 实现版本管理 + 代码模块开发管理

    Gogs:能够实现fork + 代码提交 + 代码框架 Nexus:进行jar包的版本管理,私服下载jar包共享jar包 Maven:在客户端进行模块管理和批量操作 1. 本地maven仓库配置配置s ...

  6. ELK+Kafka学习笔记之搭建ELK+Kafka日志收集系统集群

    0x00 概述 关于如何搭建ELK部分,请参考这篇文章,https://www.cnblogs.com/JetpropelledSnake/p/9893566.html. 该篇用户为非root,使用用 ...

  7. 20145101《Java程序设计》第5周学习总结

    20145101<Java程序设计>第5周学习总结 教材学习内容总结 第八章 异常处理 Java是通过try,catch,throw,throws,finally这5个关键字来实现异常处理 ...

  8. 20165310 java_blog_week4

    2165310 <Java程序设计>第4周学习总结 教材学习内容总结 继承(extends) 同一个包内:继承除了private修饰的变量与方法 不同包内:不继承private和友好,继承 ...

  9. linux内核分析 第5章读书笔记

    第五章 系统调用 一.与内核通信 系统调用在用户控件进程和硬件设备之间添加了一个中间层,作用有: 为用户空间提供了一种硬件的抽象接口 系统调用保证了系统的稳定和安全 每个进程都运行在虚拟系统中,而在用 ...

  10. 海量数据处理-BitMap算法

    一.概述 本文将讲述Bit-Map算法的相关原理,Bit-Map算法的一些利用场景,例如BitMap解决海量数据寻找重复.判断个别元素是否在海量数据当中等问题.最后说说BitMap的特点已经在各个场景 ...