Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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();
            }
        }