兰保明

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

在地图上加两个图层如下:
在Graphics 图层中添加一个多边行,但这时多边行没有设置Symbol属性
Symbol="{StaticResource Symbol2}"

<esri:Map Background="White">
     <esri:ArcGISTiledMapServiceLayer ID="PhysicalTiledLayer"
                Url="http://services.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer">
     </esri:ArcGISTiledMapServiceLayer>        
     <esri:GraphicsLayer ID="MyGraphics" >
                <esri:GraphicsLayer.Graphics >               
                    <esri:Graphic>
                        <esriGeometry:Polygon>
                            <esriGeometry:Polygon.Rings>
                                <esriGeometry:PointCollection>
                                    <esriGeometry:MapPoint X="110.039" Y="-20.303"></esriGeometry:MapPoint>
                                    <esriGeometry:MapPoint X="132.539" Y="-7.0137"></esriGeometry:MapPoint>
                                    <esriGeometry:MapPoint X="153.281" Y="-13.923"></esriGeometry:MapPoint>
                                    <esriGeometry:MapPoint X="162.773" Y="-35.174"></esriGeometry:MapPoint>
                                    <esriGeometry:MapPoint X="133.594" Y="-43.180"></esriGeometry:MapPoint>
                                    <esriGeometry:MapPoint X="111.797" Y="-36.032"></esriGeometry:MapPoint>
                                    <esriGeometry:MapPoint X="110.039" Y="-20.303"></esriGeometry:MapPoint>
                                </esriGeometry:PointCollection>
                            </esriGeometry:Polygon.Rings>
                        </esriGeometry:Polygon>
                    </esri:Graphic>
                </esri:GraphicsLayer.Graphics>
         </esri:GraphicsLayer>
  </esri:Map>

这时要建立Symbol资源,手动书写速度慢并且容易出错,好在Expression Blend为我们提供了方便
我们通过可视化的方式来建立Symbol资源,最终得到的代码如下:

<UserControl
 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"
 xmlns:esri="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client"
 xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client"
 xmlns:esriGeometry="clr-namespace:ESRI.ArcGIS.Client.Geometry;assembly=ESRI.ArcGIS.Client"
 x:Class="ArcGISSLSDK_Graphics.UserControl1"
 d:DesignWidth="640" d:DesignHeight="480">
 <UserControl.Resources>
  <esriSymbols:FillSymbol x:Key="F"></esriSymbols:FillSymbol>
  <esriSymbols:FillSymbol x:Key="Symbol1" BorderThickness="2" Fill="Red">
        </esriSymbols:FillSymbol>
  <esriSymbols:FillSymbol x:Key="Symbol2" BorderThickness="3" BorderBrush="Red">
   <esriSymbols:FillSymbol.Fill>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
     <GradientStop Color="Black" Offset="0"/>
     <GradientStop Color="#FFB3D65F" Offset="1"/>
    </LinearGradientBrush>
   </esriSymbols:FillSymbol.Fill>
        </esriSymbols:FillSymbol>
 </UserControl.Resources>
 

 <Grid x:Name="LayoutRoot">
  <esri:Map Background="White">
     <esri:ArcGISTiledMapServiceLayer ID="PhysicalTiledLayer"
                Url="http://services.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer">
     </esri:ArcGISTiledMapServiceLayer>
         
           <esri:GraphicsLayer ID="MyGraphics" >
                <esri:GraphicsLayer.Graphics >
                   
     <esri:Graphic Symbol="{StaticResource Symbol1}">
                  <esriGeometry:MapPoint X="-10.609" Y="23.729"/>
                 </esri:Graphic>
     
     <esri:Graphic Symbol="{StaticResource Symbol2}">
                        <esriGeometry:Polygon>
                            <esriGeometry:Polygon.Rings>
                                <esriGeometry:PointCollection>
                                    <esriGeometry:MapPoint X="110.039" Y="-20.303"></esriGeometry:MapPoint>
                                    <esriGeometry:MapPoint X="132.539" Y="-7.0137"></esriGeometry:MapPoint>
                                    <esriGeometry:MapPoint X="153.281" Y="-13.923"></esriGeometry:MapPoint>
                                    <esriGeometry:MapPoint X="162.773" Y="-35.174"></esriGeometry:MapPoint>
                                    <esriGeometry:MapPoint X="133.594" Y="-43.180"></esriGeometry:MapPoint>
                                    <esriGeometry:MapPoint X="111.797" Y="-36.032"></esriGeometry:MapPoint>
                                    <esriGeometry:MapPoint X="110.039" Y="-20.303"></esriGeometry:MapPoint>
                                </esriGeometry:PointCollection>
                            </esriGeometry:Polygon.Rings>
                        </esriGeometry:Polygon>
                    </esri:Graphic>
                </esri:GraphicsLayer.Graphics>
            </esri:GraphicsLayer>
  </esri:Map>
 </Grid>
</UserControl>

具体操作步骤如下:选取地图控件,找到属性面板如下图:

找到Map Settings 下的layers后面的... 出现如下对话框:

选中GraphicsLayer,出现如下对话框:

点击Graphics后的... 出现下图对话框,在此对话框建立Symbol并把它设置为资源

最终的运行结果为:

posted on 2011-08-03 10:23  兰保明  阅读(512)  评论(0编辑  收藏  举报