zoukankan      html  css  js  c++  java
  • Arcgis api for silverlight自定义一个Symbol

    工作需要自定义个Arcgis的Symbol,后台代码中包含对项目DLL中Xaml文件读取,摘抄记录下。

    参考:http://blog.csdn.net/leesmn/article/details/6882698

    1. 用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>

    2. 定义一个类OnSymbol继承自MarkerSymbol。

        public class OnSymbol : MarkerSymbol
        {
            public OnSymbol(string username)
                : base()
            {
                try
                {
                    StreamResourceInfo info = App.GetResourceStream(new Uri("SilverlightApplication3;component/OnlineSymbol.xaml", UriKind.RelativeOrAbsolute));
                    StreamReader sr = new StreamReader(info.Stream);                
                    string template = sr.ReadToEnd();
                    template = template.Replace("mynumb", username);
                    this.ControlTemplate = (ControlTemplate)XamlReader.Load(template);
                }
                catch (Exception ex)
                {
                    MainPage.add_to_logger(ex);
                }
            }
        }

    3. 对于图层对象的Symbol就可以直接赋值OnSymbol 实例  

    tmpGraphic.Symbol = new OnSymbol(mobileName);

     

     

  • 相关阅读:
    JavaScript 闭包(转)
    JavaScript 获取键盘扫描码
    前台网站优化方案
    设计模式之装饰者模式
    设计模式之蝇量模式
    设计模式之策略模式
    Algorithm学习之any_of
    Algorithm学习之all_of学习
    Algorithm学习之adjacent_find学习
    数据结构-表达式求值
  • 原文地址:https://www.cnblogs.com/mygod/p/2763504.html
Copyright © 2011-2022 走看看