Skip to main content

Provide Data Using Vector Item Attributes

  • 3 minutes to read

Attributes are used to associate a vector item with supplementary information. The Map Control operates with vector item attributes, allowing you to visualize any kind of data.

A single attribute is represented by the MapItemAttribute object. This object can be accessed as an item of the MapItemAttributeCollection, returned by the MapItem.Attributes property of the MapItem class descendant.

These attributes can be specified in various ways, depending on the approach the Map Control utilizes to obtain vector items. The sections below describe each approach in detail, as well as how to use vector item attributes.

Manual Creation of Vector Items

When vector items are created manually, you can also specify the attributes for any vector item.

MapControl_Attributes

To create an attribute:

The following code shows how this can be done for the Map Bubble Chart.

<dxm:MapBubble>
     <dxm:MapBubble.Attributes>
         <dxm:MapItemAttribute Name="Name" Value="Bubble"/>
         <dxm:MapItemAttribute Name="Description" Value="This is a bubble chart"/>
     </dxm:MapBubble.Attributes>
 </dxm:MapBubble>

Loading Vector Items from a Vector Format File

When the map control obtains vector items from a vector format file using ShapefileDataAdapter, KmlFileDataAdapter or SqlGeometryDataAdapter, vector item attributes are generated automatically.

The following code demonstrates how to load data from a Shapefile.

<dxm:VectorLayer>
    <dxm:ShapeFileDataAdapter FileUri="Countries.shp"/>
</dxm:VectorLayer>

Loading Vector Items from a Datasource

If the Map Control obtains vector items from a datasource, the attributes are created by mapping data source fields to vector item attributes.

As a result of vector item mapping, the map control specifies which data field from the data source will be bound to which attribute of DataSourceAdapterBase descendant generated items. The adapter can be accessed using the VectorItemsLayer.Data property.

To create vector item attributes, do the following.

The code below shows how to add Name, Year and Description attributes to the map item attribute mapping collection.

<dxm:VectorLayer>
    <dxm:ListSourceDataAdapter>
        <dxm:ListSourceDataAdapter.AttributeMappings>
            <dxm:MapItemAttributeMapping Name="Name" Member="Name"/>
            <dxm:MapItemAttributeMapping Name="Year" Member="Year"/>
            <dxm:MapItemAttributeMapping Name="Description" Member="Description"/>
        </dxm:ListSourceDataAdapter.AttributeMappings>
    </dxm:ListSourceDataAdapter>
</dxm:VectorLayer>

Using Vector Item Attributes

There are different ways to use vector item attributes in your application.

One of the popular uses of vector item attributes is the displaying of vector data from a datasource in tooltips. To learn how this can be done, see the How to: Create a Map Item Attribute and Show its Value in the Map Tooltip example.

Another example is to color shape contours depending on data associated with a shape. To do this, use the Colorizers. See the How to: Colorize Map Contours Using the Choropleth Colorizer example to learn more.

See Also