MapWinGIS:AxMap AddLabel

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

AddLabel

Adds a label to the map.
See also tkHJustification


VB.NET Usage

Sub AddLabel(LayerHandle As Integer, Text As String, Color As System.UInt32, x As Double, y As Double,
             hJustification As MapWinGIS.tkHJustification)

            Parameters

LayerHandle

The handle of the layer where the label will be added to.
Text The text to be used for the label.
Color The color of the added label. This is a UInt32 representation of an RGB color.
x The x coordinate in projected map units which determines where the label will be added on the map.
y The y coordinate in projected map units which determines where the label will be added on the map
hJustification Specifies whether to justify the label's text right, left, or center.

Sample Code

    Private Sub AddLabel()
        Dim hndl As Integer, field As Integer, i As Integer
        Dim sf As MapWinGIS.Shapefile
        Dim text As String
        Dim x As Double, y As Double
        Dim col As UInt32
        'Get handle for layer 0 which must contain a shapefile
        hndl = Map1.get_LayerHandle(0)
        'Get the shapefile contained in layer 0
        sf = Map1.get_GetObject(hndl)
        'Set shapefile field to use when labeling layer as field 0
        field = 0
        'Set the color for the labels to be black
        col = System.Convert.ToUInt32(RGB(0, 0, 0))
        'Label every shape in the shapefile
        For i = 0 To sf.NumShapes - 1
            'Set the text for this shape
            text = sf.CellValue(field, i)
            'Set the x and y coordinates for this label to be the min x and y coordinates of this shape
            x = sf.Shape(i).Extents.xMin
            y = sf.Shape(i).Extents.yMin
            'Add the label to the layer by the shape centering the text
            Map1.AddLabel(hndl, text, col, x, y, MapWinGIS.tkHJustification.hjCenter)
        Next
    End Sub
  

C# Usage

 private void AddLabel()
 {
        int hndl;
        int field;
        int i;
        MapWinGIS.Shapefile sf;
        string text;
        double x;
        double y;
        UInt32 col;
        //Get handle for layer 0 which must contain a shapefile
        hndl = AxMap1.get_LayerHandle(0);
        //Get the shapefile contained in layer 0
        sf = (MapWinGIS.Shapefile)AxMap1.get_GetObject(hndl);
        //Set shapefile field to use when labeling layer as field 0
        field = 0;
        //Set the color for the labels to be black
        col = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToWin32(System.Drawing.Color.Black));
        //Label every shape in the shapefile
        for (i = 0; i <= sf.NumShapes - 1; i++)
        {
                //Set the text for this shape
                text = (string)sf.get_CellValue(field, i);
                //Set the x and y coordinates for this label to be the min x and y coordinates of this   shape
                x = sf.get_Shape(i).Extents.xMin;
                y = sf.get_Shape(i).Extents.yMin;
 
                //Add the label to the layer by the shape centering the text
                AxMap1.AddLabel(hndl, text, col, x, y, MapWinGIS.tkHJustification.hjCenter);
        }
 }
    

VB 6 Usage

Sub AddLabel(LayerHandle As Long, Text As String, Color As OLE_COLOR, x As Double, y As Double,
             hJustification As tkHJustification)

            Parameters

LayerHandle

The handle of the layer where the label will be added to.
Text The text to be used for the label.
Color The color of the added label.
x The x coordinate in projected map units which determines where the label will be added on the map.
y The y coordinate in projected map units which determines where the label will be added on the map
hJustification Specifies whether to justify the label's text right, left, or center.

Sample Code

    Private Sub AddLabel()
        Dim hndl As Long
        Dim field As Integer, i As Integer
        Dim sf As MapWinGIS.Shapefile
        Dim text As String
        Dim x As Double, y As Double
        Dim col As OLE_COLOR
        'Get handle for layer 0 which must contain a shapefile
        hndl = Map1.LayerHandle(0)
        'Get the shapefile contained in layer 0
        sf = Map1.GetObject(hndl)
        'Set shapefile field to use when labeling layer as field 0
        field = 0
        'Set the color for the labels to be black
        col = RGB(0, 0, 0)
        'Label every shape in the shapefile
        For i = 0 To sf.NumShapes - 1
            'Set the text for this shape
            text = sf.CellValue(field, i)
            'Set the x and y coordinates for this label to be the min x and y coordinates of this shape
            x = sf.Shape(i).extents.xMin
            y = sf.Shape(i).extents.yMin
            'Add the label to the layer by the shape centering the text
            Map1.AddLabel(hndl, text, col, x, y, tkHJustification.hjCenter)
        Next
    End Sub

--Earljon 13:13, 14 April 2008 (UTC)

Retrieved from "http://mapwindow.org/wiki/index.php/MapWinGIS:AxMap_AddLabel"

This page has been accessed 4,449 times. This page was last modified on 14 April 2008, at 13:13.