MapLabelLayer Help

Dec 8, 2010 at 6:19 PM

Help please.

I have been struggling with adding labels to the map using IMapLayer. I have tried various different methods however I still get an object reference not set to an object exception. If I open the shape file using the addLayer map method then I can open the feature labeler and add labels with no problems. However when I add the layers by code I get an exception when I set featurelayer.showlabels = true when it is added to the map. I have attached my symbology routine below, that includes my labeling routine (the symbology works great).

 Case maplayertheme.e_county ' enum: 10033
                    poly = New PolygonSymbolizer
                    'clear all previous patterns, including default
                    poly.Patterns.Clear()
                    sPattern = New SimplePattern
                    With sPattern
                        .Outline.SetFillColor(GetTransRGBColor(84, 143, 44, 64))
                        .UseOutline = True
                        .Outline.SetWidth(0.5)
                        .Opacity = 0
                    End With
                    poly.Patterns.Add(sPattern)

                    'set symbology
                    _flayer.Symbolizer = poly

                    ' Display Annotation
                    If LayerTipsField <> "" Then

                        'set up for label
                        labelLayer = New MapLabelLayer(_flayer)
                        With labelLayer
                            .Symbology.Categories.Clear()
                            Dim lc As LabelCategory = New LabelCategory()
                            lc.Expression = "[" & LayerTipsField & "]"
                            .Symbology.Categories.Add(lc)
                        End With

                        Dim ls As ILabelSymbolizer = Nothing
                        ls = New LabelSymbolizer
                        ls = labelLayer.Symbolizer
                        ls.Orientation = ContentAlignment.MiddleCenter
                        ls.BackColorEnabled = False
                        ls.BackColorEnabled = False
                        'ls.FontColor = fontColor
                        ' ls.FontFamily = Font.FontFamily.ToString()
                        'ls.FontSize = Font.Size
                        'ls.FontStyle = Font.Style
                        ls.PartsLabelingMethod = PartLabelingMethod.LabelLargestPart
                        _flayer.ShowLabels = True

                        _flayer.LabelLayer = labelLayer
                    End If

                    isSymbolized = True

  

Jan 18, 2011 at 12:56 AM

I am having the same exact problem with still no resolution, could someone please respond to this and offer a code sample on labeling polygons.  Here is my snippet:

        //'---------------------------------------------------------
        //' METHOD:                                        
        //'---------------------------------------------------------

        private void LabelPolygons()
        {
            //' Label the plots with the plot number
            IMapLabelLayer labelLayer = new MapLabelLayer(mFeatureSet);
            labelLayer.Symbology.Categories.Clear();
            labelLayer.Symbology.AddCategory();

            ILabelCategory category = new LabelCategory();
            category = labelLayer.Symbology.Categories[0];
            category.Expression = "[plot_nbr]";
            category.Symbolizer.Orientation = ContentAlignment.MiddleCenter;
 
            mFeatureLayer.LabelLayer = labelLayer;
            mFeatureLayer.ShowLabels = true;  //' Object reference not set to an instance of an object error here --
        }