Select to view content in your preferred language

SketchEditor settings C#/WPF

1771
2
08-07-2019 03:56 AM
KiroAndreev1
Emerging Contributor

Dear,

In attached file send you video where is present situation which is NOT OK.I would like:

  1. When click on the vertex to drag polygon, not how is on video where first click vertex(and select vertex) and second drag vertex.I would like to drag vertex without select.
  2. l would like polygon don't change form if i click into or outside polygon when is on edit mode with Sketch editor.

How to setting Sketch Editor class?

I am using ArcGIS Runtime 100.5.

Best Regard

0 Kudos
2 Replies
ZackAllen
Esri Contributor

Hi Kiro, thank you for reaching out! For #1, you want to disable the RequireSelectionBeforeDrag option in the SketchEditConfiguration.

// Create a configuration for the sketch editor
SketchEditConfiguration configuration = new SketchEditConfiguration();
configuration.RequireSelectionBeforeDrag = false;
configuration.VertexEditMode = SketchVertexEditMode.InteractionEdit;

// Start the SketchEditor using your configuration.
var geometry = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Polygon, configuration);

For #3, SketchEditor does not currently have a configuration for editing polygons without adding/removing vertices. However, there is a workaround for your case.

You can add an event handler to the SketchEditor for when geometry is changed.

MyMapView.SketchEditor.GeometryChanged += Sketch_Geometry_Changed;
private void Sketch_Geometry_Changed(object sender, GeometryChangedEventArgs e)
{
    if(e.OldGeometry != null && e.OldGeometry.GeometryType == GeometryType.Polygon)
    {
        // Count the number of points before and after the geometry was changed.
        int oldPoints = (e.OldGeometry as Polygon).Parts.Sum(part => part.PointCount);
        int newPoints = (e.NewGeometry as Polygon).Parts.Sum(part => part.PointCount);

        if(newPoints != oldPoints)
        {
            // Replace the geometry beind edited with the polygon from before the change.
            MyMapView.SketchEditor.ReplaceGeometry(e.OldGeometry);
        }
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

If you need to add points to polygons later, just remove the event handler.

MyMapView.SketchEditor.GeometryChanged -= Sketch_Geometry_Changed;

Hopefully this helps,

Zack

KiroAndreev1
Emerging Contributor

Dear Zack Allen,

The example is of great help. But i have and another problem.

My  function SketchEditor_GeometryChanged is

private void SketchEditor_GeometryChanged(object sender, GeometryChangedEventArgs e)
{

if (e.OldGeometry != null && e.OldGeometry.GeometryType == GeometryType.Polygon)
{
// Count the number of points before and after the geometry was changed.
int oldPoints = (e.OldGeometry as Polygon).Parts.Sum(part => part.PointCount);
int newPoints = (e.NewGeometry as Polygon).Parts.Sum(part => part.PointCount);

if (newPoints == oldPoints)
{

if (GlobalVar.CommandBP == "attributeBuilding" || GlobalVar.CommandBP == "editbuilding" || GlobalVar.CommandBP == "holeBuilding" || GlobalVar.CommandBP == "attributeParcShape" || GlobalVar.CommandBP == "editparcel")
{
//Clear table
GlobalVar.BuildingCoordinates.Clear();
clearCoordTable();
_overlay_Point_Build.Graphics.Clear();
_overlay_Line_Build_Label.Graphics.Clear();
_overlay_Point_Build_Label.Graphics.Clear();
_overlay_Line_Build.Graphics.Clear();
SketchEditor sketch = sender as SketchEditor;
//Update table
var coords = sketch.Geometry as Multipart;
var points = coords.Parts.First().Points;
for (int i = 0; i < points.Count; i++)
{
GlobalVar.BuildingCoordinates.Add(new CoordinateTable((i + 1).ToString(), Math.Round(points.X, 2).ToString(), Math.Round(points.Y, 2).ToString()));
}
coordTable.ItemsSource = GlobalVar.BuildingCoordinates;
coordTable.Items.Refresh();
_overlay_Build_First.Graphics.Clear();
Graphic graphic = new Graphic(sketch.Geometry);
GlobalVar.SketchGraph = sketch.Geometry.ToJson();
_overlay_Build_First.Graphics.Add(graphic);
//Update graphic
Sketch.Sketch sketch1 = new Sketch.Sketch(_overlay_Build_First, _overlay_Buildngs_Label, _overlay_Line_Build, _overlay_Point_Build, _overlay_Line_Build_Label, _overlay_Point_Build_Label);
sketch1.EditBuildAsyncFinish();
}
if (GlobalVar.CommandBP == "divbuild" || GlobalVar.CommandBP == "divparcel")
{
GlobalVar.BuildingCoordinates.Clear();
clearCoordTable();
_overlay_Line_First.Graphics.Clear();
_overlay_Point_Build.Graphics.Clear();
SketchEditor sketch = sender as SketchEditor;
//Update table
var coords = sketch.Geometry as Multipart;
var points = coords.Parts.First().Points;
for (int i = 0; i < points.Count; i++)
{
GlobalVar.BuildingCoordinates.Add(new CoordinateTable((i + 1).ToString(), Math.Round(points.X, 2).ToString(), Math.Round(points.Y, 2).ToString()));
}
coordTable.ItemsSource = GlobalVar.BuildingCoordinates;
coordTable.Items.Refresh();
//Update graphic
Sketch.Sketch sketchFinish = new Sketch.Sketch(_overlay_Line_First, _overlay_Point_Build);
sketchFinish.editDelimiterDVDAsyncFinish();
}

}
else
{
MyMapView.SketchEditor.ReplaceGeometry(e.OldGeometry);

}

}
}

 if oldPoints !=newPoints then execute 

MyMapView.SketchEditor.ReplaceGeometry(e.OldGeometry);

after that execute one more time SketchEditor_GeometryChanged  and application crash.

Message is:

System.StackOverflowException
HResult=0x800703E9
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>

SketchEditor_GeometryChanged i call into Initialize() in MainWindow() 

 MyMapView.SketchEditor.GeometryChanged += SketchEditor_GeometryChanged;

0 Kudos