ComponentOne Maps for ASP.NET Web Forms
Features / Vector Layer / Add a Label
In This Topic
    Add a Label
    In This Topic

    In this topic, you add a label to a geographic point, the geographic coordinates of Erie, Pennsylvania (USA), using a C1VectorLayer and a C1VectorPlacemark (see Vector Layer for more information).

    In the Designer

    1. Right click the control and select Properties from the context menu to open the Properties window.
    2. Click the ellipsis button (...) next to the Layers property to open the C1Layers Collection Editor.
    3. Click the drop-down arrow on the Add button and select C1VectorLayer. A C1VectorLayer is added to the Layers collection and its properties are displayed on the right side of the C1Layers Collection Editor.
    4. Expand the Placemark property group and set the LabelVisibility to Visible to make the of labels of the C1VectorPlacemark visible.
    5. Expand Data property group and set the DataType to WijJson.
    6. Click the ellipsis button (...) next to Vectors property to open the C1VectorItemBase Collection Editor.
    7. Click the drop-down arrow on the Add button and select C1VectorPlacemark. A C1VectorPlacemark is added to the C1VectorItemBase collection and its properties are displayed on the right side of the C1VectorItemBase Collection Editor.
    8. Set the Label to Erie, PA and Point to -80.0852, 42.1296.
    9. Click OK to close the C1VectorItemBase Collection Editor.
    10. Click OK to close the C1Layers Collection Editor.
    11. Press F5 to run the project.

    To know how to manipulate element visibility according to the scaling of the map, please see the Element Visibility section in the topic Vector Layer.

    In Source View

    Add the following markup between the <c1:C1Maps> </c1:C1Maps> tags to add a label over the maps control:

    Source View
    Copy Code
    <Layers>
        <c1:C1VectorLayer>
            <DataWijJson>
                <vectors>
                    <c1:C1VectorPlacemark  Label="Erie, PA"  Point="-80.0852, 42.1296" >
                    </c1:C1VectorPlacemark>
                </vectors>
            </DataWijJson>
            <Placemark LabelVisibility="Visible" />
        </c1:C1VectorLayer>
    </Layers>
    

    In Code

    1. Add the following code to the Page_Load event,  to add a label over the maps control:
      C#
      Copy Code
      // Create layer and add it to the map
      C1VectorLayer vl = new C1VectorLayer();
      C1Maps1.Layers.Add(vl);
      
      // Set the datasource type to use
      vl.DataType = DataType.WijJson;
      
      // Set the Label visibility
      vl.Placemark.LabelVisibility = LabelVisibility.Visible;
      
      //Create a vector placemark and add it to the layer
      C1VectorPlacemark vp1 = new C1VectorPlacemark();
      vl.DataWijJson.Vectors.Add(vp1);
      
      // Set the placemark to a set of geographical coordinates
      vp1.Point = new PointD(-80.107008, 42.16389);
      
      // Set the placemark's label and properties
      vp1.Label = "Erie, PA";
      

      VB
      Copy Code
      ' Create layer and add it to the map
      Dim vl As New C1VectorLayer()
      C1Maps1.Layers.Add(vl)
      
      ' Set the datasource type to use
      vl.DataType = DataType.WijJson
      
      ' Set the Label visibility
      vl.Placemark.LabelVisibility = LabelVisibility.Visible
      
      'Create a vector placemark and add it to the layer
      Dim vp1 As New C1VectorPlacemark()
      vl.DataWijJson.Vectors.Add(vp1)
      
      ' Set the placemark to a set of geographical coordinates
      vp1.Point = New PointD(-80.107008, 42.16389)
      
      ' Set the placemark's label and properties
      vp1.Label = "Erie, PA"
      
    2. Run the project.

    What You've Accomplished

    The following image shows a C1Maps control with the geographic coordinates of Erie, Pennsylvania (USA) labeled.

    The theme of the form has been set to metro-dark, for a better visibility of the label.