I want to create a polyline using a Button, not a Tool (see why below ). I use the following code:
protected override async void OnClick()
{
try
{
var spatialRef = GeometryFunctions.CreateLV95SpatialReference();
// Get mouse coordinates
System.Drawing.Point screenPoint = Cursor.Position;
System.Windows.Point winPoint = new System.Windows.Point(screenPoint.X, screenPoint.Y);
var cursorPoint = await QueuedTask.Run(() =>
{
return MapView.Active.ScreenToMap(winPoint);
});
// Get current sketch
Polyline existingWbl = await MapView.Active.GetCurrentSketchAsync() as Polyline;
// Add point to current sketch
var newWbl = AddPointToPolyline(existingWbl, cursorPoint, spatialRef);
await MapView.Active.SetCurrentSketchAsync(newWbl);
}
catch (Exception ex)
{
ProPopupMessage.Error(MiscUtils.GetMethodName(), ex.Message);
}
}
private Polyline AddPointToPolyline(Polyline polyline, MapPoint newPoint, SpatialReference spatialRef)
{
PolylineBuilderEx polylineBuilder = new PolylineBuilderEx(spatialRef);
polylineBuilder.HasZ = true;
// Step through all points
List<MapPoint> newPointList = new List<MapPoint>();
if (polyline != null)
{
foreach (var existingPoint in polyline.Points)
{
newPointList.Add(existingPoint);
}
}
newPointList.Add(newPoint);
// Add polyline part
polylineBuilder.AddPart(newPointList);
return polylineBuilder.ToGeometry();
}
This code works if there already exists a sketch. If I want to add the first point of the polyline, however, it doesn't show on the stereo map. In ArcObjects, this was possible!
Why do I want to create a polyline using a button instead of a tool? I want to use a button on a 3D mouse (https://pro.arcgis.com/en/pro-app/latest/help/analysis/image-analyst/set-up-the-stereo-mapping-stealth-3d-mouse.htm)