windowsforms-114666-controls-and-libraries-map-control-examples-vector-data-providing-data-how-to-provide-additional-property-values-from-a-data-source-using-property-mappings.md
To provide additional property values from a data source using property mappings, create instances of the MapRectangleWidthMapping and MapRectangleHeightMapping classes, specify their properties and add them to the DataSourceAdapterBase.PropertyMappings collection.
class StateRect {
// The latitude of top-left angle of a rectangle.
public double Top { get; set; }
// The longitude of top-left angle of a rectangle.
public double Left { get; set; }
// The width in kilometers of a rectangle.
public double Width { get; set; }
// The height in kilometers of a rectangle.
public double Height { get; set; }
}
// Create a data source.
List<StateRect> dataSource = new List<StateRect> {
new StateRect { Top = 44.996250, Left = -111.049638, Width = 496, Height = 444 },
new StateRect { Top = 48.990004, Left = -104.042967, Width = 480, Height = 338 },
new StateRect { Top = 45.944326, Left = -104.042967, Width = 528, Height = 338 },
new StateRect { Top = 41.000038, Left = -109.049518, Width = 528, Height = 445 }
};
private void Form1_Load(object sender, EventArgs e) {
// Create a data source for the vector layer.
var dataAdapter = new ListSourceDataAdapter();
dataAdapter.DataSource = dataSource;
dataAdapter.DefaultMapItemType = MapItemType.Rectangle;
// Specify the obligatory mappings.
dataAdapter.Mappings.Latitude = "Top";
dataAdapter.Mappings.Longitude = "Left";
// Add rectange specific property mappings.
dataAdapter.PropertyMappings.AddRange(new MapItemPropertyMappingBase[] {
new MapRectangleWidthMapping { Member = "Width", DefaultValue = 0 },
new MapRectangleHeightMapping { Member = "Height", DefaultValue = 0 }
});
VectorLayer.Data = dataAdapter;
}
Private Class StateRect
' The latitude of top-left angle of a rectangle.
Public Property Top() As Double
' The longitude of top-left angle of a rectangle.
Public Property Left() As Double
' The width in kilometers of a rectangle.
Public Property Width() As Double
' The height in kilometers of a rectangle.
Public Property Height() As Double
End Class
' Create a data source.
Private dataSource As New List(Of StateRect)() From { _
New StateRect With {.Top = 44.996250, .Left = -111.049638, .Width = 496, .Height = 444}, _
New StateRect With {.Top = 48.990004, .Left = -104.042967, .Width = 480, .Height = 338}, _
New StateRect With {.Top = 45.944326, .Left = -104.042967, .Width = 528, .Height = 338}, _
New StateRect With {.Top = 41.000038, .Left = -109.049518, .Width = 528, .Height = 445} _
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
' Create a data source for the vector layer.
Dim dataAdapter = New ListSourceDataAdapter()
dataAdapter.DataSource = dataSource
dataAdapter.DefaultMapItemType = MapItemType.Rectangle
' Specify the obligatory mappings.
dataAdapter.Mappings.Latitude = "Top"
dataAdapter.Mappings.Longitude = "Left"
' Add rectange specific property mappings.
dataAdapter.PropertyMappings.AddRange(New MapItemPropertyMappingBase() { _
New MapRectangleWidthMapping With {.Member = "Width", .DefaultValue = 0}, _
New MapRectangleHeightMapping With {.Member = "Height", .DefaultValue = 0} _
})
VectorLayer.Data = dataAdapter
End Sub