New labeler

Dec 1, 2010 at 6:06 PM

I love the new shapefile object labeler. It performs much better and it seems to be more efficient. The issue I am having is that labels seem to be aligned before they are rotated. If I set label alignments to be centered on the point it is not an issue.  As soon as  I align the labels to the left or the right of the point they end up on the opposite side of the point whenever I rotate them. Is there a way to align the label after the rotation has been applied?

Here is my code.


Sub Streets_Label()
        AxMap1.ShapeDrawingMethod = MapWinGIS.tkShapeDrawingMethod.dmNewWithLabels

        Dim label As New MapWinGIS.Shapefile
        Dim label90 As New MapWinGIS.Labels
        Dim Man_Labels As New MapWinGIS.Labels

        label = AxMap1.get_GetObject(2)
        label.Labels.FontBold = True
        label.Labels.FontItalic = False
        label.Labels.FontUnderline = False
        label.Labels.FontName = "Arial"
        label.Labels.FontSize = 10
        label.Labels.FontColor = System.Convert.ToUInt32(RGB(255, 0, 0))
        label.Labels.ScaleLabels = True
        label.Labels.ShadowVisible = False
        label.Labels.Alignment = MapWinGIS.tkLabelAlignment.laCenterLeft
        label.Labels.AvoidCollisions = False
        Label.Labels.DynamicVisiblity = True
        label.Labels.MaxVisibleScale = 0.0202189640335268
        'label.GenerateLabels(4, MapWinGIS.tkLabelPositioning.lpMiddleSegment, True)

        Man_Labels = label.Labels

        'Adds address labels from a access data table
        Dim Rotation As Double
        Dim cn As OleDb.OleDbConnection
        Dim cmd As OleDb.OleDbCommand
        Dim dr As OleDb.OleDbDataReader
        Dim x As Double, y As Double
        Dim text As String
        Dim col As Integer

        col = 0
        'Create data connection
        cn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MobileMapping\Data\labels.mdb;")
        cmd = New OleDb.OleDbCommand("select * from ADDRESS_MOD", cn)
        dr = cmd.ExecuteReader
        While dr.Read()
            x = dr(1)
            y = dr(0)
            text = dr(4)
            Rotation = dr(2)
            Man_Labels.AddLabel(text, x, y, Rotation, 1)
        End While
    End Sub

Dec 3, 2010 at 5:59 PM
Edited Dec 3, 2010 at 6:00 PM

Hi dlourenco,

it's somewhat difficult to answer without seeing a screenshot. Do you have the latest version of ocx? There were some changes in the alignment property this Autumn which can be relevant to the issue.

I've written a test procedure and it seems to work correctly (see C# code below). 

Hope it'll help,


        private void btnLabelRotation_Click(object sender, EventArgs e)
            MapWinGIS.Shapefile sf = new Shapefile();
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = sf.CdlgFilter;
            if (dlg.ShowDialog() == DialogResult.OK)
                if (sf.Open(dlg.FileName, null))
                    if (sf.ShapefileType != ShpfileType.SHP_POINT)
                        MessageBox.Show("Point shapefile is expected. Exiting...");

                    Random rnd = new Random();
                    for (int i = 0; i < sf.NumShapes; i++)
                        MapWinGIS.Point pnt = sf.get_Shape(i).get_Point(0);
                        if (pnt != null)
                            sf.Labels.AddLabel(sf.get_CellValue(0, i).ToString(), pnt.x, pnt.y, rnd.NextDouble() * 360, 0);

                    sf.Labels.ScaleLabels = true;
                    sf.Labels.Alignment = tkLabelAlignment.laBottomLeft;   // any you like

                    int handle = axMap1.AddLayer(sf, true);
Dec 7, 2010 at 6:25 PM

Dear All,

I' ve a problem with the labeler infact I'm not able to see the label on my map.

The attached function is a modified version of AutomaticGeneration I've found on your old website.

The version I'm using is the last official relise  MapwinGis downloaded  from this website.

The programming environment is vb net express 10.

Do you have any advice?

Best Regards


   ' ****************************************************************
    '       Automatic generation of labels
    ' ****************************************************************
    Public Sub AutomaticGeneration(ByRef mFrm As System.Windows.Forms.Form, ByRef handle As Integer, ByRef fieldIndex As Integer, ByRef myColor As Integer)
        Dim obj As Object
        Dim sf As MapWinGIS.Shapefile
        Dim lb As New MapWinGIS.Labels
        Dim myInteger As Integer
        Dim i As Integer
        With frmMain
            .Map1.ShapeDrawingMethod = MapWinGIS.tkShapeDrawingMethod.dmNewWithLabels
            obj = .Map1.get_GetObject(handle)
            If TypeOf obj Is MapWinGIS.Shapefile Then
                sf = obj
                Exit Sub
            End If
            If sf.ShapefileType = MapWinGIS.ShpfileType.SHP_POLYGON Then
                myInteger = sf.GenerateLabels(fieldIndex, MapWinGIS.tkLabelPositioning.lpCentroid)
            ElseIf (sf.ShapefileType = MapWinGIS.ShpfileType.SHP_POINT Or sf.ShapefileType = MapWinGIS.ShpfileType.SHP_POINTZ) Then
                myInteger = sf.GenerateLabels(fieldIndex, MapWinGIS.tkLineLabelOrientation.lorHorizontal)
                myInteger = sf.GenerateLabels(fieldIndex, MapWinGIS.tkLabelPositioning.lpLongestSegement, True)
            End If
            lb = sf.Labels
            If lb Is Nothing Then Exit Sub
            lb.FontBold = True
            lb.FontItalic = False
            lb.FontUnderline = False
            lb.FontName = "Arial"
            lb.FontOutlineVisible = True
            lb.FontSize = 10
            lb.FrameType = MapWinGIS.tkLabelFrameType.lfRoundedRectangle
            lb.FrameVisible = True
            lb.FrameOutlineWidth = 3
            lb.FrameOutlineColor = System.Convert.ToUInt32(RGB(255, 255, 255))
            lb.FrameVisible = True
            lb.FontColor = System.Convert.ToUInt32(RGB(255, 255, 255))
            lb.FontOutlineColor = System.Convert.ToUInt32(RGB(255, 255, 255))
            'lb.ScaleLabels = True
            lb.ShadowVisible = False
            lb.Alignment = MapWinGIS.tkLabelAlignment.laCenterLeft
            lb.AvoidCollisions = False
            lb.DynamicVisiblity = True
            lb.BasicScale = 15
            lb.HaloVisible = True
            lb.HaloSize = 20
            lb.Visible = True
            lb.UseGdiPlus = True
            .Map1.set_LayerLabelsVisible(handle, True)
        End With
    End Sub