windowsforms-15091-controls-and-libraries-map-control-vector-data-vector-items.md
Vector items are vector shapes that the Map Control can render on the map surface. Items can be loaded from different sources, clustered and painted based on a condition. The Map Control can also handle actions when a user highlights or selects items. The Map Control uses vector item layers to store items.
The Map Control ships with Map Editor UI that allows users to create items at runtime. For more information, refer to the following help topic: Map Editor.
To add additional information to vector items, you can specify item attributes. Then, you can show this information in tooltips or use it to find a specific item by its attribute.
The following image shows how to use vector items to create an airplane tracker application. In this example, pushpins with custom images are used to display airplanes and dots show airport locations. Geodesic lines display the available routes between airports:
The following code adds a dot with the specified location, size, and color:
VectorItemsLayer VectorLayer { get { return (VectorItemsLayer)map.Layers["VectorLayer"]; } }
MapItemStorage ItemStorage { get { return (MapItemStorage)VectorLayer.Data; } }
private void Form1_Load(object sender, System.EventArgs e) {
ItemStorage.Items.Add(new MapDot() { Location = new GeoPoint(-10, 10), Size = 18, Stroke = Color.Blue });
}
Private ReadOnly Property VectorLayer As VectorItemsLayer
Get
Return CType(map.Layers("VectorLayer"), VectorItemsLayer)
End Get
End Property
Private ReadOnly Property ItemStorage As MapItemStorage
Get
Return CType(VectorLayer.Data, MapItemStorage)
End Get
End Property
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
ItemStorage.Items.Add(New MapDot() With {
.Location = New GeoPoint(-10, 10),
.Size = 18,
.Stroke = Color.Blue
})
End Sub
You can use this approach to load other shapes. The available shapes are listed below:
Use a MapBubble object to display a circle whose size is measured in pixels. In addition to the location and size, you can assign a value to the bubble.
MapCallout objects allow you to show callouts with text or/and image content.
MapCustomElement objects allow you to show text or/and image content.
Use MapDot objects to show circles whose size is measured in pixels.
MapEllipse allows you to draw ellipses with their width and height measured in kilometers. Ellipses support a geodesic view.
MapLine allows you to draw a line between two points. Lines support a geodesic view. You can show lines as arrows.
MapPath allows you to display shapes that can contain multiple segments.
MapPie allows you to display pie charts on the map surface.
MapPolygon allows you to display polygons.
MapPolyline allows you to draw lines that contain multiple segments. Polylines support a geodesic view. You can show polylines as arrows.
MapPushpin allows you to draw pushpins. You can replace the default pushpin icon with a custom raster or SVG image.
MapRectangle allows you to draw rectangles.
MapSpline allows you to draw a multi-point spline. You can show splines as arrows.
The Map Control allows you to load vector items from well-known text formatted strings.
Use the ListSourceDataAdapter to load data from a collection of objects.
You can visualize data as bubbles and pies. To do this, use the BubbleChartDataAdapter and PieChartDataAdapter.
The following list contains supported file formats and data adapters you should use to load data to a map:
KmlFileDataAdapterLoads data from .kml, .kmz files.ShapefileDataAdapterLoads data from shapefiles (.shp, .dbf).SvgFileDataAdapterLoads data from .svg files.SqlGeometryDataAdapterLoads data from SQL geometry databases.GeoJsonFileDataAdapterLoads data from .geojson files.GpxFileDataAdapterLoads data from .gpx files.
The Map Control ships with the following API that allow you to zoom the map so its viewport contains the specified items or an area:
The following properties allow you to customize map items in different states (normal, highlighted, and selected):
Refer to the following topic to get the list of available examples: Providing Data.