Example #1
0
        private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
        {
            /* ArcGIS Snippet Title:
             * Find the selected layer in the table of contents
             *
             * Add the following reference to the project:
             * ESRI.ArcGIS.Controls
             *
             * Add the following ArcGIS Engine control to the project:
             * TOCControl
             *
             * Intended ArcGIS Products for this snippet:
             * ArcGIS Engine
             *
             * Notes:
             * This snippet is intended to be inserted into the OnMouseDown event of the TOC Control
             * The code assumes that a module-level variable (m_layer) has been declared as ILayer */

            IBasicMap          map   = null;
            ILayer             layer = null;
            object             other = null;
            object             index = null;
            esriTOCControlItem item  = esriTOCControlItem.esriTOCControlItemNone;

            axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
            if ((item == esriTOCControlItem.esriTOCControlItemLayer))
            {
                m_layer = layer;
            }
        }
 private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
 {
     if (axMapControl1.LayerCount > 0)
     {
         esriTOCControlItem pItem = new esriTOCControlItem();
         pGlobalFeatureLayer = new FeatureLayerClass();
         IBasicMap pBasicMap = new MapClass();
         object    pOther    = new object();
         object    pIndex    = new object();
         axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pBasicMap, ref player, ref pOther, ref pIndex);
     }
     if (e.button == 2)
     {
         contextMenuStrip1.Show(axTOCControl1, e.x, e.y);
     }
     if (axMapControl1.LayerCount > 0)
     {
         esriTOCControlItem pItem = new esriTOCControlItem();
         pGlobalFeatureLayer = new FeatureLayerClass();
         IBasicMap pBasicMap = new MapClass();
         object    pOther    = new object();
         object    pIndex    = new object();
         axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pBasicMap, ref player, ref pOther, ref pIndex);
     }
     if (e.button == 2)
     {
         contextMenuStrip1.Show(axTOCControl1, e.x, e.y);
     }
 }
Example #3
0
 private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)//事件图层列表框(TOCControl)的右键弹出框
 {
     if (e.button == 2)
     {
         ILayer             pLayer       = null;
         IBasicMap          pBasicMap    = null;
         object             plegendGroup = null;
         object             pIndex       = null;
         esriTOCControlItem pTocItem     = esriTOCControlItem.esriTOCControlItemNone;
         axTOCControl1.HitTest(e.x, e.y, ref pTocItem, ref pBasicMap, ref pLayer,
                               ref plegendGroup, ref pIndex);
         selectLayerIndex = Convert.ToInt16(pIndex);
         Console.WriteLine(selectLayerIndex);
         if (pTocItem == esriTOCControlItem.esriTOCControlItemLayer)
         {
             if (pLayer != null)
             {
                 selectLayer = pLayer;
             }
             popupMenu1.ShowPopup(axTOCControl1.PointToScreen(new System.Drawing.Point(e.x, e.y)));
         }
         else if (pTocItem == esriTOCControlItem.esriTOCControlItemMap)
         {
             popupMenu2.ShowPopup(axTOCControl1.PointToScreen(new System.Drawing.Point(e.x, e.y)));
         }
     }
 }
Example #4
0
 private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
 {
     if (e.button == 1) //左键
     {
         esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
         IBasicMap          pMap = null; object unk = null;
         object             data   = null;
         ILayer             pLayer = null;
         axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer, ref unk, ref data);
         pCurrentLayer = pLayer as IFeatureLayer;
         return;
     }
     else if (e.button == 2)
     {
         esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
         IBasicMap          pMap = null; object unk = null;
         object             data   = null;
         ILayer             pLayer = null;
         axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer, ref unk, ref data);
         pCurrentLayer = pLayer as IFeatureLayer;
         if (pItem == esriTOCControlItem.esriTOCControlItemLayer && pCurrentLayer != null)
         {
             contextMenuStrip1.Show(Control.MousePosition);
         }
     }
 }
Example #5
0
        private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
        {
            IBasicMap pMap = null;
            ILayer    pLayer = null;
            object    unk = null, data = null;

            ESRI.ArcGIS.Controls.esriTOCControlItem pItem = ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemNone;
            try
            {
                axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer, ref unk, ref data);
            }
            catch (Exception)
            {
                throw;
            }
            switch (e.button)
            {
            case 2:
                //右键
                if (pItem == ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemMap)
                {
                    axTOCControl1.SelectItem(pMap, null);
                }
                else if (pItem == ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemLayer)
                {
                    axTOCControl1.SelectItem(pLayer, null);
                }

                axMapControl1.CustomProperty = pLayer;
                if (pItem == ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemMap)
                {
                    //
                }
                if (pItem == ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemLayer)
                {
                    var m_pMenuLayer = new ToolbarMenu();
                    m_pMenuLayer.AddItem(new BuildLineBuffer(), -1, 0, false, ESRI.ArcGIS.SystemUI.esriCommandStyles.esriCommandStyleTextOnly);
                    m_pMenuLayer.AddItem(new ShowAttribute(), 1, 1, false, ESRI.ArcGIS.SystemUI.esriCommandStyles.esriCommandStyleTextOnly);
                    m_pMenuLayer.SetHook(axMapControl1);
                    m_pMenuLayer.PopupMenu(e.x, e.y, axTOCControl1.hWnd);
                }
                break;

            default:
                break;
            }
        }
Example #6
0
 private ILayer pLayer;//定义全局变量pLayer
 private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
 {
     if (axMapControl1.LayerCount > 0)
     {
         esriTOCControlItem pItem = new esriTOCControlItem();//用类实例化
         pLayer = new FeatureLayerClass();
         IBasicMap pBasicMap = new MapClass();
         object    pOther    = new object();
         object    pIndex    = new object();
         // Returns the item in the TOCControl at the specified coordinates.
         axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pBasicMap, ref pLayer, ref pOther, ref pIndex);
     }//TOCControl类的ITOCControl接口的HitTest方法,获取坐标
     if (e.button == 2)//等待点击右键
     {
         contextMenuStrip1.Show(axTOCControl1, e.x, e.y);//显示菜单项
     }
 }
Example #7
0
 private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
 {
     if (e.button == 2)
     {
         esriTOCControlItem Item = esriTOCControlItem.esriTOCControlItemNone;
         //esriTOCControlItem Item = new esriTOCControlItem();
         IBasicMap pMap   = null;
         ILayer    pLayer = null;
         object    pOther = new object();
         object    pIndex = new object();
         axTOCControl1.HitTest(e.x, e.y, ref Item, ref pMap, ref pLayer, ref pOther, ref pIndex);
         if (Item == esriTOCControlItem.esriTOCControlItemLayer)
         {
             rightmenu.Show(MousePosition);
         }
     }
 }
Example #8
0
        /// <summary>
        /// TOCC的鼠标点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
        {
            //获得hittest,需要的参数
            esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;                  //TOCC中项的类型

            axTOCControl1.HitTest(e.x, e.y, ref item, ref bMap, ref layer, ref other, ref index); //实现赋值,ref的参数必须初始化
            if (e.button == 1)
            {
                //修改图例功能待添加
            }
            else if (e.button == 2)                                     //右键
            {
                if (item == esriTOCControlItem.esriTOCControlItemLayer) ////点击的是图层的话,就显示右键菜单
                {
                    contextMenuStrip1.Show(axTOCControl1, new System.Drawing.Point(e.x, e.y));
                }
            }
        }
        private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
        {
            //Exit not a right mouse click
            if (e.button != 2)
            {
                return;
            }

            //Determine what kind of item has been clicked on
            esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
            IBasicMap          map = null;
            object             other = null; object index = null;

            m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref m_layer, ref other, ref index);

            //Show the metadata for the layer
            if (m_layer == null)
            {
                return;
            }
            ShowMetadata(m_layer);
        }
Example #10
0
 private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
 {
     if (e.button == 1)
     {
         esriTOCControlItem pitem  = esriTOCControlItem.esriTOCControlItemNone;
         IBasicMap          pmap   = null;
         object             unk    = null;
         object             data   = null;
         ILayer             player = null;
         axTOCControl1.HitTest(e.x, e.y, ref pitem, ref pmap, ref player, ref unk, ref data);
         if (pitem == esriTOCControlItem.esriTOCControlItemLayer)
         {
             if (player is IAnnotationSublayer)
             {
                 return;
             }
             else
             {
                 pmovelayer = player;
             }
         }
     }
     if (e.button == 2)
     {
         esriTOCControlItem pitem  = esriTOCControlItem.esriTOCControlItemNone;
         IBasicMap          pmap   = null;
         object             unk    = null;
         object             data   = null;
         ILayer             player = null;
         axTOCControl1.HitTest(e.x, e.y, ref pitem, ref pmap, ref player, ref unk, ref data);
         ptocfesturelayer = player as IFeatureLayer;
         if (pitem == esriTOCControlItem.esriTOCControlItemLayer && ptocfesturelayer != null)
         {
             axTOCControl1.ContextMenuStrip.Visible = true;
             axTOCControl1.ContextMenuStrip.Show(MousePosition.X, MousePosition.Y);
         }
     }
 }
Example #11
0
 //图层拖动
 private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
 {
     if (e.button == 1)
     {
         esriTOCControlItem item  = esriTOCControlItem.esriTOCControlItemNone;
         IBasicMap          map   = null;
         ILayer             layer = null;
         object             other = null;
         object             index = null;
         mTOCControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
         if (item == esriTOCControlItem.esriTOCControlItemLayer)
         {
             if (layer is IAnnotationSublayer)   //注记层在表层,不参与移动
             {
                 return;
             }
             else
             {
                 pMoveLayer = layer;
             }
         }
     }
 }
Example #12
0
        //  Show the TOC context menu when an NALayer is right-clicked on
        private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
        {
            if (e.button != 2)
            {
                return;
            }

            esriTOCControlItem item  = esriTOCControlItem.esriTOCControlItemNone;
            IBasicMap          map   = null;
            ILayer             layer = null;
            object             other = null;
            object             index = null;

            //Determine what kind of item has been clicked on
            axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);

            // Only implemented a context menu for NALayers.  Exit if the layer is anything else.
            if ((layer as INALayer) == null)
            {
                return;
            }

            axTOCControl1.SelectItem(layer);

            // Set the layer into the CustomProperty.
            // This is used by the other commands to know what layer was right-clicked on
            // in the table of contents.
            axMapControl1.CustomProperty = layer;

            //Popup the correct context menu and update the TOC when it's done.
            if (item == esriTOCControlItem.esriTOCControlItemLayer)
            {
                m_menuLayer.PopupMenu(e.x, e.y, axTOCControl1.hWnd);
                ITOCControl toc = axTOCControl1.Object as ITOCControl;
                toc.Update();
            }
        }
        private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
        {
            //Exit if not right mouse button
            if (e.button != 2)
            {
                return;
            }

            IBasicMap          map   = new MapClass();
            ILayer             layer = new FeatureLayerClass();
            object             other = new Object();
            object             index = new Object();
            esriTOCControlItem item  = new esriTOCControlItem();

            //Determine what kind of item has been clicked on
            axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);

            //QI to IFeatureLayer and IGeoFeatuerLayer interface
            if (layer == null)
            {
                return;
            }
            IFeatureLayer featureLayer = layer as IFeatureLayer;

            if (featureLayer == null)
            {
                return;
            }
            IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
            ISimpleRenderer  simpleRenderer  = (ISimpleRenderer)geoFeatureLayer.Renderer;

            //Create the form with the SymbologyControl
            frmSymbol symbolForm = new frmSymbol();

            //Get the IStyleGalleryItem
            IStyleGalleryItem styleGalleryItem = null;

            //Select SymbologyStyleClass based upon feature type
            switch (featureLayer.FeatureClass.ShapeType)
            {
            case esriGeometryType.esriGeometryPoint:
                styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassMarkerSymbols, simpleRenderer.Symbol);
                break;

            case esriGeometryType.esriGeometryPolyline:
                styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassLineSymbols, simpleRenderer.Symbol);
                break;

            case esriGeometryType.esriGeometryPolygon:
                styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassFillSymbols, simpleRenderer.Symbol);
                break;
            }

            //Release the form
            symbolForm.Dispose();
            this.Activate();

            if (styleGalleryItem == null)
            {
                return;
            }

            //Create a new renderer
            simpleRenderer = new SimpleRendererClass();
            //Set its symbol from the styleGalleryItem
            simpleRenderer.Symbol = (ISymbol)styleGalleryItem.Item;
            //Set the renderer into the geoFeatureLayer
            geoFeatureLayer.Renderer = (IFeatureRenderer)simpleRenderer;

            //Fire contents changed event that the TOCControl listens to
            axPageLayoutControl1.ActiveView.ContentsChanged();
            //Refresh the display
            axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
Example #14
0
 private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
 {
 }
Example #15
0
 private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
 {
     if (e.button == 2)
     {
         //鼠标右键按下
         if (axMapControl1.LayerCount > 0)//主视图中要有地理数据
         {
             esriTOCControlItem mItem  = new esriTOCControlItem();
             IBasicMap          pMap   = new MapClass();
             ILayer             pLayer = new FeatureLayerClass();
             object             pOther = new object();
             object             pIndex = new object();
             axTOCControl1.HitTest(e.x, e.y, ref mItem, ref pMap, ref pLayer, ref pOther, ref pIndex);
             IGeoFeatureLayer pGeoFeatureLayer;
             pGeoFeatureLayer = pLayer as IGeoFeatureLayer;
             //添加显示属性表的代码
             string         layerPath;
             string         layerDatafileName;
             IWorkspaceName pWorkspaceName;
             IDatasetName   pDatasetName;
             IDataLayer     pDataLayer;
             pDataLayer        = pGeoFeatureLayer as IDataLayer;
             pDatasetName      = pDataLayer.DataSourceName as IDatasetName;
             pWorkspaceName    = pDatasetName.WorkspaceName;
             layerPath         = pWorkspaceName.PathName;
             layerDatafileName = pLayer.Name.Trim() + ".dbf";
             string            dbfFilePath       = layerPath;;
             string            dbfFileName       = layerDatafileName;;
             IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
             IWorkspace        pWorkspace        = pWorkspaceFactory.OpenFromFile(dbfFilePath, 0);
             IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
             if (pFeatureWorkspace != null)
             {
                 IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(dbfFileName);
                 if (pFeatureClass != null)
                 {
                     DataTable  dt = new DataTable();
                     DataColumn dc;
                     for (int i = 0; i <= pFeatureClass.Fields.FieldCount - 1; i++)
                     {
                         dc = new DataColumn(pFeatureClass.Fields.get_Field(i).Name);
                         dt.Columns.Add(dc);
                     }
                     IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
                     IFeature       pFeature       = pFeatureCursor.NextFeature();
                     DataRow        dr;
                     while (pFeature != null)
                     {
                         dr = dt.NewRow();
                         for (int j = 0; j <= pFeatureClass.Fields.FieldCount - 1; j++)
                         {
                             if (pFeatureClass.FindField(pFeatureClass.ShapeFieldName) == j)
                             {
                                 dr[j] = pFeatureClass.ShapeType.ToString();
                             }
                             else
                             {
                                 dr[j] = pFeature.get_Value(j).ToString();
                             }
                         }
                         dt.Rows.Add(dr);
                         pFeature = pFeatureCursor.NextFeature();
                     }
                     GeoMapAttribute frmTable = new GeoMapAttribute();
                     frmTable.Show();
                     frmTable.dataGridView1.DataSource = dt;
                 }
             }
         }
     }
 }