private void axTOCControl_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) { esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone; IBasicMap map = null; ILayer layer = null; object other = null; object index = null; _tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); //确保有项目被选择 if (item == esriTOCControlItem.esriTOCControlItemMap) { _tocControl.SelectItem(map, null); } else { _tocControl.SelectItem(layer, null); } //选择的是Map if (item == esriTOCControlItem.esriTOCControlItemMap) { //将Map信息传递给propertyGrid控件 MapInfo _mapInfo = new MapInfo(_mapControl.Map); //propertyGrid.SelectedObject = _mapInfo; //如果是右键点击,弹出菜单 if (e.button == 2) { _mapMenu.PopupMenu(e.x, e.y, _tocControl.hWnd); } } //选择的是 Layer if (item == esriTOCControlItem.esriTOCControlItemLayer) { //将Layer信息传递给PropertyGrid控件 _mapControl.CustomProperty = layer; IFeatureLayer pFeatLyr = layer as IFeatureLayer; if (pFeatLyr == null) { return; } MapLayerInfo _mapLyrInfo = new MapLayerInfo(pFeatLyr, _mapControl.Map); //propertyGrid.SelectedObject = _mapLyrInfo; //_App.StatusBar.Panels[0].Text = "当前选择图层:" + layer.Name; //数据表中出现当前图层数据 //获取有效的图层名称 a_b被解析为a.b string LayerName = LayerDataTable.getValidFeatureClassName(layer.Name); //判断当前图层是否存在Selection IFeatureSelection pFeatureSelection = layer as IFeatureSelection; if (pFeatureSelection.SelectionSet.Count > 0) { LayerName += "_Selection"; if (_App.MainDataSet.Tables.Contains(LayerName)) { _App.MainDataSet.Tables.Remove(LayerName); } DataTable dt = LayerDataTable.CreateDataTable(layer, LayerName); _App.MainDataSet.Tables.Add(dt); } else { if (!this._App.MainDataSet.Tables.Contains(LayerName)) { DataTable dt = LayerDataTable.CreateDataTable(layer, LayerName); _App.MainDataSet.Tables.Add(dt); } } //bindingSource.DataSource = _App.MainDataSet; //bindingSource.DataMember = LayerName; //dataGridView.DataSource = bindingSource; //DataPanel.Text = "数据表[" + LayerName + "]" + " 记录数:" + _DataSet.Tables[LayerName].Rows.Count.ToString(); //dataGridView.Refresh(); } }
/// <summary> /// 图层树控件事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void axTOCControl_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) { esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone; IBasicMap map = null; ILayer layer = null; object other = null; object index = null; _tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); if (index != null) { currentIndex = (int)index; } else { currentIndex = 0; } //确保有项目被选择 //if (item == esriTOCControlItem.esriTOCControlItemMap) //{ // _tocControl.SelectItem(map, null); //} if (item == esriTOCControlItem.esriTOCControlItemLayer && layer == currentLayer) { _tocControl.SelectItem(layer, null); } legend = other; currentLayer = layer; //选择的是Map if (item == esriTOCControlItem.esriTOCControlItemMap) { //将Map信息传递给propertyGrid控件 MapInfo _mapInfo = new MapInfo(_mapControl.Map); //propertyGrid.SelectedObject = _mapInfo; //如果是右键点击,弹出菜单 if (e.button == 2) { _mapMenu.PopupMenu(e.x, e.y, _tocControl.hWnd); } } //选择的是 Layer if (item == esriTOCControlItem.esriTOCControlItemLayer) { if (e.button == 2) { this._mapControl.CustomProperty = layer; _layerMenu.PopupMenu(e.x, e.y, _tocControl.hWnd); } } //Legend 选择的是遥感影像 修改波段 RGB if (item == esriTOCControlItem.esriTOCControlItemLegendClass && e.button == 1) { IRasterLayer pRasterLayer = layer as IRasterLayer; if (pRasterLayer != null && pRasterLayer.BandCount > 1) //判断是影像后排除单波段影像。 { BandSelectorMenu.Items.Clear(); BandSelectorMenu.Items.Add("不可见"); ToolStripSeparator separator = new ToolStripSeparator(); BandSelectorMenu.Items.Add(separator); string toolItem; for (int i = 0; i < pRasterLayer.BandCount; i++) { toolItem = "Band_" + (i + 1); BandSelectorMenu.Items.Add(toolItem); } IRasterRGBRenderer pRGBRender = pRasterLayer.Renderer as IRasterRGBRenderer; ToolStripMenuItem VisuableItem = BandSelectorMenu.Items[0] as ToolStripMenuItem; ToolStripMenuItem ChangeItem; if ((int)index == 0) { if (pRGBRender.UseRedBand == false) { VisuableItem.Checked = true; } else { ChangeItem = BandSelectorMenu.Items[pRGBRender.RedBandIndex + 2] as ToolStripMenuItem; ChangeItem.Checked = true; } } if ((int)index == 1) { if (pRGBRender.UseGreenBand == false) { VisuableItem.Checked = true; } else { ChangeItem = BandSelectorMenu.Items[pRGBRender.GreenBandIndex + 2] as ToolStripMenuItem; ChangeItem.Checked = true; } } if ((int)index == 2) { if (pRGBRender.UseBlueBand == false) { VisuableItem.Checked = true; } else { ChangeItem = BandSelectorMenu.Items[pRGBRender.BlueBandIndex + 2] as ToolStripMenuItem; ChangeItem.Checked = true; } } BandSelectorMenu.Show(axTOCControl1, e.x, e.y); } } }
private void axTOCControl_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) { esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone; IBasicMap map = null; ILayer layer = null; object other = null; object index = null; _tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); if (index != null) { currentIndex = (int)index; } else { currentIndex = 0; } legend = other; currentLayer = layer; //确保有项目被选择 if (item == esriTOCControlItem.esriTOCControlItemMap) { _tocControl.SelectItem(map, null); } else if (item == esriTOCControlItem.esriTOCControlItemLayer) { _tocControl.SelectItem(layer, null); } //else if (item == esriTOCControlItem.esriTOCControlItemLegendClass) //{ // _tocControl.SelectItem(other, null); //} //选择的是Map if (item == esriTOCControlItem.esriTOCControlItemMap) { //将Map信息传递给propertyGrid控件 MapInfo _mapInfo = new MapInfo(_mapControl.Map); //propertyGrid.SelectedObject = _mapInfo; //如果是右键点击,弹出菜单 if (e.button == 2) { _mapMenu.PopupMenu(e.x, e.y, _tocControl.hWnd); } } //选择的是 Layer if (item == esriTOCControlItem.esriTOCControlItemLayer) { if (e.button == 2) { this._mapControl.CustomProperty = layer; _layerMenu.PopupMenu(e.x, e.y, _tocControl.hWnd); } /* * //将Layer信息传递给PropertyGrid控件 * _mapControl.CustomProperty = layer; * IFeatureLayer pFeatLyr = layer as IFeatureLayer; * if (pFeatLyr == null) * return; * MyMainGIS.Library.MapLayerInfo _mapLyrInfo = new MyMainGIS.Library.MapLayerInfo(pFeatLyr, _mapControl.Map); * //propertyGrid.SelectedObject = _mapLyrInfo; * //_App.StatusBar.Panels[0].Text = "当前选择图层:" + layer.Name; * * //数据表中出现当前图层数据 * //获取有效的图层名称 a_b被解析为a.b * string LayerName = LayerDataTable.getValidFeatureClassName(layer.Name); * //判断当前图层是否存在Selection * IFeatureSelection pFeatureSelection = layer as IFeatureSelection; * if (pFeatureSelection.SelectionSet.Count > 0) * { * LayerName += "_Selection"; * if (_App.MainDataSet.Tables.Contains(LayerName)) * { * _App.MainDataSet.Tables.Remove(LayerName); * } * DataTable dt = LayerDataTable.CreateDataTable(layer, LayerName); * _App.MainDataSet.Tables.Add(dt); * } * else * { * if (!this._App.MainDataSet.Tables.Contains(LayerName)) * { * DataTable dt = LayerDataTable.CreateDataTable(layer, LayerName); * _App.MainDataSet.Tables.Add(dt); * } * } * //bindingSource.DataSource = _App.MainDataSet; * //bindingSource.DataMember = LayerName; * //dataGridView.DataSource = bindingSource; * //DataPanel.Text = "数据表[" + LayerName + "]" + " 记录数:" + _DataSet.Tables[LayerName].Rows.Count.ToString(); * //dataGridView.Refresh(); */ } //Legend 选择的是遥感影像 修改波段 RGB if (item == esriTOCControlItem.esriTOCControlItemLegendClass && e.button == 1) { IRasterLayer pRasterLayer = layer as IRasterLayer; if (pRasterLayer != null && pRasterLayer.BandCount > 1) //判断是影像后排除单波段影像。 { BandSelectorMenu.Items.Clear(); BandSelectorMenu.Items.Add("不可见"); ToolStripSeparator separator = new ToolStripSeparator(); BandSelectorMenu.Items.Add(separator); string toolItem; for (int i = 0; i < pRasterLayer.BandCount; i++) { toolItem = "Band_" + (i + 1); BandSelectorMenu.Items.Add(toolItem); } IRasterRGBRenderer pRGBRender = pRasterLayer.Renderer as IRasterRGBRenderer; ToolStripMenuItem VisuableItem = BandSelectorMenu.Items[0] as ToolStripMenuItem; ToolStripMenuItem ChangeItem; if ((int)index == 0) { if (pRGBRender.UseRedBand == false) { VisuableItem.Checked = true; } else { ChangeItem = BandSelectorMenu.Items[pRGBRender.RedBandIndex + 2] as ToolStripMenuItem; ChangeItem.Checked = true; } } if ((int)index == 1) { if (pRGBRender.UseGreenBand == false) { VisuableItem.Checked = true; } else { ChangeItem = BandSelectorMenu.Items[pRGBRender.GreenBandIndex + 2] as ToolStripMenuItem; ChangeItem.Checked = true; } } if ((int)index == 2) { if (pRGBRender.UseBlueBand == false) { VisuableItem.Checked = true; } else { ChangeItem = BandSelectorMenu.Items[pRGBRender.BlueBandIndex + 2] as ToolStripMenuItem; ChangeItem.Checked = true; } } BandSelectorMenu.Show(axTOCControl1, e.x, e.y); } } }