private void Window_Closed(object sender, EventArgs e) { UCControls.UCVectorDataEditing.m_CreatePolylineDlg = null; CoordList.Clear(); MainWindow.m_AddFeaType = FeaType.None; if (!HasSaved) { MainWindow.m_DotMap.Layers.Remove(m_PolylineLayer as IMapLayer); } }
public void MoveFeature(Coordinate coord) { if (selectFea == null || m_CurrentFeaLyr == null) { return; } //确保目标图层只选中编辑的那一个要素,因为后面会把选中要素移除 m_CurrentFeaLyr.UnSelectAll(); m_CurrentFeaLyr.Selection.Clear(); m_CurrentFeaLyr.Select(selectFea); //move Coordinate moveCoord = new Coordinate(); moveCoord.X = coord.X - selectFea.Geometry.Coordinates[0].X; moveCoord.Y = coord.Y - selectFea.Geometry.Coordinates[0].Y; if (selectFea.FeatureType == FeatureType.Point) { Coordinate resultCoord = new Coordinate(); //move resultCoord.X = selectFea.Geometry.Coordinate.X + moveCoord.X; resultCoord.Y = selectFea.Geometry.Coordinate.Y + moveCoord.Y; IPoint pPoint = new NetTopologySuite.Geometries.Point(resultCoord); lFeaM = m_InputFeaSet.AddFeature(pPoint); for (int i = 0; i < selectFea.DataRow.ItemArray.Count(); i++) { lFeaM.DataRow[i] = selectFea.DataRow[i]; } } else if (selectFea.FeatureType == FeatureType.Line) { //move for (int i = 0; i < selectFea.Geometry.NumPoints; i++) { Coordinate resultCoord = new Coordinate(); resultCoord.X = selectFea.Geometry.Coordinates[i].X + moveCoord.X; resultCoord.Y = selectFea.Geometry.Coordinates[i].Y + moveCoord.Y; CoordList.Add(resultCoord); } ILineString pLine = new LineString(CoordList.ToArray()); lFeaM = m_InputFeaSet.AddFeature(pLine); for (int i = 0; i < selectFea.DataRow.ItemArray.Count(); i++) { lFeaM.DataRow[i] = selectFea.DataRow[i]; } CoordList.Clear(); } else if (selectFea.FeatureType == FeatureType.Polygon) { //move for (int i = 0; i < selectFea.Geometry.NumPoints; i++) { Coordinate resultCoord = new Coordinate(); resultCoord.X = selectFea.Geometry.Coordinates[i].X + moveCoord.X; resultCoord.Y = selectFea.Geometry.Coordinates[i].Y + moveCoord.Y; CoordList.Add(resultCoord); } ILinearRing LineRing = new LinearRing(CoordList.ToArray()); IPolygon pPolygon = new NetTopologySuite.Geometries.Polygon(LineRing); lFeaM = m_InputFeaSet.AddFeature(pPolygon); for (int i = 0; i < selectFea.DataRow.ItemArray.Count(); i++) { lFeaM.DataRow[i] = selectFea.DataRow[i]; } CoordList.Clear(); } //m_CurrentFeaLyr.FeatureSet.AddFeature(lFeaM.Geometry); m_CurrentFeaLyr.RemoveSelectedFeatures(); MainWindow.m_DotMap.ResetBuffer(); MainWindow.m_DotMap.Refresh(); if (MessageBox.Show("Save edit?", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { m_CurrentFeaLyr.FeatureSet.Save(); MessageBox.Show("Save successfully!"); } //移除图层重新加载,因为底层bug 移动节点之后选择要素会报错。 MainWindow.m_AddFeaType = Enum.FeaType.None; MainWindow.m_DotMap.FunctionMode = FunctionMode.None; MainWindow.m_DotMap.Cursor = System.Windows.Forms.Cursors.Default; string shpPath = m_CurrentFeaLyr.FeatureSet.FilePath; string name = m_CurrentFeaLyr.LegendText; var symbol = m_CurrentFeaLyr.Symbolizer; var extent = m_CurrentFeaLyr.Extent; IFeatureSet s = Shapefile.Open(shpPath); MainWindow.m_DotMap.Layers.Remove(m_CurrentFeaLyr as IMapLayer); var result = MainWindow.m_DotMap.Layers.Add(s); result.Symbolizer = symbol; result.Projection = MainWindow.m_DotMap.Projection; result.LegendText = name; //result.Select((result as FeatureLayer).FeatureSet.Features[(result as FeatureLayer).FeatureSet.Features.Count - 1]); this.Close(); }