SketchEditor broken in Quartz (WPF/v100.0)?

2490
15
12-12-2016 01:25 PM
KeithGemeinhart1
New Contributor III

I have code that I wrote in .NET runtime 10.2.7 using the MapView.Editor that allows the user to draw a polyline on the map. I'm sure it came from one of the samples. I'm trying to do the same thing in Quartz (WPF only), and it doesn't seem to work as expected. When I click my button, the map is clearly in editor mode, and I can click to draw the polyline. However, there doesn't seem to be a way to end the editing mode. Typically this is a double-click, but that does nothing. I'm left with the polyline in edit mode.

Maybe I'm missing a step, but I couldn't find an example in the docs or in the sample code.

Here is my button click code:

private async void Button_Click(object sender, RoutedEventArgs e)
{
    var geometry = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Polyline);

    GraphicsOverlay graphicsOverlay;
    if (MyMapView.GraphicsOverlays.Count < 1)
    {
        graphicsOverlay = new GraphicsOverlay();
        MyMapView.GraphicsOverlays.Add(graphicsOverlay);
    }
    else
        graphicsOverlay = MyMapView.GraphicsOverlays[0];

    var outlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Black, 1.0);
    var line = new Graphic(geometry, outlineSymbol);

    graphicsOverlay.Graphics.Add(line);
}
0 Kudos
15 Replies
StefanKallin1
New Contributor II

The new editor is slightly different compared to the one present in version 10.2.7.

The new one offer two ways of drawing geometries; "Draw and edit" (default) and "draw and commit".

If you use the StartAsync method with the boolean drawAndEdit set to false you will be able to commit your geometry using double-click.

var geometry = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Polyline, false)

The default option offer a more flexible way of creating and editing geometries but as far as I can tell you will have to call SketchEditor.CompleteCommand.Execute(null) yourself to finalize the geometry and exit edit mode.

I will let you know if I find some other solution to this.

KeithGemeinhart1
New Contributor III

Awesome! Such a small detail made a huge difference. Thanks!!

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

We'll review the doc for this area and look at clarifying the behavior (SketchEditor.StartAsync Method (SketchCreationMode, Boolean)).

Cheers

Mike

BjørnarSundsbø1
Occasional Contributor II

I've just upgraded to 100.2.0, and experience the same problem with double click not completing/cancelling the edit. I've tried passing in false to drawAndEdit, but it is not completed. Double clicking the right mouse button cancels the edit though, but that doesn't seem like an intuitive way of exiting. I've also tried subscribing to the GeoViewDoubleTapped event to complete/cancel the operation, but this event is not triggered every time on double click. I assume it is because I'm the last delegate, and the event has already been set to Handled,and my handler is not called.

Since I need to add an initial point to start measuring at the right click location, I pass a polyline with the initial position.

Even if drawAndEdit = false would have worked, this parameter is not available to the override that accept a geometry. I suppose that in some way it makes sense that drawAndEdit would be enabled since the documentation says the parameter edits the existing geometry. In the past, you could implement some events to add the initial point, but I can't find these events to do the same as before.

0 Kudos
JenniferNery
Esri Regular Contributor

As you pointed out `drawAndEdit`, which completes draw by double-click for SketchCreationMode.Polygon/Polygline, is not an option when passing existing geometry. But you should be able to execute Cancel/Complete any time to mimic the same behavior during edit. Are you seeing a regression in v100.2.0?

I had just tried the following code with latest. GeoViewDoubleTapped event fires just fine, CompleteCommand also gets executed returning the updated geometry. 

public MainWindow()
{
    InitializeComponent();

    MyMapView.Map = new Map(Basemap.CreateTopographic());
    MyMapView.GraphicsOverlays.Add(new GraphicsOverlay());


    MyMapView.GeoViewDoubleTapped += (s, e) =>
      {
          if (_editStarted && MyMapView.SketchEditor.CompleteCommand.CanExecute(null))
              MyMapView.SketchEditor.CompleteCommand.Execute(null);
      };
}

private async void OnDraw(object sender, RoutedEventArgs e)
{
    try
    {
        var geometry = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Polygon, false);
        var overlay = MyMapView.GraphicsOverlays[0];
        overlay.Graphics.Add(new Graphic(geometry, new SimpleFillSymbol()));
    }
    catch (TaskCanceledException) { }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, ex.GetType().Name);
    }
}

private bool _editStarted = false;
private async void OnEdit(object sender, RoutedEventArgs e)
{
    Graphic graphic = null;
    try
    {
        var overlay = MyMapView.GraphicsOverlays[0];
        graphic = overlay.Graphics.FirstOrDefault();
        if (graphic == null)
            return;
        graphic.IsVisible = false;
        _editStarted = true;
        var geometry = await MyMapView.SketchEditor.StartAsync(graphic.Geometry);
        graphic.Geometry = geometry;
    }
    catch (TaskCanceledException) { }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, ex.GetType().Name);
    }
    finally
    {
        _editStarted = false;
        if (graphic != null)
            graphic.IsVisible = true;
    }
}

Can you share some code on how I may be able to reproduce the issue? 

Thank you.

0 Kudos
BjørnarSundsbø1
Occasional Contributor II

I'll try to mock up a sample. However, I forgot to mention that I'm upgrading from 10.2.7, so I can't say for sure that there is a regression from 100.1. I'll try to tripple check my claim that the GeoViewDoubleTapped event is not raised on double click, tomorrow.

0 Kudos
BjørnarSundsbø1
Occasional Contributor II

Jennifer Nery Submitted as part of support case with title "ArcGIS .Net Runtime 100.2.0 crashes"

0 Kudos
KeithGemeinhart1
New Contributor III

This has gotten me on the right track, but I have a quick follow-up .... If I have this line of code to sketch a shape, it throws an exception if the user presses the Enter/Return key while the shape is editable. I've tried capturing the key press on both the map view and main window, but this happens before the key down or up events.

_geometry = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Polyline, true);

I'm attaching a screenshot of the exception details.

0 Kudos
StefanKallin1
New Contributor II
 try
 {
 geometry = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Polyline) as Polyline;
 }
 catch (TaskCanceledException)
 { }

This should solve this particular issue. I used this in my test code.