/// <summary> /// Creates a simple line callout text symbol. The [CIMSimpleLineCallout](http://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic2760.html) created is a dash-dot-dash line symbol with an offset of 10 from the geometry being labeled. /// ![lineCallOut](http://Esri.github.io/arcgis-pro-sdk/images/Labeling/line-callout.png "Line Callout text symbol") /// </summary> /// <returns></returns> private static Task <CIMTextSymbol> CreateSimpleLineCalloutAsync() { return(QueuedTask.Run <CIMTextSymbol>(() => { //create a text symbol var textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 10, "Verdana", "Regular"); //Create a line call out var lineCalloutSymbol = new CIMSimpleLineCallout(); //Get a line symbol var lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 1, SimpleLineStyle.DashDotDot); //assign the line symbol to the callout lineCalloutSymbol.LineSymbol = lineSymbol; //Offset for the text textSymbol.OffsetX = 10; textSymbol.OffsetY = 10; //Assign the callout to the text symbol textSymbol.Callout = lineCalloutSymbol; return textSymbol; })); }
protected override Task <bool> OnSketchCompleteAsync(Geometry geometry) { // execute on the MCT return(QueuedTask.Run(() => { // find features under the sketch var features = MapView.Active.GetFeatures(geometry); if (features.Count == 0) { return false; } EditOperation op = null; foreach (var layerKey in features.Keys) { // is it an anno layer? if (!(layerKey is AnnotationLayer)) { continue; } // are there features? var featOids = features[layerKey]; if (featOids.Count == 0) { continue; } // for each feature foreach (var oid in featOids) { // create the edit operation if (op == null) { op = new EditOperation(); op.Name = "Alter symbol to simple line callout"; op.SelectModifiedFeatures = true; op.SelectNewFeatures = false; } // use the callback method op.Callback(context => { // find the feature QueryFilter qf = new QueryFilter(); qf.WhereClause = "OBJECTID = " + oid.ToString(); // use the table using (var table = layerKey.GetTable()) { // make sure you use a non-recycling cursor using (var rowCursor = table.Search(qf, false)) { rowCursor.MoveNext(); if (rowCursor.Current != null) { ArcGIS.Core.Data.Mapping.AnnotationFeature annoFeature = rowCursor.Current as ArcGIS.Core.Data.Mapping.AnnotationFeature; if (annoFeature != null) { // get the CIMTextGraphic var textGraphic = annoFeature.GetGraphic() as CIMTextGraphic; if (textGraphic != null) { // // add a leader point to the text graphic // // get the feature shape var feature = annoFeature as Feature; var textExtent = feature.GetShape(); // find the lower left of the text extent var extent = textExtent.Extent; var lowerLeft = MapPointBuilder.CreateMapPoint(extent.XMin, extent.YMin, textExtent.SpatialReference); // move it a little to the left and down var newPoint = GeometryEngine.Instance.Move(lowerLeft, -40, -40); // create a leader point CIMLeaderPoint leaderPt = new CIMLeaderPoint(); leaderPt.Point = newPoint as MapPoint; // add to a list List <CIMLeader> leaderArray = new List <CIMLeader>(); leaderArray.Add(leaderPt); // assign to the textGraphic textGraphic.Leaders = leaderArray.ToArray(); // // add the simpleLineCallout // CIMSimpleLineCallout lineCallout = new CIMSimpleLineCallout(); lineCallout.LineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1, SimpleLineStyle.Dash); // asign it to the textSymbol var symbol = textGraphic.Symbol.Symbol; var textSymbol = symbol as CIMTextSymbol; textSymbol.Callout = lineCallout; try { // update the graphic annoFeature.SetGraphic(textGraphic); // store annoFeature.Store(); // refresh the cache context.Invalidate(annoFeature); } // SetGraphic can throw a GeodatabaseException if the AnnotationFeatureClassDefinition AreSymbolOverridesAllowed = false // or if IsSymbolIDRequired = true and the symbol edit you're making causes the symbol to be disconnected from the symbol collection. // see http://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic17424.html // and http://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic17432.html catch (GeodatabaseException ex) { } } } } } } }, layerKey.GetTable()); } } if ((op != null) && !op.IsEmpty) { bool result = op.Execute(); return result; } return false; })); }
/// <summary> /// Called when the sketch finishes. This is where we will create the edit operation and then execute it. /// </summary> /// <param name="geometry">The geometry created by the sketch.</param> /// <returns>A Task returning a Boolean indicating if the sketch complete event was successfully handled.</returns> protected override Task <bool> OnSketchCompleteAsync(Geometry geometry) { // execute on the MCT return(QueuedTask.Run(() => { // find features under the sketch var features = MapView.Active.GetFeatures(geometry); if (features.Count == 0) { return false; } EditOperation op = null; foreach (var annoLayer in features.Keys.OfType <AnnotationLayer>()) { // are there features? var featOids = features[annoLayer]; if (featOids.Count == 0) { continue; } var insp = new Inspector(); // for each feature foreach (var oid in featOids) { // load an inspector insp.Load(annoLayer, oid); // get the annotation properties var annoProperties = insp.GetAnnotationProperties(); // get the text graphic var cimTextGraphic = annoProperties.TextGraphic; if (cimTextGraphic != null) { // // add a leader point to the text graphic // // get the feature shape var textExtent = insp.Shape; // find the lower left of the text extent var extent = textExtent.Extent; var lowerLeft = MapPointBuilder.CreateMapPoint(extent.XMin, extent.YMin, textExtent.SpatialReference); // move it a little to the left and down var newPoint = GeometryEngine.Instance.Move(lowerLeft, -40, -40); // create a leader point CIMLeaderPoint leaderPt = new CIMLeaderPoint(); leaderPt.Point = newPoint as MapPoint; // add to a list List <CIMLeader> leaderArray = new List <CIMLeader>(); leaderArray.Add(leaderPt); // assign to the textGraphic cimTextGraphic.Leaders = leaderArray.ToArray(); // // add the simpleLineCallout // CIMSimpleLineCallout lineCallout = new CIMSimpleLineCallout(); lineCallout.LineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1, SimpleLineStyle.Dash); // asign it to the textSymbol var symbol = cimTextGraphic.Symbol.Symbol; var textSymbol = symbol as CIMTextSymbol; textSymbol.Callout = lineCallout; // assign the text graphic back to the annotation properties annoProperties.LoadFromTextGraphic(cimTextGraphic); // assign the annotation properties back to the inspector insp.SetAnnotationProperties(annoProperties); } // create the edit operation if (op == null) { op = new EditOperation(); op.Name = "Alter symbol to simple line callout"; op.SelectModifiedFeatures = true; op.SelectNewFeatures = false; } // modify the feature op.Modify(insp); } } if ((op != null) && !op.IsEmpty) { bool result = op.Execute(); return result; } return false; })); }