Generate Vector Items Automatically
- 2 minutes to read
The Map control can display vector items from lists and list sources of objects.
To do this, follow the steps below:
Create an instance of the ListSourceDataAdapter class and assign it to the VectorItemsLayer.Data property.
Assign a list of data objects to the adapter’s DataSource property.
Specify the data object properties that are used to generate vector items. To provide this information, use a MapItemMappingInfo object returned by the ListSourceDataAdapter.Mappings property.
To create multi-point shapes (MapPolylines and MapPolygons), use the MapPolylinePointCollectionMapping and MapPolygonPointCollectionMapping objects.
The MapItemMappingInfo.Latitude and MapItemMappingInfo.Longitude properties should be mapped to data object properties containing latitude and longitude data.
- The MapItemMappingInfo.Type property should be mapped to a data object property, specifying the type of vector item to be generated. Note that if this mapping isn’t set, the type of generated vector items is defined by the ListSourceDataAdapter.DefaultMapItemType property value.
- If generated vector items have the Text property. The MapItemMappingInfo.Text property should be mapped to a data object property containing text to be displayed within a vector item.
- If generated vector items have the ImageIndex property. The MapItemMappingInfo.ImageIndex property should be mapped to a data object property containing an index of an image to be displayed in a vector item. Note that images to be accessed by the image index are stored in a map’s MapControl.ImageList collection.
When it is necessary to provide additional property values of complex shapes (e.g. MapRectangle, MapHitInfo.MapEllipse), use Property Mappings. To do this, add the MapItemPropertyMappingBase class descendant specifying the required property mapping, to the DataSourceAdapterBase.PropertyMappings collection. The following image demonstrates the result of using property mappings to specify the rectangles’ width and height.
Note
If you need to provide additional information for generated vector items (e.g., to display this information in tooltips), specify it using the DataSourceAdapterBase.AttributeMappings property of ListSourceDataAdapter. For detailed information, refer to Provide Data Using Vector Item Attributes.
To learn more on how to bind data using the ListSourceDataAdapter class, refer to How to: Automatically Generate Vector Items from a Datasource.