arcgis api for silverlight自訂一個Symbol

來源:互聯網
上載者:User

用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);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.