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

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

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

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

以下是控件模板的代码:

[html] view plain copy
  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代码如下:

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

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

 

 

后话:

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

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

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

posted on 2013-07-22 18:48 NET未来之路 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/3206266.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值