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
                    sPattern = New SimplePattern
                    With sPattern
                        .Outline.SetFillColor(GetTransRGBColor(84, 143, 44, 64))
                        .UseOutline = True
                        .Opacity = 0
                    End With

                    'set symbology
                    _flayer.Symbolizer = poly

                    ' Display Annotation
                    If LayerTipsField <> "" Then

                        'set up for label
                        labelLayer = New MapLabelLayer(_flayer)
                        With labelLayer
                            Dim lc As LabelCategory = New LabelCategory()
                            lc.Expression = "[" & LayerTipsField & "]"
                        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);

            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 --