(转)扩展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

<ControlTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  xmlns:esri="http://schemas.esri.com/arcgis/client/2009"  xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">      <TextBlock Text="{Binding Symbol.Text}"                  FontFamily="{Binding Symbol.FontFamily}"                  FontSize="{Binding Symbol.FontSize}"                  Foreground="{Binding Symbol.Foreground}">          <TextBlock.RenderTransform>              <CompositeTransform Rotation="{Binding Symbol.TextRotation}"/>          </TextBlock.RenderTransform>      </TextBlock>  </ControlTemplate> 

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

对象类的加载XAML代码如下: [csharp] view plain copy

base.ControlTemplate = XamlReader.Load(LoadXaml("LabelSymbol.xaml")) as ControlTemplate;            public static string LoadXaml(string FileName)           {              string xamlstring;              var assemblyName = new AssemblyName(Assembly.GetExecutingAssembly().FullName);              string CurrentAssemblyName = assemblyName.Name;              string resourceName = string.Format("{0};component{1}{2}", CurrentAssemblyName, "/", FileName);              Uri uri = new Uri(resourceName, UriKind.Relative);              StreamResourceInfo streamResourceInfo = Application.GetResourceStream(uri);              using (Stream resourceStream = streamResourceInfo.Stream)              {                  using (StreamReader streamReader = new StreamReader(resourceStream))                  {                      xamlstring = streamReader.ReadToEnd();                  }              }              return xamlstring;          } 

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

后话:

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

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

沿

原文地址:https://www.cnblogs.com/enjoyprogram/p/2676375.html