• ArcGIS 中UniqueValueRenderer和SimpleRenderer的异同点


        唯一值渲染器:UniqueValueRenderer用符号表示一组有匹配属性的图形,这通常用于名词或字符串数据。SimpleRenderer是使用单一符号进行着色分类,不涉及对要素的数据进行处理。这种专题图同一个图层内的所有元素都是一种符号。通过SimpleRenderer对象对Symbol进行设置后,赋予FeatureLayer接口的Renderer属性就可以了。

    ESRI.ArcGIS.Client.UniqueValueInfo info = new UniqueValueInfo();
                info.Value = "0";
                info.Symbol = this.CreateSymbolFromEmbedFile("GQYPGIS.MapElement.Symbols.BayonetSymbol.xml");
    
                ESRI.ArcGIS.Client.UniqueValueInfo info1 = new UniqueValueInfo();
                info.Value = "1";
                info.Symbol = this.CreateSymbolFromEmbedFile("GQYPGIS.MapElement.Symbols.CameraSymbol.xml");
    
    
                ESRI.ArcGIS.Client.UniqueValueInfo info2 = new UniqueValueInfo();
                info.Value = "2";
                info.Symbol = this.CreateSymbolFromEmbedFile("GQYPGIS.MapElement.Symbols.CameraSymbol.xml");
    
              
                ESRI.ArcGIS.Client.UniqueValueInfo info3 = new UniqueValueInfo();
                info.Value = "3";
                info.Symbol = this.CreateSymbolFromEmbedFile("GQYPGIS.MapElement.Symbols.CameraSymbol.xml");
    
    
                ESRI.ArcGIS.Client.UniqueValueRenderer renderer = new ESRI.ArcGIS.Client.UniqueValueRenderer();
                renderer.Field = "CAMERATYPE";
                renderer.Infos.Add(info);
    
                this.Renderer = renderer;  
    
                public Symbol CreateSymbolFromEmbedFile(string embedFile)
            {
                Assembly ass = Assembly.GetExecutingAssembly();
                System.IO.UnmanagedMemoryStream ums = ass.GetManifestResourceStream(embedFile) as System.IO.UnmanagedMemoryStream;
                byte[] bytes = new byte[ums.Length];
                ums.Read(bytes, 0, (int)ums.Length);
                string xmlString = System.Text.Encoding.UTF8.GetString(bytes);
                xmlString = System.Text.RegularExpressions.Regex.Replace(xmlString, "^[^<]", "");
                byte[] datas = System.Text.Encoding.ASCII.GetBytes(xmlString);
                System.IO.MemoryStream ms = new MemoryStream(datas);
                MarkerSymbol symbol = new MarkerSymbol();
                symbol.ControlTemplate = (ControlTemplate)System.Windows.Markup.XamlReader.Load(ms);
                return symbol;
    
            }

    在上述的例子中,this代表的是一个继承自FeatureLayer的摄像机图层,这里也列出 GQYPGIS.MapElement.Symbols.CameraSymbol.xml里面的具体内容,这里面把从该xml文件读取相应的ControlTemplate并作为UniqueValueInfo的Symbol

    <ControlTemplate
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:esri="http://schemas.esri.com/arcgis/client/2009" >
    
      <Grid>
        <VisualStateManager.VisualStateGroups>
          <VisualStateGroup x:Name="CommonStates">
            <VisualState x:Name="Normal" />
            <VisualState x:Name="MouseOver">        
            </VisualState>
          </VisualStateGroup>
          <VisualStateGroup x:Name="SelectionStates">
            <VisualState x:Name="Unselected" />
            <VisualState x:Name="Selected">
              <Storyboard>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="MarkerSymbolVideoImg1">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="MarkerSymbolVideoImg2">
                  <DiscreteObjectKeyFrame KeyTime="0"  Value="{x:Static Visibility.Visible}"/>
                </ObjectAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
          </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Image Name="MarkerSymbolVideoImg1" Source="/GQYPGIS;component/Source/Image/point_video.png" Visibility="Visible" Width="6"  Height="6" />
        <Image Name="MarkerSymbolVideoImg2" Source="/GQYPGIS;component/Source/Image/point_video_hit.png" Visibility="Hidden" Width="6" Height="6" />
      </Grid>
      
    </ControlTemplate>

       这里必须注意的是要把该xml文件设置成一种嵌入式资源来进行使用,否则是不能正常使用的。其实SimpleRender的用法差不错,也是将获取到的Symbol赋值给SimpleRender的一个对象,下面贴出部分代码。 

    Assembly ass = Assembly.GetExecutingAssembly();
                System.IO.UnmanagedMemoryStream ums = ass.GetManifestResourceStream("ServerShell.ServerWindows.IGIS.MapElement.Symbols.BayonetSymbol.xml") as System.IO.UnmanagedMemoryStream;
                byte[] bytes = new byte[ums.Length];
                ums.Read(bytes, 0, (int)ums.Length);
                string xmlString = System.Text.Encoding.UTF8.GetString(bytes);
                xmlString = System.Text.RegularExpressions.Regex.Replace(xmlString, "^[^<]", "");
                xmlString = xmlString.Replace("Width="6"", "Width="" + size.ToString() + """);
                xmlString = xmlString.Replace("Height="6"", "Height="" + size.ToString() + """);
    
                byte[] datas = System.Text.Encoding.ASCII.GetBytes(xmlString);
                System.IO.MemoryStream ms = new System.IO.MemoryStream(datas);
                MarkerSymbol symbol = new MarkerSymbol();
                symbol.ControlTemplate = (System.Windows.Controls.ControlTemplate)System.Windows.Markup.XamlReader.Load(ms);
                this.Renderer = new SimpleRenderer()
                {
                    Symbol = symbol
                };
    <ControlTemplate
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:esri="http://schemas.esri.com/arcgis/client/2009" >
    
      <Grid>
        <VisualStateManager.VisualStateGroups>
          <VisualStateGroup x:Name="CommonStates">
            <VisualState x:Name="Normal" />
            <VisualState x:Name="MouseOver">
            </VisualState>
          </VisualStateGroup>
          <VisualStateGroup x:Name="SelectionStates">
            <VisualState x:Name="Unselected" />
            <VisualState x:Name="Selected">
              <Storyboard>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="MarkerSymbolCheckPointImg1">
                  <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="MarkerSymbolCheckPointImg2">
                  <DiscreteObjectKeyFrame KeyTime="0"  Value="{x:Static Visibility.Visible}"/>
                </ObjectAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
          </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    
        <Image Name="MarkerSymbolCheckPointImg1" Source="/ServerShell;component/Source/Image/point_checkpoint.png" Visibility="Visible" Width="6"  Height="6"/>
        <Image Name="MarkerSymbolCheckPointImg2" Source="/ServerShell;component/Source/Image/point_checkpoint_hit.png" Visibility="Hidden" Width="6"  Height="6"/>
      </Grid>
      
    </ControlTemplate>

        其实采用上面的两种方式都是差不多的,都能够将相应的图片添加到相应地图层上面去,另外通过读取xml的这种方式能够通过代码的方式去控制添加图片的宽度和高度,这个也是非常好的一种方式,如果直接在前台进行代码的书写,那么在程序中将非常不好更改,这一点采用xml的方式会比较灵活的。

      

  • 相关阅读:
    Monkey测试
    第八周作业-说说本周项目工作中的情况
    第七周作业-谈谈各种文档
    第六周作业-UML在详细设计阶段的使用心得&&UML建模与软件开发过程模型
    第五周作业-Markdown的使用心得
    第四周作业-Java Web学习心得
    第三周作业-谈谈对编程规范的认识
    第二周作业-软件工作量的估计
    支付宝-发展史及其优缺点
    三种软件的特点分析
  • 原文地址:https://www.cnblogs.com/seekdream/p/5102608.html
Copyright © 2020-2023  润新知