1,作为每个标注作为元素进行添加,在ElmentLayer可以放任何SL的控件,可操作性比较强,用起来也比较灵活。可以利用Elment 实现,InfoWindow,tip等功能,当然实现标注可是小菜一碟,
先定义一个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);
c.To = Color.FromArgb(255,255);
c.Duration = new Duration(new TimeSpan(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();
}
}
}
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" 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,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);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。