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;
            }));
        }
示例#2
0
        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 balloon 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();

                            // make sure you use a non-recycling cursor
                            using (var rowCursor = layerKey.GetTable().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 balloon callout
                                            //

                                            // create the callout
                                            CIMBalloonCallout balloon = new CIMBalloonCallout();
                                            // yellow background
                                            balloon.BackgroundSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.CreateRGBColor(255, 255, 0));
                                            // set the balloon style
                                            balloon.BalloonStyle = BalloonCalloutStyle.RoundedRectangle;
                                            // add a text margin
                                            CIMTextMargin textMargin = new CIMTextMargin()
                                            {
                                                Left = 4, Right = 4, Bottom = 4, Top = 4
                                            };
                                            balloon.Margin = textMargin;

                                            // asign it to the textSymbol
                                            var symbol = textGraphic.Symbol.Symbol;
                                            var textSymbol = symbol as CIMTextSymbol;

                                            textSymbol.Callout = balloon;

                                            // update the textGraphic symbol
                                            textGraphic.Symbol = symbol.MakeSymbolReference();

                                            // update the graphic
                                            annoFeature.SetGraphic(textGraphic);

                                            // store
                                            annoFeature.Store();

                                            // refresh the cache
                                            context.Invalidate(annoFeature);
                                        }
                                    }
                                }
                            }
                        }, layerKey.GetTable());
                    }
                }

                if ((op != null) && !op.IsEmpty)
                {
                    bool result = op.Execute();
                    return result;
                }
                return
                false;
            }));
        }
        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;
                // for each layer in the features retrieved
                foreach (var layer in features.Keys)
                {
                    // is it an anno layer?
                    if (!(layer is AnnotationLayer))
                    {
                        continue;
                    }

                    // are there features?
                    var featOids = features[layer];
                    if (featOids.Count == 0)
                    {
                        continue;
                    }

                    // for each feature
                    foreach (var oid in featOids)
                    {
                        // Remember - the shape of an annotation feature is a polygon - the bounding box of the annotation text.
                        // We need to update the cimTextGraphic geometry.  Use the GetGraphic method from the AnnotationFeature to obtain the geometry.

                        Geometry textGraphicGeometry = null;

                        // query for each feature
                        QueryFilter qf = new QueryFilter();
                        qf.WhereClause = "OBJECTID = " + oid.ToString();
                        using (var rowCursor = layer.Search(qf))
                        {
                            rowCursor.MoveNext();
                            if (rowCursor.Current != null)
                            {
                                ArcGIS.Core.Data.Mapping.AnnotationFeature annoFeature = rowCursor.Current as ArcGIS.Core.Data.Mapping.AnnotationFeature;
                                if (annoFeature != null)
                                {
                                    var graphic = annoFeature.GetGraphic();
                                    // cast to a CIMTextGraphic
                                    var textGraphic = graphic as CIMTextGraphic;
                                    // get the shape
                                    textGraphicGeometry = textGraphic.Shape;
                                }
                            }
                        }

                        // if cimTextGraphic geometry is not a polyline, ignore
                        Polyline baseLine = textGraphicGeometry as Polyline;
                        if (baseLine == null)
                        {
                            continue;
                        }

                        // rotate the baseline 90 degrees
                        var origin = GeometryEngine.Instance.Centroid(baseLine);
                        Geometry rotatedBaseline = GeometryEngine.Instance.Rotate(baseLine, origin, System.Math.PI / 2);

                        // create the edit operation
                        if (op == null)
                        {
                            op = new EditOperation();
                            op.Name = "Update annotation baseline";
                            op.SelectModifiedFeatures = true;
                            op.SelectNewFeatures = false;
                        }

                        op.Modify(layer, oid, rotatedBaseline);

                        // OR
                        // use the Dictionary methodology

                        //Dictionary<string, object> newAtts = new Dictionary<string, object>();
                        //newAtts.Add("SHAPE", rotatedBaseline);
                        //op.Modify(layer, oid, newAtts);

                        // OR
                        // use the pattern in AnnoModifySymbol (EditOperation.Callback) to update the textGraphic geometry
                    }
                }

                // execute the operation
                if ((op != null) && !op.IsEmpty)
                {
                    return op.Execute();
                }
                return
                false;
            }));
        }
示例#4
0
        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)
                {
                    // is it an anno layer?
                    if (!(annoLayer is AnnotationLayer))
                    {
                        continue;
                    }

                    // are there features?
                    var featOids = features[annoLayer];
                    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 = "Update annotation symbol";
                            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 = annoLayer.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)
                                            {
                                                // change the text
                                                textGraphic.Text = "Hello World";

                                                // get the symbol reference
                                                var cimSymbolReference = textGraphic.Symbol;
                                                // get the symbol
                                                var cimSymbol = cimSymbolReference.Symbol;

                                                // change the color to red
                                                cimSymbol.SetColor(ColorFactory.Instance.RedRGB);

                                                //// change the horizontal alignment
                                                //var cimTextSymbol = cimSymbol as CIMTextSymbol;
                                                //cimTextSymbol.HorizontalAlignment = HorizontalAlignment.Center;

                                                // update the symbol
                                                textGraphic.Symbol = cimSymbol.MakeSymbolReference();

                                                // update the graphic
                                                annoFeature.SetGraphic(textGraphic);

                                                // store
                                                annoFeature.Store();

                                                // refresh the cache
                                                context.Invalidate(annoFeature);
                                            }
                                        }
                                    }
                                }
                            }
                        }, annoLayer.GetTable());
                    }
                }

                // execute the operation
                if ((op != null) && !op.IsEmpty)
                {
                    return op.Execute();
                }
                return
                false;
            }));
        }