I have a tool that runs and creates a feature where the user clicks. It creates a polygon of a certain shape that the user must move and rotate.
How do i initiate either the Move or Rotate modify feature function from code. i can't seem to get the setcurrenttoolasync to do this?
I am trying to do this at the end of my OnSketchCompleteAsync at the end but it seems to make my Map unusable and doesn't change the tool. Do I need to deactivate my tool and trigger the other tool or something?
ArcGIS.Desktop.Framework.FrameworkApplication.SetCurrentToolAsync("esri_editing_EditVerticesRotate");
I first create a Polyline from a point where a user clicks, then i want the user to rotate that line as they desire.
protected async override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
await QueuedTask.Run(async () =>
{
//Get the Geometry of the map and project to Local for better distance
Geometry thisGeometry = geometry;
thisGeometry = GeometryEngine.Instance.Project(geometry, MapView.Active.Map.SpatialReference);
double extendLength = 125;
Coordinate2D ClickPoint = new Coordinate2D(geometry as MapPoint);
//Get the Row Direction Line to Display
MapPointBuilder TopPoint = new MapPointBuilder();
MapPointBuilder MidPoint = new MapPointBuilder();
MapPointBuilder BottomPoint = new MapPointBuilder();
MapPointBuilder RowDirectionPoint = new MapPointBuilder();
//Get Top Point
TopPoint.X = ClickPoint.X;
TopPoint.Y = ClickPoint.Y;
//Get Bottom Point
BottomPoint.X = ClickPoint.X;
BottomPoint.Y = ClickPoint.Y - (extendLength * 2);
//Get Mid Point
MidPoint.X = ClickPoint.X;
MidPoint.Y = ClickPoint.Y - extendLength;
//Get Row Direction Point
RowDirectionPoint.X = MidPoint.X + (extendLength / 2);
RowDirectionPoint.Y = MidPoint.Y;
//Creating the Line though the vertex for the direction
IList<MapPoint> segmentDirection = new List<MapPoint>
{
MapPointBuilder.CreateMapPoint(TopPoint.X, TopPoint.Y, thisGeometry.SpatialReference),
MapPointBuilder.CreateMapPoint(BottomPoint.X, BottomPoint.Y, thisGeometry.SpatialReference),
MapPointBuilder.CreateMapPoint(MidPoint.X, MidPoint.Y, thisGeometry.SpatialReference),
MapPointBuilder.CreateMapPoint(RowDirectionPoint.X, RowDirectionPoint.Y, thisGeometry.SpatialReference)
};
Polyline directionThroughVertex = PolylineBuilder.CreatePolyline(segmentDirection, thisGeometry.SpatialReference);
//Create and Row Direction Feature from the new line
string intersectingFeatureName = "Row Direction Line";
FeatureLayer RowDirectionFeatureLayer =
FeatureServiceManagement.GetFeatureLayer(intersectingFeatureName);
EditOperation RowDirectionCreateOperation = new EditOperation()
{
Name = string.Format("Create point in '{0}'", intersectingFeatureName),
ProgressMessage = "Working...",
CancelMessage = "Operation canceled.",
ErrorMessage = "Error creating point",
SelectModifiedFeatures = true,
SelectNewFeatures = true,
ShowProgressor = true
};
//Create the Feature and get its OID, then we can load it with defaults for the Tool
long newFeatureOID = -1;
RowDirectionCreateOperation.Create(RowDirectionFeatureLayer,
directionThroughVertex, oid => newFeatureOID = oid);
bool result = await RowDirectionCreateOperation.ExecuteAsync();
});
//I WANT TO GET THE ROTATE TOOL TO WORK HERE (It deadlocks now or something)
ArcGIS.Desktop.Framework.FrameworkApplication.SetCurrentToolAsync("esri_editing_EditVerticesRotate");
return true;
}
"esri_editing_EditVerticesRotate" is a button (i.e. "command") not a tool. Try this instead:
//elsewhere
private ICommand _rotate = null;
//Do work, process sketch, etc.
//ArcGIS.Desktop.Framework.FrameworkApplication.SetCurrentToolAsync(
// "esri_editing_EditVerticesRotate");
//activate rotate
if (_rotate == null)
_rotate =
FrameworkApplication.GetPlugInWrapper("esri_editing_EditVerticesRotate") as ICommand;
if (_rotate.CanExecute(null))
{
_rotate.Execute(null);
}
I am not sure why you are deadlocking. FrameworkApplication.SetCurrentToolAsync would be a no-op in your case because the tool "esri_editing_EditVerticesRotate" does not exist.