基本信息
源码名称:资源环境管理系统源码下载(ArcGIS)
源码大小:5.46M
文件格式:.zip
开发语言:C#
更新时间:2015-07-30
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.ADF;
using System.IO;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI;

namespace 资源环境管理系统
{
    public partial class Form1 : Form
    {
        #region
       
        private int flagSelect = 0;//选择标记
        private ITOCControl2 m_tocControl=null;//TOC控件
        private IMapControl3 m_mapControl = null;//Map控件
        private IToolbarMenu m_menuLayer = null;//图层菜单控件
     
        #endregion
        /// <summary>
        /// 主窗体构造函数
        /// </summary>
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 主窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            //创建鹰眼窗口
            CreateOverviewSymbol();
           //地图控件对应绑定
            m_tocControl = (ITOCControl2)axTOCControl1.Object;
            m_mapControl = (IMapControl3)axMapControl1.Object;

            //设置关联控件
            m_tocControl.SetBuddyControl(m_mapControl);
            axToolbarControl1.SetBuddyControl(m_mapControl);

          //打开图层属性表
            m_menuLayer = new ToolbarMenuClass();
            m_menuLayer.AddItem(new OpenAttributeTableCmd(), 0, 0);
           

            //设置关联hook
            m_menuLayer.SetHook(m_mapControl);
          

        }
        /// <summary>
        /// 加载地图图层
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e)
        {
            IMap pMap;//地图接口
            pMap = axMapControl1.Map;//引用地图控件赋值
            int i;
            //循环加载地图图层
            for (i = 0; i <= pMap.LayerCount - 1; i  )
            {
                axMapControl2.Map.AddLayer(pMap.get_Layer(i));
            }
            //设置图层范围
            this.axMapControl2.Extent = this.axMapControl2.FullExtent;
        }
      
        /// <summary>
        /// 创建鹰眼窗口
        /// </summary>
        private void CreateOverviewSymbol()
        {
            //获取IRGBColor接口.
            IRgbColor color = new RgbColorClass();
            //设置颜色属性
            color.RGB = 255;
            //获取线性符号l接口
            ILineSymbol outline = new SimpleLineSymbolClass();
            //设置线性符号属性
            outline.Width = 2;
            outline.Color = color;
            //获取填充符号接口
            ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
            //设置填充符号属性
            simpleFillSymbol.Outline = outline;
            simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
          
        }


     
        /// <summary>
        /// 鼠标移动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
        {
            toolStripStatusLabel1.Text = "X:"   e.mapX.ToString();//获取地图x坐标
            toolStripStatusLabel2.Text = "Y:"   e.mapY.ToString();//获取地图y坐标
            toolStripStatusLabel3.Text = "地图缩放比例:"   Convert.ToInt32(axMapControl1.FullExtent.Height /
            axMapControl1.Extent.Height * 100)   "%";//获取地图缩放比例

        }
        //打开地图事件
        private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog2 = new OpenFileDialog();//文件选择框
            openFileDialog2.Title = "打开地图文档";//设置标题
            openFileDialog2.Filter = "地图文档 (*.mxd)|*.mxd";//设置过滤条件
            openFileDialog2.ShowDialog();//打开文件选择框
            string sFilePath = openFileDialog2.FileName;//获取选择文件路径
            if (axMapControl1.CheckMxFile(sFilePath))//验证是否地图文档
            {
                axMapControl1.LoadMxFile(sFilePath, 0, Type.Missing);//加载地图文档
            }
            else
            {
                MessageBox.Show(sFilePath   " 格式不正确!");//提示错误
                return;
            }
        }



      /// <summary>
      /// 鼠标按下事件,处理选择事件
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        { 
            //制定几何接口
            axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
            IGeometry selectGeo = null;
            //判断选择标记
            if (flagSelect != 0)
            {
             //分类出来
                switch (flagSelect)
                {
                    case 1://矩形选择
                        selectGeo=axMapControl1.TrackRectangle ();
                        axMapControl2.Refresh();
                        break;
                    case 2://圆形选择
                        selectGeo = axMapControl1.TrackCircle();
                        axMapControl2.Refresh();
                        break;
                    case 3://线性选择
                        selectGeo = axMapControl1.TrackLine();
                        axMapControl2.Refresh();
                        break;
                    default ://清空
                        flagSelect=0;
                        break;
                }
                if (null != selectGeo)
                {
                    axMapControl1.Map.SelectByShape(selectGeo, null, false);
                    axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                }

            }

        }
      
        /// <summary>
        /// 矩形标记事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rectangleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flagSelect = 1;
        }
        /// <summary>
        /// 圆形标记事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void circleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flagSelect = 2;
        }
        /// <summary>
        /// 线性标记事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lineToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flagSelect = 3;
        }

        /// <summary>
        /// 清空事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clearToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //清除选择
            //在这里需要特别注意,在清除选择集前必须做一个刷新,否则在视图上看不到清除的效果
            IActiveView pActiveView = (IActiveView)(axMapControl1.Map);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, axMapControl1.get_Layer(0), null);
            axMapControl1.Map.ClearSelection();
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, axMapControl1.get_Layer(0), null);
            axMapControl2.Refresh();
        }

        //地图内容控件右键菜单
        private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
        {
            if (e.button == 1)
            {
                #region "左键点击图例符号,弹出符号选择对话框"
                IBasicMap map = new MapClass();
                ILayer layer = new FeatureLayerClass();
                object other = new object();
                object index = new object();
                esriTOCControlItem item = new esriTOCControlItem();

                //定义点击类别
                axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
                //查询要素接口
                if (layer == null) return;
                IFeatureLayer featureLayer = layer as IFeatureLayer;
                if (featureLayer == null) return;
                IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;

                ILegendClass legendClass = new LegendClassClass();
                ISymbol symbol = null;
                if (other is ILegendGroup && (int)index != -1)
                {
                    legendClass = ((ILegendGroup)other).get_Class((int)index);
                    symbol = legendClass.Symbol;
                }
                if (symbol == null) return;

                symbol = GetSymbolByControl(symbol);
                if (symbol == null) return;
                legendClass.Symbol = symbol;
                this.Activate();
                //监听内容改变事件
                axMapControl1.ActiveView.ContentsChanged();
                //刷新展示
                axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
                axMapControl2.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
                axTOCControl1.Update();
                #endregion
            }

            if (e.button == 2)
            {
                esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
                IBasicMap map = null; ILayer layer = null;
                object other = null; object index = null;

                //定义选择项类别
                m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);

                //确保选中
                if (item == esriTOCControlItem.esriTOCControlItemMap)
                    m_tocControl.SelectItem(map, null);
                else
                    m_tocControl.SelectItem(layer, null);

                //设置图层自定义属性		
                m_mapControl.CustomProperty = layer;   
                if (item == esriTOCControlItem.esriTOCControlItemLayer) m_menuLayer.PopupMenu(e.x, e.y, m_tocControl.hWnd);
            }
        }
        /// <summary>
        /// 获取样式符号,展示图层符号配置窗口
        /// </summary>
        /// <param name="symbolType"></param>
        /// <returns></returns>
        private ISymbol GetSymbolByControl(ISymbol symbolType)
        {
            ISymbol symbol = null;
            IStyleGalleryItem styleGalleryItem = null;
            esriSymbologyStyleClass styleClass = esriSymbologyStyleClass.esriStyleClassMarkerSymbols;
            if (symbolType is IMarkerSymbol)
            {
                styleClass = esriSymbologyStyleClass.esriStyleClassMarkerSymbols;
            }
            if (symbolType is ILineSymbol)
            {
                styleClass = esriSymbologyStyleClass.esriStyleClassLineSymbols;
            }
            if (symbolType is IFillSymbol)
            {
                styleClass = esriSymbologyStyleClass.esriStyleClassFillSymbols;
            }
            GetSymbolByControlForm symbolForm = new GetSymbolByControlForm(styleClass);
            symbolForm.ShowDialog();
            styleGalleryItem = symbolForm.m_styleGalleryItem;
            if (styleGalleryItem == null) return null;
            symbol = styleGalleryItem.Item as ISymbol;
            symbolForm.Dispose();
            this.Activate();
            return symbol;
        }

        /// <summary>
        /// 属性选择事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void selectByAttributesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ICommand command = new AttributeQueryCmd();
            command.OnCreate(m_mapControl.Object);
            command.OnClick();
        }

       

        }
    }