arcgis api for silverlight自定义一个Symbol

用xaml写一个ControlTemplate。源码如下

<ControlTemplate 
    xmlns="http://schemas.microsoft.com/client/2007"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
    xmlns:sys="clr-namespace:System;assembly=mscorlib"   
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"    >
    <Grid
        RenderTransformOrigin="0.5,0.5"       
        Height="50"       
        Width="50">
        <Grid.RenderTransform>
            <TransformGroup>
                <ScaleTransform x:Name="scale" ScaleX="1" ScaleY="1" />
                <TranslateTransform X="-25" Y="-25"/>
            </TransformGroup>
        </Grid.RenderTransform>

        <vsm:VisualStateManager.VisualStateGroups>
            <vsm:VisualStateGroup x:Name="CommonStates">
                <vsm:VisualState x:Name="Normal">
                    <Storyboard>
                        <DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="scale" Storyboard.TargetProperty="ScaleX" To="1" Duration="0:0:0.3" />
                        <DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="scale" Storyboard.TargetProperty="ScaleY" To="1" Duration="0:0:0.3" />
                    </Storyboard>
                </vsm:VisualState>
                <vsm:VisualState x:Name="MouseOver">
                    <Storyboard>
                        <DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="scale" Storyboard.TargetProperty="ScaleX" To="2" Duration="0:0:0.3" />
                        <DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="scale" Storyboard.TargetProperty="ScaleY" To="2" Duration="0:0:0.3" />
                    </Storyboard>
                </vsm:VisualState>
            </vsm:VisualStateGroup>
            <vsm:VisualStateGroup x:Name="SelectionStates">
                <vsm:VisualState x:Name="Selected" />
                <vsm:VisualState x:Name="Unselected" />
            </vsm:VisualStateGroup>
        </vsm:VisualStateManager.VisualStateGroups>
        <Image           
            HorizontalAlignment="Center"           
            VerticalAlignment="Center"           
            Height="16"           
            Width="16"           
            Source="Images/sym.png"  
            />
        <Image
            HorizontalAlignment="Center"           
            VerticalAlignment="Center"           
            Height="24"           
            Width="24"           
            Source="Images/symout.png"/>
        <TextBlock HorizontalAlignment="Center"           
            VerticalAlignment="Center"           
            Height="20"           
            Width="40"    
            Margin="0,0,0,30"
            FontWeight="Bold"
            Foreground="Purple"
            FontSize="9"
            Text="mynumb"/>
    </Grid>
</ControlTemplate>

 

改变其属性“生成操作”为”嵌入的资源“(这个很重要)

定义一个类OnSymbol继承自MarkerSymbol

public class OnSymbol : MarkerSymbol
    {
        public OnSymbol(string username)
            : base()
        {
            try
            {
                string key = "LS.PRJ2011.Tracker.OnlinSymbol.xaml";
                Stream stream = typeof(OnSymbol).Assembly.GetManifestResourceStream(key);
                string template = new StreamReader(stream).ReadToEnd();
                //template = template.Replace("force1.png", "force" + sType.ToString() + ".png");
                //template = template.Replace("comp1.png", "comp" + sComp.ToString() + ".png");
                template = template.Replace("mynumb", username);
                this.ControlTemplate = (ControlTemplate)XamlReader.Load(template);
            }
            catch (Exception ex)
            {
                MainPage.add_to_logger(ex);
            }
        }
    }

然后,对于图层对象的Symbol就可以直接赋值OnSymbol 实例

  tmpGraphic.Symbol = new OnSymbol(mobileName);

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

leesmn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值