我有一个地图,其中包含一个带有多个点的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。
答案 0 :(得分: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);
答案 1 :(得分:0)
您可以使用GeometryEngine.Intersects方法检查点图形何时相交,触摸,交叉选择多边形。 https://community.esri.com/message/826699-re-determine-points-that-are-under-a-sketchoverlay-in-a-map?commentID=826699#comment-826699