예제 #1
0
 public bool AddVertex(Point worldPosition)
 {
     if (EditMode == EditMode.AddPoint)
     {
         Layer.Add(new Feature {
             Geometry = worldPosition
         });
     }
     else if (EditMode == EditMode.AddLine)
     {
         var firstPoint = worldPosition.Clone();
         // Add a second point right away. The second one will be the 'hover' vertex
         var secondPoint = worldPosition.Clone();
         _addInfo.Vertex  = secondPoint;
         _addInfo.Feature = new Feature {
             Geometry = new LineString(new[] { firstPoint, secondPoint })
         };
         _addInfo.Vertices = _addInfo.Feature.Geometry.MainVertices();
         Layer.Add(_addInfo.Feature);
         Layer.DataHasChanged();
         EditMode = EditMode.DrawingLine;
     }
     else if (EditMode == EditMode.DrawingLine)
     {
         var lineString = (LineString)_addInfo.Feature.Geometry;
         // Set the final position of the 'hover' vertex (that was already part of the geometry)
         SetPointXY(_addInfo.Vertex, worldPosition.Clone());
         _addInfo.Vertex = worldPosition.Clone();  // and create a new hover vertex
         lineString.Vertices.Add(_addInfo.Vertex); // and add it to the geometry
         _addInfo.Feature.RenderedGeometry?.Clear();
         Layer.DataHasChanged();
     }
     else if (EditMode == EditMode.AddPolygon)
     {
         var firstPoint = worldPosition.Clone();
         // Add a second point right away. The second one will be the 'hover' vertex
         var secondPoint = worldPosition.Clone();
         _addInfo.Vertex  = secondPoint;
         _addInfo.Feature = new Feature
         {
             Geometry = new Polygon
             {
                 ExteriorRing = new LinearRing(new[] { firstPoint, secondPoint })
             }
         };
         _addInfo.Vertices = _addInfo.Feature.Geometry.MainVertices();
         Layer.Add(_addInfo.Feature);
         Layer.DataHasChanged();
         EditMode = EditMode.DrawingPolygon;
     }
     else if (EditMode == EditMode.DrawingPolygon)
     {
         var polygon = (Polygon)_addInfo.Feature.Geometry;
         // Set the final position of the 'hover' vertex (that was already part of the geometry)
         SetPointXY(_addInfo.Vertex, worldPosition.Clone());
         _addInfo.Vertex = worldPosition.Clone();            // and create a new hover vertex
         polygon.ExteriorRing.Vertices.Add(_addInfo.Vertex); // and add it to the geometry
         _addInfo.Feature.RenderedGeometry?.Clear();
         Layer.DataHasChanged();
     }
     return(false);
 }