ComponentOne Maps for WinForms
In This Topic
    Quick Start: Map for Win Forms
    In This Topic

    This quick start guide familiarizes you with some of the features of Map control. In this section, you learn to create a new WinForms application in Visual Studio, add the C1Map control to the application, add vector data to it and run the application.

    Step 1: Creating an application with C1Map control

    1. Create a new Windows Forms Application
    2. Add C1Map control to the form in your application.
    3. Set the Dock property of C1Map control to Fill.

    Step 2: Adding vector data to Map

    1. Add the following namespaces in code view:
      • using C1.FlexMap
      • using C1.Win.Map
    2. Use the following code to display map in the C1Map control and add vector layer to it:
      'specify tile source used by the map
      C1Map1.TileLayer.TileSource = New VirtualEarthRoadSource()
      
      'create a vector layer and add it to the map
      Dim layer As New C1.Win.Map.VectorLayer()
      C1Map1.Layers.Add(layer)
      
      //specify tile source used by the map
      c1Map1.TileLayer.TileSource = new VirtualEarthRoadSource();
                  
      //create a vector layer and add it to the map
      C1.Win.Map.VectorLayer layer = new C1.Win.Map.VectorLayer();
      c1Map1.Layers.Add(layer);
      
      Maps for WinForms also support Bing Rest Api. To use the Api you need to pass Bing Maps key to VirtualEarthSource constructor, as shown below:
      c1Map1.TileLayer.TileSource = new VirtualEarthHybridSource("Bing_maps_key");
      
    3. Add a vector placemark element to the layer using VectorPlacemark class and customize the element using the following code:
      'Create a vector placemark and add it to the layer
      Dim vpl As New C1.Win.Map.VectorPlacemark()
      layer.Items.Add(vpl)
      
      'customize the vector placemark
      vpl.Style.BackColor = Color.Aqua
      vpl.Marker.Shape = MarkerShape.Diamond
      vpl.Marker.Size = New SizeF(10, 10)
      
      'set the geometry shape for vector placemark
      vpl.Geometry = New GeoPoint(75, 25)
      
      //Create a vector placemark and add it to the layer
      C1.Win.Map.VectorPlacemark vpl = new C1.Win.Map.VectorPlacemark();         
      layer.Items.Add(vpl);
      
      //customize the vector placemark
      vpl.Style.BackColor = Color.Aqua;
      vpl.Marker.Shape = MarkerShape.Diamond;
      vpl.Marker.Size = new SizeF(10, 10);
      
      //set the geometry shape for vector placemark
      vpl.Geometry = new GeoPoint(75,25);
      

    You can add any other vector elements such as, VectorPolyline and/or VectorPolygon to the map according to your requirements. To know more on adding these elements to the map, refer Adding VectorPolygon and Adding VectorPolyline to map.

    Step 3: Running the application

    Press F5 to run the application and observe how the C1Map control appears with the placemark vector added to it.
    Map control with placemark

    In addition to adding placemarks, you can add various types of vector data on a map. C1Maps also allows you to add markers on a map, customize them, and add image as markers as well, and add legends. For more information on further information, see Working with Map Control.