Пример #1
0
        /// <summary>
        /// 定义任务区多边形名称注记
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static ITextElement getTextElement(string name)
        {
            //定义任务区名称符号格式
            IRgbColor pColor = new RgbColorClass()
            {
                Red   = 0,
                Blue  = 255,
                Green = 0
            };
            IFontDisp pFont = new StdFont()
            {
                Name = "宋体",
                Bold = true
            } as IFontDisp;
            ITextSymbol pTextSymbol = new TextSymbolClass()
            {
                Color = pColor,
                Font  = pFont,
                Size  = 10
            };
            ITextElement pTextElement = new TextElementClass()
            {
                Symbol    = pTextSymbol,
                ScaleText = true,
                Text      = name
            };

            return(pTextElement);
        }
Пример #2
0
        private static IGridLabel CreateMixedFontGridLabel()
        {
            IMixedFontGridLabel mixedFontGridLabelClass = new MixedFontGridLabel() as IMixedFontGridLabel;
            IGridLabel          gridLabel    = mixedFontGridLabelClass as IGridLabel;
            IFontDisp           stdFontClass = new StdFont() as IFontDisp;

            stdFontClass.Name     = "Arial";
            stdFontClass.Size     = new decimal(16);
            gridLabel.Font        = stdFontClass;
            gridLabel.Color       = CartoHelper.BuildRGB(0, 0, 0);
            gridLabel.LabelOffset = 2;
            gridLabel.LabelAlignment[esriGridAxisEnum.esriGridAxisLeft]  = false;
            gridLabel.LabelAlignment[esriGridAxisEnum.esriGridAxisRight] = false;
            stdFontClass      = new StdFont() as IFontDisp;
            stdFontClass.Name = "Arial";
            stdFontClass.Size = new decimal(12);
            mixedFontGridLabelClass.SecondaryFont    = stdFontClass;
            mixedFontGridLabelClass.SecondaryColor   = CartoHelper.BuildRGB(0, 0, 0);
            mixedFontGridLabelClass.NumGroupedDigits = 6;
            IFormattedGridLabel formattedGridLabel = mixedFontGridLabelClass as IFormattedGridLabel;
            INumericFormat      format             = new NumericFormat() as INumericFormat;

            format.AlignmentOption = esriNumericAlignmentEnum.esriAlignRight;
            format.RoundingOption  = esriRoundingOptionEnum.esriRoundNumberOfDecimals;
            format.RoundingValue   = 2;
            format.ShowPlusSign    = true;
            format.UseSeparator    = false;
            format.ZeroPad         = true;
            INumericFormat numericFormatClass = format as INumericFormat;

            formattedGridLabel.Format = numericFormatClass as INumberFormat;
            return(gridLabel);
        }
Пример #3
0
        /// <summary>
        /// 显示指定图层指定字段的标注
        /// </summary>
        /// <param name="geoLayer">要设置注标注的图层(IFeatureLayer as IGeoFeatureLayer)</param>
        /// <param name="fieldName">显示标注的字段</param>
        /// <param name="fontName">标注的字体</param>
        /// <param name="size">标注的大小</param>
        public static void ShowLabel(this IGeoFeatureLayer geoLayer, string fieldName, string fontName = "宋体", int size = 12)
        {
            //标注属性集
            IAnnotateLayerPropertiesCollection annotateLyrProColl = geoLayer.AnnotationProperties;

            annotateLyrProColl.Clear();

            //普通标准属性(另一个是Maplex标准属性)
            ILabelEngineLayerProperties labelEngine = new LabelEngineLayerPropertiesClass();

            labelEngine.Expression = $"[{fieldName}]";

            //字体
            IFontDisp fontDisp = new StdFont()
            {
                Name = fontName, Bold = false
            } as IFontDisp;

            //标注符号
            ITextSymbol textSymbol = new TextSymbolClass();

            textSymbol.Color   = ColorCreate.GetIColor(0, 0, 0);
            textSymbol.Font    = fontDisp;
            textSymbol.Size    = size;
            labelEngine.Symbol = textSymbol;

            //设置同名标注:默认为移除同名标注,应设为每个要素放置一个标注
            IBasicOverposterLayerProperties basicOverpLyrPro = labelEngine.BasicOverposterLayerProperties as IBasicOverposterLayerProperties;

            basicOverpLyrPro.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape;//每个要素放置一个标注

            annotateLyrProColl.Add(labelEngine as IAnnotateLayerProperties);
            geoLayer.DisplayAnnotation = true;
        }
Пример #4
0
        /// <summary>
        /// 插入带文字的注记
        /// </summary>
        /// <param name="point"></param>
        /// <param name="mapControl"></param>
        /// <param name="text"></param>
        /// <returns></returns>

        public static IElement DrawSymbolWithText(IPoint point, AxMapControl mapControl, string text)
        {
            #region 设置样式
            IFontDisp pFont = new StdFont()
            {
                Name = "宋体",
                Size = 5
            } as IFontDisp;

            ITextSymbol pTextSymbol = new TextSymbolClass()
            {
                Color = GetColor(255, 0, 0),
                Font  = pFont,
                Size  = 11
            };
            #endregion
            //设置带注记的元素
            ITextElement pTextElment = null;
            pTextElment = new TextElementClass()
            {
                Symbol    = pTextSymbol,
                ScaleText = true,
                Text      = text
            };
            IElement pEle = pTextElment as IElement;
            pEle.Geometry = point;
            //添加标注
            InsertElement(mapControl, pEle, 1);
            return(pEle);
        }
Пример #5
0
        //添加标注
        void itemaddlable_Click(object sender, EventArgs e)
        {
        //    //使用TextElment绘制标注, fieldName为要绘制的属性
        //public static void AddLable(AxMapControl axMapControl, ILayer layer, string fieldName)
        //{
            ILayer layer = Global.mainmap.Map.get_Layer(0);
            
            IRgbColor pColor = new RgbColorClass()
            {
                Red = 255,
                Blue = 0,
                Green = 0
            };
            IFontDisp pFont = new StdFont()
            {
                Name = "宋体",
                Size = 5
            } as IFontDisp;
            
            ITextSymbol pTextSymbol = new TextSymbolClass()
            {
                Color = pColor,
                Font = pFont,
                Size = 11
            };

            IGraphicsContainer pGraContainer = Global.mainmap.Map as IGraphicsContainer;

            //遍历要标注的要素
            IFeatureLayer pFeaLayer = layer as IFeatureLayer;
            IFeatureClass pFeaClass = pFeaLayer.FeatureClass;
            IFeatureCursor pFeatCur = pFeaClass.Search(null, false);
            IFeature pFeature = pFeatCur.NextFeature();
            int index = pFeature.Fields.FindField("NAME");//要标注的字段的索引
            IEnvelope pEnv = null;
            ITextElement pTextElment = null;
            IElement pEle = null;
            while (pFeature != null)
            {
                //使用地理对象的中心作为标注的位置
                pEnv = pFeature.Extent;
                IPoint pPoint = new PointClass();
                pPoint.PutCoords(pEnv.XMin + pEnv.Width * 0.5, pEnv.YMin + pEnv.Height * 0.5);

                pTextElment = new TextElementClass()
                {
                    Symbol = pTextSymbol,
                    ScaleText = true,
                    Text = pFeature.get_Value(index).ToString()
                };
                pEle = pTextElment as IElement;
                pEle.Geometry = pPoint;
                //添加标注
                pGraContainer.AddElement(pEle, 0);
                pFeature = pFeatCur.NextFeature();
            }
            (Global.mainmap.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, Global.mainmap.Extent);
       
        }
Пример #6
0
        private void ActiveViewEventsOnAfterDraw(IDisplay display, esriViewDrawPhase phase)
        {
            if (!_drawFence)
            {
                return;
            }
            if (_fenceArray == null || _fenceArray.Count == 0)
            {
                return;
            }
            IScreenDisplay paramScreenDisplay = ((IActiveView)_context.FocusMap).ScreenDisplay;

            paramScreenDisplay.StartDrawing(paramScreenDisplay.hDC, -2);
            for (int i = 0; i < _fenceArray.Count; i++)
            {
                IGeometry fence = _fenceArray.Element[i];
                if (fence.IsEmpty)
                {
                    continue;
                }
                if (fence is IPolyline)
                {
                    paramScreenDisplay.SetSymbol(_lineSymbol);
                    paramScreenDisplay.DrawPolyline(fence);
                }
                else if (fence is IPolygon)
                {
                    paramScreenDisplay.SetSymbol(_fillSymbol);
                    paramScreenDisplay.DrawPolygon(fence);
                }
            }
            if (_drawPage && _pageInfos != null && _pageInfos.Count > 0)
            {
                IFontDisp disp = new StdFont() as IFontDisp;
                disp.Name = "Arial";
                disp.Size = new decimal(16);

                foreach (IPrintPageInfo pageInfo in _pageInfos)
                {
                    IGeometry pageBoundary = pageInfo.Boundary;
                    paramScreenDisplay.SetSymbol(_fillSymbol);
                    paramScreenDisplay.DrawPolygon(pageBoundary);
                    _textSymbol = SymbolHelper.CreateTextSymbol(Color.Red, disp, 16, pageInfo.PageName);
                    paramScreenDisplay.SetSymbol(_textSymbol as ISymbol);
                    if (!string.IsNullOrEmpty(pageInfo.PageName))
                    {
                        IPoint    centerPoint = new ESRI.ArcGIS.Geometry.Point();
                        IEnvelope pEnv        = pageBoundary.Envelope;
                        centerPoint.PutCoords((pEnv.XMin + pEnv.Width / 2.0), pEnv.YMin + pEnv.Height / 2.0);
                        paramScreenDisplay.DrawText(centerPoint, pageInfo.PageName);
                    }
                }
            }
            paramScreenDisplay.FinishDrawing();
        }
Пример #7
0
        private void btnLabel_Click(object sender, RoutedEventArgs e)
        {
            //The FeatureLayer for labelling


            IFeatureLayer    labelLayer  = this.m_map.Map.get_Layer(0) as IFeatureLayer;
            IGeoFeatureLayer gLabelLayer = labelLayer as IGeoFeatureLayer;
            IAnnotateLayerPropertiesCollection annoPropCol = gLabelLayer.AnnotationProperties;

            annoPropCol.Clear();
            //ITextSymbol uasage
            ITextSymbol pTextSyl = new TextSymbol();
            //Font fnt = new System.Drawing.Font("宋体", 10f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
            //using stdole
            IFontDisp font = new StdFont() as IFontDisp;

            font.Size   = 20;
            font.Italic = true;
            // pTextSyl.Size = 20;
            pTextSyl.Font = font;
            //IRgbColor fromColor = new RgbColor(255,0, 0);
            //ESRI.ArcGIS.Display.RgbColorClass()
            RgbColor color = new RgbColor();

            color.Red      = 255;
            color.Green    = 0;
            color.Blue     = 0;
            pTextSyl.Color = color;
            //Position
            IBasicOverposterLayerProperties pBasic = new BasicOverposterLayerProperties();

            //   if (labelLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
            //   {
            IPointPlacementPriorities pPlacementPoint = new PointPlacementPriorities();

            pBasic.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
            pBasic.PointPlacementPriorities = pPlacementPoint;
            pBasic.PointPlacementOnTop      = false;
            pBasic.PointPlacementMethod     = esriOverposterPointPlacementMethod.esriOnTopPoint;// esriAroundPoint;
            //      }

            //Point a field as a label
            ILabelEngineLayerProperties labelField = new LabelEngineLayerProperties() as ILabelEngineLayerProperties;

            labelField.Expression = "[name]";
            //set postion
            labelField.BasicOverposterLayerProperties = pBasic;
            //set  symbol
            labelField.Symbol = pTextSyl;
            IAnnotateLayerProperties annoProp = labelField as IAnnotateLayerProperties;

            annoPropCol.Add(annoProp);
            gLabelLayer.DisplayAnnotation = true;
            m_map.Refresh();
        }
Пример #8
0
        public static IFontDisp CreateFont(string pFontName, float pSize)
        {
            StdFont class2 = new StdFont();

            class2.Name          = pFontName;
            class2.Size          = Convert.ToDecimal(pSize);
            class2.Bold          = false;
            class2.Italic        = false;
            class2.Underline     = false;
            class2.Strikethrough = false;
            return(class2 as IFontDisp);
        }
Пример #9
0
        private void ShowLabel()
        {
            if (labelOn)
            {
                if (!this.cbxActiveMap.HasItems || !this.cbxFeatureLayer.HasItems || !this.cbxField.HasItems)
                {
                    return;
                }
                if (annoPropCol != null)
                {
                    annoPropCol.Clear();
                }
                labelLayer  = this.m_map.Map.get_Layer(this.cbxFeatureLayer.SelectedIndex) as IFeatureLayer;
                gLabelLayer = labelLayer as IGeoFeatureLayer;
                annoPropCol = gLabelLayer.AnnotationProperties;

                ITextSymbol pTextSyl = new TextSymbol();
                IFontDisp   font     = new StdFont() as IFontDisp;
                font.Size     = 20;
                font.Italic   = true;
                pTextSyl.Font = font;
                RgbColor color = new RgbColor();
                color.Red      = LabelColor.R;
                color.Green    = LabelColor.G;
                color.Blue     = LabelColor.B;
                pTextSyl.Color = color;

                IBasicOverposterLayerProperties pBasic          = new BasicOverposterLayerProperties();
                IPointPlacementPriorities       pPlacementPoint = new PointPlacementPriorities();
                pBasic.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
                pBasic.PointPlacementPriorities = pPlacementPoint;
                pBasic.PointPlacementOnTop      = false;
                pBasic.PointPlacementMethod     = esriOverposterPointPlacementMethod.esriOnTopPoint;

                ILabelEngineLayerProperties labelField = new LabelEngineLayerProperties() as ILabelEngineLayerProperties;

                //IFeatureClass fClass = ((IFeatureLayer)labelLayer).FeatureClass;
                //IFields fields = fClass.Fields;
                //String fieldName = fields.get_Field(this.cbxField.SelectedIndex).Name;

                string fieldName = (string)cbxField.SelectedItem;
                //Console.WriteLine(fields.FindField(fieldName));
                labelField.Expression = "[" + fieldName + "]";
                //set postion
                labelField.BasicOverposterLayerProperties = pBasic;
                //set  symbol
                labelField.Symbol = pTextSyl;
                IAnnotateLayerProperties annoProp = labelField as IAnnotateLayerProperties;
                annoPropCol.Add(annoProp);
                gLabelLayer.DisplayAnnotation = true;
                m_map.Refresh();
            }
        }
Пример #10
0
        public static IFontDisp CreateFont(string pFontName, float pSize, bool pBold, bool pItalic, bool pUnderline,
                                           bool pStroke)
        {
            StdFont class2 = new StdFont();

            class2.Name          = pFontName;
            class2.Size          = Convert.ToDecimal(pSize);
            class2.Bold          = pBold;
            class2.Italic        = pItalic;
            class2.Underline     = pUnderline;
            class2.Strikethrough = pStroke;
            return(class2 as IFontDisp);
        }
Пример #11
0
        //给图片加标签
        private void Label(AxMapControl IN_Axmapcontrols, IEnvelope pEnv, ResultItem r, string name, int fontsize)
        {
            IGraphicsContainer pGraContainer = (IGraphicsContainer)IN_Axmapcontrols.Map;

            pGraContainer.DeleteAllElements();

            IPoint pPoint = new PointClass();

            pPoint.PutCoords(pEnv.XMin, pEnv.YMin + pEnv.Height * 0.15);

            IRgbColor pColor = new RgbColorClass()
            {
                Red   = 255,
                Blue  = 0,
                Green = 255
            };

            IFontDisp pFont = new StdFont()
            {
                Name = "宋体",
                Bold = true
            } as IFontDisp;

            ITextSymbol pTextSymbol = new TextSymbolClass()
            {
                Color = pColor,
                Font  = pFont,
                HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft,
                Size = 15
            };

            ITextElement pTextElement = new TextElementClass()
            {
                Symbol    = pTextSymbol,
                ScaleText = true,
                //Size = 15,  //若用缩小图则设置为4,大图为15
                //Text = "河名:" + RiverID + "\n" + "镇名:" + RegionID + "\n" + address +
                //"\n" + "经度:" + Convert.ToString(lng) + "\n" + "纬度:" + Convert.ToString(Lat)
                //Text = "图号:" + r.Figure + "\n" + "镇名:" + r.RegionID + "\n" + "位置:" + address + " " + "\n"
                //+ "经纬度:" + r.Location.X + " " + r.Location.Y + "\n"

                Size = fontsize, //若用缩小图则设置为4,大图为15
                Text = name
            };

            IElement pEle = (IElement)pTextElement;

            pEle.Geometry = pPoint;

            pGraContainer.AddElement(pEle, 0);
        }
Пример #12
0
//        标题

        private void AddTitle(String title)
        {
            IGraphicsContainer graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer;
            IEnvelope          envelope          = new EnvelopeClass();
            double             x = 8;
            double             y = 22;

            envelope.PutCoords(x, y, x + 5, y + 5);
            IRgbColor pColor = new RgbColorClass()
            {
                Red   = 0,
                Blue  = 0,
                Green = 0
            };

            IFontDisp pFont = new StdFont()
            {
                Name = "宋体",
                Bold = true
            } as IFontDisp;

            ITextSymbol pTextSymbol = new TextSymbolClass()
            {
                Color = pColor,
                Font  = pFont,
                Size  = 25
            };

            ITextElement pTextElement = new TextElementClass()
            {
                Symbol    = pTextSymbol,
                ScaleText = true,
                Text      = title
            };

            IElement element = pTextElement as IElement;

            element.Geometry = envelope;
            graphicsContainer.AddElement(element, 0);
            axPageLayoutControl1.Refresh();
        }
Пример #13
0
            public StdFont Clone()
            {
                StdFont tempFont = new StdFont();
                tempFont.Bold = Bold;
                tempFont.Italic = Italic;
                tempFont.Name = Name;
                tempFont.Size = Size;
                tempFont.StrikeThrough = StrikeThrough;
                tempFont.UnderLine = UnderLine;
                tempFont.CharSet = CharSet;
                tempFont.Weight = Weight;

                return tempFont;
            }