private void InsertAnnotation(AnnotationFeature annofeat)
        {
            var selectedFeatures = MapView.Active.Map.GetSelection().Where(kvp => kvp.Key is AnnotationLayer).ToDictionary(kvp => (AnnotationLayer)kvp.Key, kvp => kvp.Value);
            var layer            = selectedFeatures.Keys.FirstOrDefault();

            // コピーするアノテーション用に行を作成
            AnnotationFeatureClass annotationFeatureClass = layer.GetFeatureClass() as AnnotationFeatureClass;
            RowBuffer rowBuffer = annotationFeatureClass.CreateRowBuffer();
            Feature   feature   = annotationFeatureClass.CreateRow(rowBuffer) as Feature;

            // コピーするアノテーションを作成
            AnnotationFeature copyAnnoFeat = feature as AnnotationFeature;

            copyAnnoFeat.SetStatus(AnnotationStatus.Placed);
            copyAnnoFeat.SetAnnotationClassID(0);

            // コピー元のアノテーションの重心にポイントを作成
            Envelope shape           = annofeat.GetShape().Extent;
            var      x               = shape.Center.X;
            var      y               = shape.Center.Y;
            var      mapPointBuilder = new MapPointBuilder(layer.GetSpatialReference());

            mapPointBuilder.X = x;
            mapPointBuilder.Y = y;
            MapPoint mapPoint = mapPointBuilder.ToGeometry();

            // コピー元のアノテーションのテキストを作成
            var annoGraphich = annofeat.GetGraphic() as CIMTextGraphic;

            // 作成したポイントとアノテーションをコピー先のアノテーションにコピー
            CIMTextGraphic cimTextGraphic = new CIMTextGraphic();

            cimTextGraphic.Text  = annoGraphich.Text;
            cimTextGraphic.Shape = mapPoint;

            // シンボル設定
            var symbolRef = new CIMSymbolReference();

            symbolRef.SymbolName  = annoGraphich.Symbol.SymbolName;
            symbolRef.Symbol      = annoGraphich.Symbol.Symbol;
            cimTextGraphic.Symbol = symbolRef;

            // コピー
            copyAnnoFeat.SetGraphic(cimTextGraphic);
            copyAnnoFeat.Store();
        }
Ejemplo n.º 2
0
        private void AddElement(IPolyline polyline)
        {
            try
            {
                ArcGIS.Common.Editor.Editor.StartEditOperation();

                string strLineInfo = CommonHelper.GetIntersectInformationFlagLineOnlyOne(polyline, _cheQiConfig,
                                                                                         _feature);
                if (string.IsNullOrWhiteSpace(strLineInfo))
                {
                    MessageBox.Show(@"扯旗字段为空,请重新设置扯旗字段", @"扯旗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                IPoint referPoint = new PointClass();
                referPoint.X = _polyline.ToPoint.X;
                referPoint.Y = _polyline.ToPoint.Y;

                stdole.IFontDisp fontDisp = new StdFontClass() as IFontDisp;
                fontDisp.Name          = _cheQiConfig.FontName;
                fontDisp.Size          = _cheQiConfig.FontSize;
                fontDisp.Italic        = _cheQiConfig.Italic;
                fontDisp.Underline     = _cheQiConfig.Underline;
                fontDisp.Bold          = _cheQiConfig.Bold;
                fontDisp.Strikethrough = _cheQiConfig.Strikethrough;

                ITextSymbol textSymbol = new TextSymbolClass();
                textSymbol.Size  = (double)_cheQiConfig.FontSize;
                textSymbol.Font  = fontDisp;
                textSymbol.Color = _cheQiConfig.FontColor;
                textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;

                ITextElement textElement = new TextElementClass();
                textElement.Text      = strLineInfo;
                textElement.Symbol    = textSymbol;
                textElement.ScaleText = true;

                IPoint textPoint = new PointClass();
                textPoint.X = referPoint.X;
                textPoint.Y = referPoint.Y + 1;

                IElement element = textElement as IElement;
                element.Geometry = textPoint;

                IFeature annoFeature = _cheQiConfig.FlagAnnoLayer.FeatureClass.CreateFeature();
                IAnnotationClassExtension annotationClassExtension = _cheQiConfig.FlagAnnoLayer.FeatureClass.Extension as IAnnotationClassExtension;
                IAnnotationFeature        annotationFeature        = new AnnotationFeatureClass();
                annotationFeature                 = annoFeature as IAnnotationFeature;
                annotationFeature.Annotation      = element;
                annotationFeature.LinkedFeatureID = _feature.OID;
                annoFeature.Store();
                _context.ActiveView.ScreenDisplay.StartDrawing(_context.ActiveView.ScreenDisplay.hDC, 0);
                annotationClassExtension.Draw(annotationFeature, _context.ActiveView.ScreenDisplay, null);
                _context.ActiveView.ScreenDisplay.FinishDrawing();

                double           maxLength            = annoFeature.Shape.Envelope.Width;
                IFeatureClass    flagLineFeatureClass = _cheQiConfig.FlagLineLayer.FeatureClass;
                IFeature         feature         = flagLineFeatureClass.CreateFeature();
                IPointCollection pointCollection = _polyline as IPointCollection;
                IPoint           point           = new PointClass();
                point.Y = referPoint.Y;
                point.X = referPoint.X + maxLength;
                pointCollection.AddPoint(point);
                feature.Shape = pointCollection as IPolyline;
                feature.Store();

                _context.ActiveView.Refresh();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
            finally
            {
                ArcGIS.Common.Editor.Editor.StartEditOperation();
            }
        }