Example #1
0
        private void btnSelectDatumPoint_Click(object sender, EventArgs e)
        {
            if (cmbDirection.SelectedItem == null)
            {
                return;
            }
            enumAnnotationDirection direction = enumAnnotationDirection.RightUp;

            switch (cmbDirection.SelectedItem.ToString())
            {
            case "左上":
                direction = enumAnnotationDirection.LeftUp;
                break;

            case "右上":
                direction = enumAnnotationDirection.RightUp;
                break;

            case "右下":
                direction = enumAnnotationDirection.RightDown;
                break;

            case "左下":
                direction = enumAnnotationDirection.LeftDown;
                break;
            }
            CmdGetTargetPoint tool = new CmdGetTargetPoint(_context, _plugin);

            _context.CurrentTool        = tool;
            tool.MouseDownEventHandler += delegate(IPoint point)
            {
                List <IPolygon> polygons = CommonHelper.GetMovedPoints(_annotationFeatures, point, direction);
                for (int i = 0; i < _annotationFeatures.Count; i++)
                {
                    IFeature pFeature = _annotationFeatures[i];
                    pFeature.Shape = polygons[i];
                    pFeature.Store();
                    IAnnotationFeature pAnnotationFeature = pFeature as IAnnotationFeature;
                    if (pAnnotationFeature == null)
                    {
                        continue;
                    }
                    IElement pElement = pAnnotationFeature.Annotation as IElement;
                    pElement.Geometry = new PointClass
                    {
                        X = (polygons[i].Envelope.XMin + polygons[i].Envelope.XMax) / 2,
                        Y = (polygons[i].Envelope.YMin + polygons[i].Envelope.YMax) / 2
                    };
                    pAnnotationFeature.Annotation = pElement;
                    pFeature.Store();
                }
                _context.FocusMap.ClearSelection();
                _context.ActiveView.Refresh();
            };
        }
Example #2
0
        public static List <IPolygon> GetMovedPoints(List <IFeature> features, IPoint point,
                                                     enumAnnotationDirection direction)
        {
            List <IPolygon> list = new List <IPolygon>();

            if (features.Count <= 0)
            {
                return(list);
            }
            IPoint originPoint = new PointClass
            {
                X = point.X,
                Y = point.Y - features[0].Extent.Height / 2
            };

            for (int i = 0; i < features.Count; i++)
            {
                IFeature         pFeature        = features[i];
                IPolygon         tempPolygon     = new PolygonClass();
                IPointCollection pointCollection = tempPolygon as IPointCollection;
                IPoint           point1          = new PointClass();
                IPoint           point2          = new PointClass();
                IPoint           point3          = new PointClass();
                IPoint           point4          = new PointClass();
                switch (direction)
                {
                case enumAnnotationDirection.LeftUp:
                {
                    point1 = new PointClass
                    {
                        X = originPoint.X - pFeature.Extent.Width,
                        Y = originPoint.Y + pFeature.Extent.Height * (features.Count - 1 - i)
                    };
                    point2 = new PointClass
                    {
                        X = originPoint.X - pFeature.Extent.Width,
                        Y = originPoint.Y + pFeature.Extent.Height * (features.Count - i)
                    };
                    point3 = new PointClass
                    {
                        X = originPoint.X,
                        Y = originPoint.Y + pFeature.Extent.Height * (features.Count - i)
                    };
                    point4 = new PointClass
                    {
                        X = originPoint.X,
                        Y = originPoint.Y + pFeature.Extent.Height * (features.Count - 1 - i)
                    };
                }
                break;

                case enumAnnotationDirection.RightUp:
                {
                    point1 = new PointClass
                    {
                        X = originPoint.X,
                        Y = originPoint.Y + pFeature.Extent.Height * (features.Count - 1 - i)
                    };
                    point2 = new PointClass
                    {
                        X = originPoint.X,
                        Y = originPoint.Y + pFeature.Extent.Height * (features.Count - i)
                    };
                    point3 = new PointClass
                    {
                        X = originPoint.X + pFeature.Extent.Width,
                        Y = originPoint.Y + pFeature.Extent.Height * (features.Count - i)
                    };
                    point4 = new PointClass
                    {
                        X = originPoint.X + pFeature.Extent.Width,
                        Y = originPoint.Y + pFeature.Extent.Height * (features.Count - 1 - i)
                    };
                }
                break;

                case enumAnnotationDirection.RightDown:
                {
                    point1 = new PointClass
                    {
                        X = originPoint.X,
                        Y = originPoint.Y - pFeature.Extent.Height * (i + 1)
                    };
                    point2 = new PointClass
                    {
                        X = originPoint.X,
                        Y = originPoint.Y - pFeature.Extent.Height * (i)
                    };
                    point3 = new PointClass
                    {
                        X = originPoint.X + pFeature.Extent.Width,
                        Y = originPoint.Y - pFeature.Extent.Height * (i)
                    };
                    point4 = new PointClass
                    {
                        X = originPoint.X + pFeature.Extent.Width,
                        Y = originPoint.Y - pFeature.Extent.Height * (i + 1)
                    };
                }
                break;

                case enumAnnotationDirection.LeftDown:
                {
                    point1 = new PointClass
                    {
                        X = originPoint.X - pFeature.Extent.Width,
                        Y = originPoint.Y - pFeature.Extent.Height * (i + 1)
                    };
                    point2 = new PointClass
                    {
                        X = originPoint.X - pFeature.Extent.Width,
                        Y = originPoint.Y - pFeature.Extent.Height * (i)
                    };
                    point3 = new PointClass
                    {
                        X = originPoint.X,
                        Y = originPoint.Y - pFeature.Extent.Height * (i)
                    };
                    point4 = new PointClass
                    {
                        X = originPoint.X,
                        Y = originPoint.Y - pFeature.Extent.Height * (i + 1)
                    };
                }
                break;
                }
                pointCollection.AddPoint(point1);
                pointCollection.AddPoint(point2);
                pointCollection.AddPoint(point3);
                pointCollection.AddPoint(point4);
                pointCollection.AddPoint(point1);
                list.Add(tempPolygon);
            }

            return(list);
        }