ArcGIS二次开发基础教程(06):有关图层的基本操作

ArcGIS二次开发基础教程(06):有关图层的基本操作

0. PageLayout和MapControl 的同步

void CopyToPage()
   {
       //对象拷贝,把mapcontrol的地图拷贝重写到pagelayout里
       IObjectCopy copy = new ObjectCopyClass();
       object fromMap = axMapControl1.Map as Object;
       object toMap = axPageLayoutControl1.ActiveView.FocusMap as object;
       object copyMap = copy.Copy(fromMap) as object;
       copy.OverWrite(toMap,copyMap);
   }

//mapdontrol的事件
   void OnAfterScreenDraw(object sender, IMapControlEvents2_OnAfterScreenDrawEvent e)
   {
       //mapcontrol每次刷新都将显示范围设置为mapcontrol的视图
       IActiveView activeView =IPageLayoutControl1.ActiveView.FocusMap;
       IDisplayTransformation displayTransformation = activeView.ScreenDisplay.DisplayTransformation;
       displayTransformation.VisibleBounds = axMapControl1.Extent;
       axPageLayoutControl1.Refresh();
       CopyToPage();
   }

//mapcontrol的事件
   void OnMapReplaced(object sender, IMapControlEvents2_OnMapRepalcedEvent e)
   {
       //增添数据时调用
        CopyToPage();   
   }

1. 基本图层操作(更名,可见性,比例),矢量图层透明度,栅格图层对比度、亮度和透明度

private IFeatureLayer GetLayerByName(string name)
{
    IFeatureLayer featureLayer = null;
    for(int i=0;i

2. 在TOCControl中右击图层名显示菜单,单击属性栏显示图层属性表

ILayer layer = null;//定义图层为全局变量
//TOCControl的点击事件
void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
{
    if(e.Button == 2)//如果是右击
    {
        //TOCControl提供了HitTest方法用来检测控件上被击中的item,参数详情可查阅帮助文档
        IBasicMap basicMap = new MapClass();
        //用来存储被击中的图层
        layer = new FeatureLayerClass();
        object other = new object();
        object index = new object();
        esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
        axTOCControl1.HitTest(e.x, e.y, ref utem, ref layer, ref other, ref index);
        if(item == esriTOCControlItem.esriTOCControlItemLayer)
        {
            //ContextMenuStrip控件 在右键对应位置显示
            contextMenuStrip1.Show(axTOCContorl,new System.Drawing.Point(e.x, e.y));
        }
	}
}
//图层菜单的属性栏点击事件
void attributeToolStripMenuItem_Click(object sender, EventArgs e)
{
    //Attribute是我新建的窗体,构造函数用点击的图层作为参数
    Attribute attribute = new Attribute(layer);
    attribute.Show();
}
//以下是Attribute窗体中的代码
private ILayer myLayer;
public Attribute(ILayer layer)
{
    InitializeComponent();
    myLayer = layer;
}
//Attribute窗体的load事件,当窗体加载的时候把属性表显示出来
private void Attribute_Load(object sender, EventArgs e)
{
    //建表
    DataTable dt = new DataTable();
    DataColumn dc;
    //按表属性字段添加列
    for(int i=0;i

历届GIS应用技能大赛开发题答案点这里,尚在不定期更新中

你可能感兴趣的:(ArcGIS二次开发基础教程(06):有关图层的基本操作)