ArcGIS API for Silverlight 之ElementLayer使用及TextSymbol的模板使用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ArcGIS API for Silverlight 之ElementLayer使用及TextSymbol的模板使用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2840字,纯文字阅读大概需要5分钟。
内容图文

在开发中动态在地图上添加文字信息,可以使用TextSymbol添加文字
//动态添加文本 TextSymbol textSymbol = new TextSymbol() { FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei"), Foreground = new System.Windows.Media.SolidColorBrush(Color.FromArgb(255, 255, 0, 0)), FontSize = 14, Text = item.ZDMC, OffsetX = 12, OffsetY = -5 }; Graphic graphicText1 = new Graphic() { Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture), double.Parse(item.Longitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture))), Symbol = textSymbol }; graphicText1.Attributes["TextYLZMC"] = item.ZDMC; graphicsLayer1.Graphics.Add(graphicText1);
如果要考虑给文字加背景颜色的话,该类就无法起作用了
//动态添加带背景颜色的文字信息 Border b = new Border(); b.Background = new SolidColorBrush(Colors.Blue); b.Height = 20; b.CornerRadius = new CornerRadius(5); TextBlock tb = new TextBlock(); tb.Text = item.ZDMC; tb.Foreground = new SolidColorBrush(Colors.White); tb.HorizontalAlignment = HorizontalAlignment.Center; tb.FontSize = 15; b.Child = tb; ElementLayer.SetEnvelope(b, new Envelope(new MapPoint(double.Parse(item.Latitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture), double.Parse(item.Longitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture))),new MapPoint(double.Parse(item.Latitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture), double.Parse(item.Longitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture)))); elementLayer.Children.Add(b);
效果如下
提供第二种方法,使用TextSymbol的模板使用:
<esri:TextSymbol x:Key="SWZTextSymbol"> <esri:TextSymbol.ControlTemplate> <ControlTemplate> <Border Background="White" BorderBrush="Black" CornerRadius="5" BorderThickness="1,1,1,1"> <TextBlock Width="70" FontSize="14" Text="{Binding Attributes[TextSWZMC]}" //注意这里的TextSWZMC,和后台代码中要一致 Foreground="Blue" FontFamily="Microsoft YaHei" HorizontalAlignment="Center" /> </Border> </ControlTemplate> </esri:TextSymbol.ControlTemplate> </esri:TextSymbol>
TextSymbol textSymbol = LayoutRoot.Resources["SWZTextSymbol"] as TextSymbol; //这里和模板的Key名称要一致 textSymbol.OffsetX = 15; textSymbol.OffsetY = -15; Graphic graphicText = new Graphic() { Geometry = mercator.FromGeographic(new MapPoint(double.Parse(item.Latitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture), double.Parse(item.Longitute.ToString().Trim(), System.Globalization.CultureInfo.InvariantCulture))), Symbol = textSymbol }; graphicText.Attributes["TextSWZMC"] = item.ZDMC; //注意这里的TextSWZMC,和前台xaml代码中要一致
graphicsLayer11.Graphics.Add(graphicText);
原文:http://www.cnblogs.com/lonelyxmas/p/5754994.html
内容总结
以上是互联网集市为您收集整理的ArcGIS API for Silverlight 之ElementLayer使用及TextSymbol的模板使用全部内容,希望文章能够帮你解决ArcGIS API for Silverlight 之ElementLayer使用及TextSymbol的模板使用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。