/// <summary> /// 从集合中移除指定的shape,通过shape在地图中的实际索引移除 /// </summary> /// <param name="ShapeIndex">shape的索引</param> public void RemoveByShapeIndex(int ShapeIndex) { int i; int j; MainProgram.SelectedShape tShp; if (Program.frmMain.MapMain == null) { return; } for (i = 0; i < m_Shapes.Length; i++) { if (m_Shapes[i].ShapeIndex == ShapeIndex) //找到该shapIndex的对象 { tShp = m_Shapes[i]; if (Program.frmMain.MapMain.ShapeDrawingMethod != MapWinGIS.tkShapeDrawingMethod.dmNewSymbology) { Program.frmMain.MapMain.LockWindow(MapWinGIS.tkLockMode.lmLock); try { Program.frmMain.MapMain.set_ShapePointColor(m_LayerHandle, ShapeIndex, tShp.OriginalColor); Program.frmMain.MapMain.set_ShapeLineColor(m_LayerHandle, ShapeIndex, tShp.OriginalOutlineColor); Program.frmMain.MapMain.set_ShapeFillColor(m_LayerHandle, ShapeIndex, tShp.OriginalColor); Program.frmMain.MapMain.set_ShapeDrawFill(m_LayerHandle, ShapeIndex, tShp.OriginalDrawFill); if (Program.projInfo.TransparentSelection) { Program.frmMain.MapMain.set_ShapeFillTransparency(m_LayerHandle, ShapeIndex, tShp.OriginalTransparency); } } finally { Program.frmMain.MapMain.LockWindow(MapWinGIS.tkLockMode.lmUnlock); } } else { // 新版中ocx会自己选择合适的颜色 MainProgram.Layer layer = (MainProgram.Layer)Program.frmMain.Layers[m_LayerHandle]; if (layer != null) { MapWinGIS.Shapefile sf; sf = (MapWinGIS.Shapefile)(layer.GetObject()); if (sf != null) { sf.ShapeSelected[ShapeIndex] = false; } } } for (j = i; j <= m_NumSelected - 2; j++) { m_Shapes[j] = m_Shapes[j + 1]; } m_Shapes[m_NumSelected - 1] = null; m_NumSelected--; if (m_NumSelected == 0) { m_Shapes = null; } else { Array.Resize(ref m_Shapes, m_NumSelected); } tShp = null; return; //所有的操作完成,直接返回 } } }
/// <summary> /// 从集合中移除指定索引的shape,通过shape存储在集合中的索引删除 /// </summary> /// <param name="ListIndex">要移除的shape的集中对应的索引</param> public void RemoveSelectedShape(int ListIndex) { int i; MainProgram.SelectedShape tShp; int mapIndex; int mapHandle; if (Program.frmMain.MapMain == null) { return; } mapHandle = m_LayerHandle; if (ListIndex >= 0 && ListIndex < m_NumSelected) { Program.frmMain.MapMain.LockWindow(MapWinGIS.tkLockMode.lmLock); try { tShp = m_Shapes[ListIndex]; mapIndex = tShp.ShapeIndex; if (Program.frmMain.MapMain.ShapeDrawingMethod != MapWinGIS.tkShapeDrawingMethod.dmNewSymbology) { Program.frmMain.MapMain.set_ShapePointColor(mapHandle, mapIndex, tShp.OriginalColor); Program.frmMain.MapMain.set_ShapeLineColor(mapHandle, mapIndex, tShp.OriginalOutlineColor); Program.frmMain.MapMain.set_ShapeFillColor(mapHandle, mapIndex, tShp.OriginalColor); Program.frmMain.MapMain.set_ShapeDrawFill(mapHandle, mapIndex, tShp.OriginalDrawFill); if (Program.projInfo.TransparentSelection) { Program.frmMain.MapMain.set_ShapeFillTransparency(mapHandle, mapIndex, tShp.OriginalTransparency); } } else { MainProgram.Layer layer = (MainProgram.Layer)Program.frmMain.Layers[m_LayerHandle]; if (layer != null) { MapWinGIS.Shapefile sf; sf = (MapWinGIS.Shapefile)(layer.GetObject()); if (sf != null) { tShp = m_Shapes[ListIndex]; mapIndex = tShp.ShapeIndex; sf.ShapeSelected[mapIndex] = false; } } } tShp = null; for (i = ListIndex; i < m_NumSelected - 1; i++) //移除并整理数组 { m_Shapes[i] = m_Shapes[i + 1]; } m_Shapes[m_NumSelected - 1] = null; m_NumSelected--; if (m_NumSelected == 0) { m_Shapes = null; } else { Array.Resize(ref m_Shapes, m_NumSelected); } } finally { Program.frmMain.MapMain.LockWindow(MapWinGIS.tkLockMode.lmUnlock); } } else { Program.g_error = "RemoveSelectedShape: 无效的索引"; } }