MapWinGIS:SampleCode-VB Net:AddLabels

This is a back-up of the WIKI.
Not all links might work
We're working on a new wiki.

Main Page | Recent changes | View source | Page history | Log in / create account |

Printable version | Disclaimers | Privacy policy

Add Rotated Labels to Current Extent

This sub will attempt to determine the direction of a line using the points 1/3 and 2/3 of the way through the shapefile. It will add labels to the lines in the current extent.

     'Globally Defined sf As MapWinGIS.Shapefile
     'Globally Defined layer as Integer
     '
     '** Adds rotated labels to lines only currently in view
     '
     Sub Add_Labels()
         Dim text As String
         Dim col As UInt32
         Dim ext As MapWinGIS.Extents
         Dim shapes As Object
         Dim I As Integer
         Dim InfoField As Integer = 11 'The column of the dbf
         Dim x1, x2, y1, y2, angle As Double
         AxMap1.set_LayerLabelsVisible(layer, True)
         AxMap1.set_LayerLabelsOffset(layer, True)
         AxMap1.set_LayerLabelsShadow(layer, True)
 
         'Set the color for the labels to be black 
         col = Convert.ToUInt32(RGB(0, 0, 0))
         AxMap1.LayerFont(layer, "Arial", 8)
 
         'Determine the shapes in the current extent
         ext = AxMap1.Extents
         If sf.SelectShapes(ext, 0, MapWinGIS.SelectMode.INTERSECTION, shapes) = False Then Exit Sub
         For I = 0 To shapes.GetUpperBound(0)
             text = sf.CellValue(InfoField, shapes(I))
             Dim MidPointIndex, LC, RC As Integer
             MidPointIndex = Int(sf.Shape(shapes(I)).numPoints / 2)
             LC = MidPointIndex * 2 / 3
             RC = MidPointIndex * 4 / 3
             x1 = sf.QuickPoint(shapes(I), LC).x
             x2 = sf.QuickPoint(shapes(I), RC).x
             y1 = sf.QuickPoint(shapes(I), LC).y
             y2 = sf.QuickPoint(shapes(I), RC).y
             angle = (y2 - y1) / (x2 - x1)
             angle = Math.Atan(angle)
             angle = (angle * 180) / 3.14159265358979
             AxMap1.AddLabelEx(layer, text, col, x1, y1, MapWinGIS.tkHJustification.hjLeft, angle)
         Next
 
     End Sub

Posted by Shade1974 on 12/14/2005

Retrieved from "http://mapwindow.org/wiki/index.php/MapWinGIS:SampleCode-VB_Net:AddLabels"

This page has been accessed 2,383 times. This page was last modified on 14 December 2005, at 15:40.