原文 http://blog.csdn.net/esricd/article/details/7587136

在ArcGIS API for Silverlight/WPF中原版的TextSymbol只能支持文字正向显示。在很多实际项目中,往往需要文字标注有一些角度甚至是沿线标注,下面 我们来看一下原装的TextSymbol和扩展后的TextSymbol的比较和实现思路。

要实现右图的效果只需要从TextSymbol继承一个Symbol并增加Rotation属性,并加载相应的控件模板就行了。

以下是控件模板的代码:

  1. <ControlTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
  4. xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
  5. <TextBlock Text="{Binding Symbol.Text}"
  6. FontFamily="{Binding Symbol.FontFamily}"
  7. FontSize="{Binding Symbol.FontSize}"
  8. Foreground="{Binding Symbol.Foreground}">
  9. <TextBlock.RenderTransform>
  10. <CompositeTransform Rotation="{Binding Symbol.TextRotation}"/>
  11. </TextBlock.RenderTransform>
  12. </TextBlock>
  13. </ControlTemplate>

控件模板中需要绑定对象中的文本、字体、字号、颜色、角度五个属性。

对象类的加载XAML代码如下:

  1. base.ControlTemplate = XamlReader.Load(LoadXaml("LabelSymbol.xaml")) as ControlTemplate;
  2. public static string LoadXaml(string FileName)
  3. {
  4. string xamlstring;
  5. var assemblyName = new AssemblyName(Assembly.GetExecutingAssembly().FullName);
  6. string CurrentAssemblyName = assemblyName.Name;
  7. string resourceName = string.Format("{0};component{1}{2}", CurrentAssemblyName, "/", FileName);
  8. Uri uri = new Uri(resourceName, UriKind.Relative);
  9. StreamResourceInfo streamResourceInfo = Application.GetResourceStream(uri);
  10. using (Stream resourceStream = streamResourceInfo.Stream)
  11. {
  12. using (StreamReader streamReader = new StreamReader(resourceStream))
  13. {
  14. xamlstring = streamReader.ReadToEnd();
  15. }
  16. }
  17. return xamlstring;
  18. }

对象类中再定义对应的五个属性就能实现有倾斜角度的标注了。最终实现效果如图:

后话:

这个扩展的Symbol仅仅是对文字符号增加旋转角度,其中还有不完善的地方,在线路转角的地方标注的时候往往会与线交叉,如:

如果再深入完善一下,稍做修改可以将标注做成真正的沿线标注,如:

沿线文本在网上有大量的资料,在这里就不再啰嗦了,希望本文对各位ArcGIS API for Silverlight开发人员有帮助。

扩展ArcGIS API for Silverlight/WPF 中的TextSymbol支持角度标注的更多相关文章

  1. ArcGIS API for Silverlight代码中使用Template模板

    原文:ArcGIS API for Silverlight代码中使用Template模板 在项目开发中,会遇到点选中聚焦闪烁效果,但是因为在使用Symbol的时候,会设置一定的OffSetX和OffS ...

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

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

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

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

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

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

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

      五.Graphics layer 1.新增Graphics layer Graphics layer用于显示用户自定义绘制的点.线.面图形.使用时确保xaml文件中Graphics layer定义 ...

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

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

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

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

  8. ArcGIS API for Silverlight开发入门

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

  9. ArcGIS API for Silverlight学习笔记

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

随机推荐

  1. Could not find qmake configuration file win32-g++

    D:\Source>c:\Qt\Qt5.3.2_static\bin\qmake -makefile -o Makefile my.proCould not find qmake configu ...

  2. linux svn用法

    创建一个版本库.项目目录. 创建一个版本库: svnadmin create ~/SVNTestRepo 创建一个项目目录: svn mkdir file:///home/lsf/SVNTestRep ...

  3. Linux shell编程02 shell程序的执行 及文件权限

    第一个shell脚本 1.       shell编程的方式 交互式shell编程 非交互式shell编程:执行的语句存放到一个文件 shell脚本:可以任意文件名,建议扩展名为sh 2.       ...

  4. Merlin 的魔力: SpringLayout 管理器

    摘自http://tech.it168.com/a2009/0211/265/000000265087_all.shtml 摘自http://cache.baiducontent.com/c?m=9f ...

  5. html天气预报小插件

    <head></head> <body> <iframe width="225" scrolling="no" hei ...

  6. pyqt 正则表达式例子学习

    def rex01(self): username=QtCore.QRegExp('[a-zA-Z0-9_]{2,10}') self.names.setValidator(QtGui.QRegExp ...

  7. C#分层开发MySchool

    分层开发之MYSCHOOL No.1实现登陆功能,验证用户名和密码.从数据库里进行匹配,看是否有符合要求的数据. 在DAL层编写代码,返回值为布尔类型.方法参数为(student实体类对象),使用参数 ...

  8. oracle 临时表空间的增删改查

    oracle 临时表空间的增删改查 oracle 临时表空间的增删改查 1.查看临时表空间 (dba_temp_files视图)(v_$tempfile视图)select tablespace_nam ...

  9. 21. DNS 配置和端口检测

    一.将本机的 DNS 配置为 8.8.8.8 ,用 nslookup (还可以使用 host.dig)验证 # 修改配置文件     # vim /etc/resolv.conf # 在文件的最后加入 ...

  10. Linq:切勿使用 Count() > 0 来判断集合非空

    原文(http://www.cnblogs.com/ldp615/archive/2011/12/11/2284154.html) Linq 出现之前,我们通常使用下面的方式来判断集合是否非空,即集合 ...