0

我有一张带有不同点的 GraphicsOverlay 的地图。我让用户能够通过使用 SketchEditor 绘制多边形来选择点的子集。如何确定哪些点已被选中?

以下是设置地图的代码子集:

private GraphicsOverlay graphicsOverlayLow;

// Graphics overlay to host sketch graphics
private GraphicsOverlay _sketchOverlay;

var symbolLow = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Colors.Green, 10d);

graphicsOverlayLow = new GraphicsOverlay() { Renderer = new SimpleRenderer(symbolLow) };

foreach (var graphic in graphicListLow)  // graphicListLow is a List of Points
    graphicsOverlayLow.Graphics.Add(graphic);

MyMapView.GraphicsOverlays = new GraphicsOverlayCollection();

MyMapView.GraphicsOverlays.Add(graphicsOverlayLow);

_sketchOverlay = new GraphicsOverlay();
MyMapView.GraphicsOverlays.Add(_sketchOverlay);

我有两个按钮,一个用于开始绘制多边形,一个用于在完成后单击(这遵循 SketchEditor 的 esri 示例)。启动代码如下:

private async void SelectButton_Click(object sender, RoutedEventArgs e)
{
    try
    {
        // Let the user draw on the map view using the chosen sketch mode
        SketchCreationMode creationMode = SketchCreationMode.Polygon;
        Esri.ArcGISRuntime.Geometry.Geometry geometry = await MyMapView.SketchEditor.StartAsync(creationMode, true);

        // Create and add a graphic from the geometry the user drew
        Graphic graphic = CreateGraphic(geometry);
        _sketchOverlay.Graphics.Add(graphic);
    }
    catch (TaskCanceledException)
    {
        // Ignore ... let the user cancel drawing
    }
    catch (Exception ex)
    {
        // Report exceptions
        MessageBox.Show("Error drawing graphic shape: " + ex.Message);
    }
}


private Graphic CreateGraphic(Esri.ArcGISRuntime.Geometry.Geometry geometry)
{
    // Create a graphic to display the specified geometry
    Symbol symbol = null;
    switch (geometry.GeometryType)
    {
        // Symbolize with a fill symbol
        case GeometryType.Envelope:
        case GeometryType.Polygon:
            {
                symbol = new SimpleFillSymbol()
                {
                    Color = Colors.Red,
                    Style = SimpleFillSymbolStyle.Solid,
                };
                break;
            }

这是当用户单击表示他们已完成绘制多边形的按钮时调用的例程的处理程序。这是我要确定已选择哪些点的地方。

private void CompleteButton_Click(object sender, RoutedEventArgs e)
{
    // Cancel execution of the sketch task if it is already active
    if (MyMapView.SketchEditor.CancelCommand.CanExecute(null))
    {
        MyMapView.SketchEditor.CancelCommand.Execute(null);
    }
}

请注意,我使用的是 100.4 SDK for WPF。

在此处输入图像描述

4

2 回答 2

0

您可以使用 GeometryEngine.Intersects 方法检查点图形何时相交、触摸、交叉选择多边形。 https://community.esri.com/message/826699-re-determine-points-that-are-under-a-sketchoverlay-in-a-map?commentID=826699#comment-826699

于 2019-01-23T18:27:03.233 回答
0

这可以通过空间查询来完成。您将不得不使用草图编辑器返回的几何图形,并使用几何过滤器在图层上执行空间查询。

Esri.ArcGISRuntime.Geometry.Geometry geometry = await MyMapView.SketchEditor.StartAsync(creationMode, true);

var queryparameters = new QueryParameters()
            {
                Geometry = geometry,
                SpatialRelationship = SpatialRelationship.Intersects
            };
await layer.SelectFeaturesAsync(queryparameters, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
于 2019-01-23T00:01:46.393 回答