两种方式 用 ArCGIS API for Silverlight增加标注

 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, 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);
        }

    }




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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值