//protected override void OnKeyUpCore(MapViewKeyEventArgs k) //{ // _msg.VerboseDebug("OnKeyUpCore"); // if (k.Key == _keyToggleNonDefaultSide) // { // _nonDefaultSideMode = ! _nonDefaultSideMode; // k.Handled = true; // } // else if (k.Key == Key.Space) // { // k.Handled = true; // } // base.OnKeyUpCore(k); //} //protected override async Task HandleKeyUpAsync(MapViewKeyEventArgs k) //{ // // At 2.5 this is never called (despite setting k.Handled = true above). // TODO: Test in 2.6/2.7 // try // { // if (k.Key == _keyToggleNonDefaultSide || // k.Key == Key.Space) // { // _updateFeedbackTask = UpdateFeedbackAsync(_nonDefaultSideMode); // await _updateFeedbackTask; // } // } // catch (Exception e) // { // _msg.Warn("Error generating preview", e); // } // finally // { // _updateFeedbackTask = null; // } //} protected override async Task <bool> OnEditSketchCompleteCoreAsync( Geometry sketchGeometry, EditingTemplate editTemplate, MapView activeView, CancelableProgressor cancelableProgressor = null) { _feedback.Clear(); // TODO: cancel all running background tasks... var polyline = (Polyline)sketchGeometry; List <Feature> selection; // Or allow selecting next feature already? SetCursor(Cursors.Wait); bool success = await QueuedTaskUtils.Run(async() => { selection = GetApplicableSelectedFeatures(activeView).ToList(); var potentiallyAffectedFeatures = GetAdjacentFeatures(selection, cancelableProgressor); // This timout should be enough even in extreme circumstances: int timeout = selection.Count * 10000; _cancellationTokenSource = new CancellationTokenSource(timeout); ReshapeResult result = MicroserviceClient.Reshape( selection, polyline, potentiallyAffectedFeatures, true, true, _nonDefaultSideMode, _cancellationTokenSource.Token); if (result == null) { return(false); } Dictionary <Feature, Geometry> resultFeatures = result.ResultFeatures.ToDictionary(r => r.Feature, r => r.UpdatedGeometry); LogReshapeResults(result, selection.Count); success = await SaveAsync(resultFeatures); // At some point, hopefully, read-only operations on the CIM model can run in parallel await ToolUtils.FlashResultPolygonsAsync(activeView, resultFeatures); return(success); }); _nonDefaultSideMode = false; //if (!_advancedReshapeOptions.RemainInSketchMode) { StartSelectionPhase(); } return(success); // taskSave.Result; }
public async Task StartSketchToolAsync() { EditingTemplate editingFeatureTemplate = EditingTemplate.Current; Layer layer = editingFeatureTemplate?.Layer; VectorLayer vectorLayer = GetLayer(layer); if (vectorLayer?.IsVisibleInGlobespotter ?? false) { await StartMeasurementSketchAsync(vectorLayer); } }
public async Task StartSketchToolAsync() { EditingTemplate editingFeatureTemplate = EditingTemplate.Current; Layer layer = editingFeatureTemplate?.Layer; VectorLayer vectorLayer = GetLayer(layer); if (vectorLayer != null) { await StartMeasurementSketchAsync(vectorLayer); } }
protected override async Task <bool> OnSketchCompleteCoreAsync( Geometry sketchGeometry, CancelableProgressor progressor) { if (IsInSketchMode) { // take snapshots EditingTemplate currentTemplate = CurrentTemplate; MapView activeView = ActiveMapView; return(await OnEditSketchCompleteCoreAsync( sketchGeometry, currentTemplate, activeView, progressor)); } return(false); }
protected override async void OnClick() { // get an anno layer AnnotationLayer annoLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <AnnotationLayer>().FirstOrDefault(); if (annoLayer == null) { return; } bool result = await QueuedTask.Run(async() => { // get an existing template EditingTemplate template = annoLayer.GetTemplates().FirstOrDefault(); if (template == null) { return(false); } // make sure it is active before you get the inspector await template.ActivateDefaultToolAsync(); var insp = template.Inspector; if (insp == null) { return(false); } // set up some properties AnnotationProperties annoProperties = insp.GetAnnotationProperties(); annoProperties.TextString = "special text"; annoProperties.Color = ColorFactory.Instance.GreenRGB; annoProperties.SmallCaps = true; insp.SetAnnotationProperties(annoProperties); // set up default tool - use daml-id rather than guid string defaultTool = "esri_editing_SketchStraightAnnoTool"; // dont alter the filter or tags // create a new CIM template - new extension method var newTemplate = annoLayer.CreateTemplate("template from existing template", "sample template description", insp, defaultTool); return(newTemplate != null); }); }
//The data referenced in this snippet can be downloaded from the arcgis-pro-sdk-community-samples repo //https://github.com/Esri/arcgis-pro-sdk-community-samples protected async Task <string> CreateRings(EditingTemplate currentTemplate) { var valueArray = await QueuedTask.Run(() => { return(Geoprocessing.MakeValueArray(currentTemplate.MapMember.Name, @"C:\Data\FeatureTest\FeatureTest.gdb\Points_MultipleRingBuffer", new List <string> { "1000", "2000" }, "Meters", "Distance", "ALL", "FULL")); }); IGPResult gpResult = await Geoprocessing.ExecuteToolAsync("Analysis.MultipleRingBuffer", valueArray); return(string.IsNullOrEmpty(gpResult.ReturnValue) ? $@"Error in gp tool: {gpResult.ErrorMessages}" : $@"Ok: {gpResult.ReturnValue}"); }
protected override async Task <bool> OnEditSketchCompleteCoreAsync( Geometry sketchGeometry, EditingTemplate editTemplate, MapView activeView, CancelableProgressor cancelableProgressor = null) { var polygon = (Polygon)sketchGeometry; var resultFeatures = await QueuedTaskUtils.Run( () => CalculateResultFeatures(activeView, polygon), cancelableProgressor); var taskSave = QueuedTaskUtils.Run(() => SaveAsync(resultFeatures)); var taskFlash = QueuedTaskUtils.Run(() => FlashAsync(activeView, resultFeatures)); await Task.WhenAll(taskFlash, taskSave); return(taskSave.Result); }
//The data referenced in this snippet can be downloaded from the arcgis-pro-sdk-community-samples repo //https://github.com/Esri/arcgis-pro-sdk-community-samples protected async Task <string> NonBlockingExecuteGP(EditingTemplate currentTemplate) { var valueArray = await QueuedTask.Run(() => { string in_data = @"C:\tools\data.gdb\cities"; string cities_buff = @"E:\data\data.gdb\cities_2km"; return(Geoprocessing.MakeValueArray(in_data, cities_buff, "2000 Meters")); }); // to let the GP tool run asynchronously without blocking the main thread // use the GPThread option of GPExecuteToolFlasgs // GPExecuteToolFlags flags = GPExecuteToolFlags.GPThread; // instruct the tool run non-blocking GPThread IGPResult gpResult = await Geoprocessing.ExecuteToolAsync("Analysis.Buffer", valueArray, null, null, null, flags); return(string.IsNullOrEmpty(gpResult.ReturnValue) ? $@"Error in gp tool: {gpResult.ErrorMessages}" : $@"Ok: {gpResult.ReturnValue}"); }
protected async Task <bool> ExecuteCut(EditingTemplate template, Geometry geometry, Dictionary <string, object> attributes) { if (template == null) { return(false); } if (geometry == null) { return(false); } // create an edit operation EditOperation op = EditingModule.CreateEditOperation(); op.Name = "Cut Elements"; op.ProgressMessage = "Working..."; op.CancelMessage = "Operation canceled."; op.ErrorMessage = "Error cutting polygons"; op.SelectModifiedFeatures = false; op.SelectNewFeatures = false; // get the feature class associated with the layer Table fc = await template.Layer.GetTableAsync(); // initialize a list of ObjectIDs that need to be cut var cutOIDs = new List <long>(); // on a separate thread await QueuingTaskFactory.StartNew(async() => { // TODO // find the features crossed by the sketch geometry RowCursor rc = await fc.SearchAsync(geometry, SpatialRelationship.Crosses); // add the feature IDs into our prepared list while (rc.MoveNext()) { var feature = rc.Current as Feature; if (feature == null) { break; } if (feature.Shape != null) { // we are interested in the intersection points // in case there is only one intersection then the sketch geometry doesn't enter and leave the // base geometry and the cut operation won't work. Geometry intersectionGeometry = GeometryEngine.Intersection(feature.Shape, geometry, GeometryDimension.esriGeometry0Dimension); if (intersectionGeometry is MultiPoint) { //var intersectionPoints = intersectionGeometry as MultiPoint; //// we are only interested in feature IDs where the count of intersection points is larger than 1 //// i.e., at least one entry and one exit //if (intersectionPoints.Coordinates.Count > 1) //{ // // add the current feature to the overall list of features to cut // cutOIDs.Add(rc.Current.ObjectID); //} } } } }); // add the elements to cut into the edit operation op.Cut(template.Layer, cutOIDs, geometry); //execute the operation bool operationResult = await op.ExecuteAsync(); return(operationResult); }
protected abstract Task <bool> OnEditSketchCompleteCoreAsync( Geometry sketchGeometry, EditingTemplate editTemplate, MapView activeView, CancelableProgressor cancelableProgressor = null);
protected async void OnDrawCompleted(MapViewEventArgs args) { MapView mapView = args.MapView; Geometry geometry = await mapView.GetCurrentSketchAsync(); EditingTemplate editingFeatureTemplate = EditingTemplate.Current; Layer layer = editingFeatureTemplate?.Layer; VectorLayer thisVectorLayer = GetLayer(layer); if (geometry != null) { switch (EditTool) { case EditTools.ModifyFeatureImpl: if (_measurementList.Count == 1) { KeyValuePair <int, Measurement> firstElement = _measurementList.ElementAt(0); Measurement measurement = firstElement.Value; measurement.SetSketch(); VectorLayer vectorLayer = measurement.VectorLayer; if (geometry.PointCount == 0) { await StartMeasurementSketchAsync(vectorLayer); } else if (geometry.HasZ) { await AddHeightToMeasurementAsync(geometry, mapView); } await _measurementList.SketchModifiedAsync(geometry, thisVectorLayer); } break; case EditTools.SketchLineTool: case EditTools.SketchPolygonTool: case EditTools.Verticles: if (geometry.HasZ) { await AddHeightToMeasurementAsync(geometry, mapView); } await _measurementList.SketchModifiedAsync(geometry, thisVectorLayer); break; case EditTools.SketchPointTool: if (geometry.HasZ) { await AddHeightToMeasurementAsync(geometry, mapView); } break; } } else { SketchFinished(); } }
protected sealed override FrameworkElement GenerateEditingElement(PropertyItemBase propertyItem) { return(EditingTemplate is not null ? EditingTemplate.LoadContent() as FrameworkElement : null); }