windowsforms-devexpress-dot-xtramap-dot-mapitem-a538907b.md
Gets or sets the object that contains data related to a map item.
Namespace : DevExpress.XtraMap
Assembly : DevExpress.XtraMap.v25.2.dll
NuGet Package : DevExpress.Win.Map
[DefaultValue(null)]
public object Tag { get; set; }
<DefaultValue(Nothing)>
Public Property Tag As Object
| Type | Default | Description |
|---|---|---|
| Object | null |
A Object that contains information about the map item.
|
Any type derived from the Object class can be assigned to this property. Use it to store data associated with a map item.
The following example adds two pushpins to a map item storage. Each pushpin’s Tag property is initialized with an object of the ItemInfo type. The storage’s DataChanged event handler defines pushpins’ visibility based on the ItemInfo.IsOpened property value.
VectorItemsLayer vectorLayer;
//...
private void Form1_Load(object sender, EventArgs e) {
vectorLayer = new VectorItemsLayer();
mapControl1.Layers.Add(vectorLayer);
MapItemStorage storage = new MapItemStorage();
vectorLayer.Data = storage;
storage.DataChanged += Storage_DataChanged;
MapPushpin pushpin1 = new MapPushpin();
pushpin1.Location = new GeoPoint(48.862644, 2.336578);
pushpin1.Tag = new ItemInfo { IsOpened = true };
storage.Items.Add(pushpin1);
MapPushpin pushpin2 = new MapPushpin();
pushpin2.Location = new GeoPoint(59.9398, 30.3146);
pushpin2.Tag = new ItemInfo { IsOpened = false };
storage.Items.Add(pushpin2);
}
private void Storage_DataChanged(object sender, DataAdapterChangedEventArgs e) {
foreach (MapItem item in vectorLayer.Data.Items) {
ItemInfo info = item.Tag as ItemInfo;
item.Visible = info.IsOpened;
}
}
public class ItemInfo {
public bool IsOpened { get; set; }
}
Private vectorLayer As VectorItemsLayer
'...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
vectorLayer = New VectorItemsLayer()
mapControl1.Layers.Add(vectorLayer)
Dim storage As MapItemStorage = New MapItemStorage()
vectorLayer.Data = storage
storage.DataChanged += AddressOf Storage_DataChanged
Dim pushpin1 As MapPushpin = New MapPushpin()
pushpin1.Location = New GeoPoint(48.862644, 2.336578)
pushpin1.Tag = New ItemInfo With {
.IsOpened = True
}
storage.Items.Add(pushpin1)
Dim pushpin2 As MapPushpin = New MapPushpin()
pushpin2.Location = New GeoPoint(59.9398, 30.3146)
pushpin2.Tag = New ItemInfo With {
.IsOpened = False
}
storage.Items.Add(pushpin2)
End Sub
Private Sub Storage_DataChanged(ByVal sender As Object, ByVal e As DataAdapterChangedEventArgs)
For Each item As MapItem In vectorLayer.Data.Items
Dim info As ItemInfo = TryCast(item.Tag, ItemInfo)
item.Visible = info.IsOpened
Next
End Sub
Public Class ItemInfo
Public Property IsOpened As Boolean
End Class
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Tag property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
IList<DashboardFlatDataSourceRow> selectedRows = selection.GetDashboardFlatDataSourceRows(flatData);
var selectedLines = mapItemStorage.Items.Where(item => selectedRows.Contains(item.Tag));
vectorLayer.SelectedItems.AddRange(selectedLines.ToList());
Dim selectedRows As IList(Of DashboardFlatDataSourceRow) = selection.GetDashboardFlatDataSourceRows(flatData)
Dim selectedLines = mapItemStorage.Items.Where(Function(item) selectedRows.Contains(item.Tag))
vectorLayer.SelectedItems.AddRange(selectedLines.ToList())
See Also