AnsweredAssumed Answered

How to use SketchEditor in a combined Rectangle and Point SketchCreationMode

Question asked by m.glasesri-de-esridist Employee on Feb 20, 2018
Latest reply on Mar 1, 2018 by m.glasesri-de-esridist

Hi,

 

I tried to write an Editing Workflow using the SketchEditor, where the user can select Features with the Rectangle drawing

(SketchCretionMode.Rectangle).

Everything is fine if the user draw a rectangle, the SketchEditor delivers the rectangle geometry as a result which I can use to select my features.

 

But, if the user decides to just select a single object by a click, this will not work with rectangle creation mode. The SketchEditor returns a null object in this case. By the way, this is the same for all SketchCreationModes with values 3 to 9.

 

I tried some workarounds to solve this, the best idea I had was to save the last click in the MapView in a local variable and - if the result of rectangle selection was null - to use this stored map point to select features.

 

private MapPoint _lastLocationClicked;

public MainWindow()
{
   MyMapView.GeoViewTapped += MyMapView_GeoViewTapped;
}

private void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
{
    _lastLocationClicked = e.Location;
}

private async void Select_OnClick(object sender, RoutedEventArgs e)
{
    var creationMode =
        (SketchCreationMode) Enum.Parse(typeof(SketchCreationMode), EditingModeComboBox.SelectionBoxItem.ToString());
    Esri.ArcGISRuntime.Geometry.Geometry geometry =
        await MyMapView.SketchEditor.StartAsync(creationMode, false);

    MyMapView.SketchEditor.ClearGeometry();

    if (geometry != null)
    {
        var query = new QueryParameters() {Geometry = geometry};

        var selection = await MyMapView.Map.OperationalLayers.OfType<FeatureLayer>()
            .First()
            .SelectFeaturesAsync(query, SelectionMode.New);
    }
    else
    {
        if (creationMode == SketchCreationMode.Rectangle)
        {
            //add a scale dependent buffer
            var buffer = MyMapView.MapScale / 500;
            var bufferedGeometry = GeometryEngine.Buffer(_lastLocationClicked, buffer);
            var query = new QueryParameters() {Geometry = bufferedGeometry};

            var selection = await MyMapView.Map.OperationalLayers.OfType<FeatureLayer>()
                .First()
                .SelectFeaturesAsync(query, SelectionMode.New);
        }
        else
        {
            MyMapView.Map.OperationalLayers.OfType<FeatureLayer>()
                .First()
                .ClearSelection();
        }
    }
}

 

Of course, this is not a pretty way, so I have two questions:

  1. Is this the expected behavior, that the geometry returned is null in case of a single map click?
  2. Does anyone have a better idea how to allow both, rectangle and single point selection without enforcing the user to choice between this options manually?

 

Cheers

Max

Outcomes