两种方式 用 ArCGIS API for Silverlight增加标注
2012-07-17 16:58
211 查看
1,作为每个标注作为元素进行添加,在ElmentLayer可以放任何SL的控件,可操作性比较强,用起来也比较灵活。可以利用Elment 实现,InfoWindow,tip等功能,当然实现标注可是小菜一碟,
先定义一个UserControl ,XAML 如下
cs 文件如下
主要功能是使textbox1中的文本闪烁
为Map 增加一个Element的Layer
第二种方法,使用TextSymbol 符号化graphic,、
具体代码 如下
XAML
cs内容如下
先定义一个UserControl ,XAML 如下
<UserControl x:Class="VolunteerAction.MyInfoWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="{x:Null}" Height="62" Width="290"> <TextBlock HorizontalAlignment="Right" TextWrapping="Wrap" VerticalAlignment="Top" Height="61" Name="textBlock1" Text="TextBlock" Width="114" FontSize="18" FontStyle="Italic" FontWeight="Bold" FontFamily="Arial" /> </Grid> </UserControl>
cs 文件如下
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace VolunteerAction { public partial class MyInfoWindow : UserControl { public MyInfoWindow() { InitializeComponent(); Storyboard sd = new Storyboard(); sd.AutoReverse = true; ColorAnimation c = new ColorAnimation(); c.From = Color.FromArgb(255, 255, 0, 0); c.To = Color.FromArgb(255, 255, 255, 255); c.Duration = new Duration(new TimeSpan(0,0,0,1,500)); c.RepeatBehavior = RepeatBehavior.Forever; Storyboard.SetTarget(c, textBlock1); Storyboard.SetTargetProperty(c, new PropertyPath("(TextBlock.ForeGround).(SolidColorBrush.Color)")); sd.Children.Add(c); sd.Begin(); } } }
主要功能是使textbox1中的文本闪烁
为Map 增加一个Element的Layer
ElementLayer() _elementLayer = new ElementLayer(); Mymap .Layers.Add(_elementLayer); MapPoint addpt =(MapPoint) g1.Geometry; MyInfoWindow m = new MyInfoWindow(); m.textBlock1.Text = g.Attributes["Name"].ToString(); ElementLayer.SetEnvelope(m, new Envelope(addpt, addpt)); _elementLayer.Children.Add(m);
第二种方法,使用TextSymbol 符号化graphic,、
具体代码 如下
XAML
<UserControl xmlns:esri="http://schemas.esri.com/arcgis/client/2009" x:Class="addLabel.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <esri:Map Extent="13233421.4187963, 3713635.69873,13361710.4066037,3805303.59307" Background="White" x:Name="map" WrapAround="True"> <esri:Map.Layers> <esri:LayerCollection> <esri:ArcGISTiledMapServiceLayer Url="http://www.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineStreetCold/MapServer" /> <esri:FeatureLayer ID="Mylayer" Url="http://tm.arcgisonline.cn:8038/ags10/rest/services/zjPoint/MapServer/0" OutFields="*"></esri:FeatureLayer> </esri:LayerCollection> </esri:Map.Layers> </esri:Map> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="48,117,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /> </Grid> </UserControl>
cs内容如下
namespace addLabel { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { FeatureLayer mylayer = map.Layers["Mylayer"] as FeatureLayer; GraphicCollection gs = mylayer.Graphics; GraphicsLayer layer=new GraphicsLayer (); foreach (Graphic g in gs) { Graphic g1 = new Graphic(); g1.Geometry=g.Geometry; Brush b=new SolidColorBrush(Color.FromArgb(100,0,0,255)); g1.Symbol = new TextSymbol() { Text = g.Attributes["Name_PY"].ToString().Substring(0,5), Foreground=b, FontSize=20 }; layer.Graphics.Add(g1); } map.Layers.Add(layer); } }
相关文章推荐
- ArcGIS API for Silverlight 地图元素点闪烁,线流动显示的处理方式
- 【转】ArCGIS API for Silverlight 实现闪烁标注功能
- arcgis api for js中使用d3.js标注点的属性值代替textsymbol方式
- 扩展ArcGIS API for Silverlight/WPF 中的TextSymbol支持角度标注
- ArcGIS api for javascript——地图配置-增加标注到滑动器
- ArcGIS api for javascript——地图配置-增加标注到滑动器
- arcgis api for js featurelayer 两种查询方式
- ArCGIS API for Silverlight 实现闪烁标注功能
- ArcGIS API for Silverlight 地图元素点闪烁,线流动显示的处理方式
- 扩展ArcGIS API for Silverlight/WPF 中的TextSymbol支持角度标注
- ArcGIS API for Silverlight之Web Mapping开发:根据图层属性查询、定位、高亮显示并显示标注(2)
- (转)扩展ArcGIS API for Silverlight/WPF 中的TextSymbol支持角度标注
- ArCGIS API for Silverlight 实现闪烁标注功能
- ArcGIS API for Silverlight开发入门(5):任务外包——Tasks
- ArcGIS Api for javaScript 4.6 实现地图标注的点击事件
- ArcGIS API for Silverlight开发入门(1):Getting Started
- ArcGIS API for Silverlight开发入门(2):一个基础地图实例
- 使用ArcGIS API for Silverlight + Visifire绘制地图统计图
- FlickrOnMap - A Silverlight Application Developed by Flickr Web API and ArcGIS Server API for Silverlight
- ArcGIS API for Silverlight开发入门准备