windowsforms-devexpress-dot-xtramap-dot-mapitemattribute-d7379142.md
Specifies the mapping value of the map item attribute.
Namespace : DevExpress.XtraMap
Assembly : DevExpress.XtraMap.v25.2.dll
NuGet Package : DevExpress.Win.Map
[DefaultValue(null)]
public object Value { get; set; }
<DefaultValue(Nothing)>
Public Property Value As Object
| Type | Default | Description |
|---|---|---|
| Object | null |
An object that is the value of the map item attribute.
|
For more information, see Provide Data Using Vector Item Attributes.
This example demonstrates how to paint two triangles on a map using the choropleth colorizer.
To accomplish this task for map shapes, do the following:
Create a choropleth colorizer using the VectorItemsLayer.Colorizer property;
Specify range stops (data splits in ranges) for the colorizer using the ChoroplethColorizer.RangeStops property;
Specify a set of colors in the GenericColorizerItemCollection<T> object, which is accessed via the ChoroplethColorizer.ColorItems property;
Create a MapItemAttribute object using the MapItem.Attributes property;
Specify the attribute name and value using the corresponding properties (MapItemAttribute.Name and MapItemAttribute.Value);
Assign the ShapeAttributeValueProvider object with the specified attribute name (ShapeAttributeValueProvider.AttributeName) to the ChoroplethColorizer.ValueProvider property.
using DevExpress.Utils;
using DevExpress.XtraMap;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Manual_Colorization {
public partial class Form1 : Form {
const string areaValueAttrName = "AreaValue";
const string polygonNameAttrName = "PolygonName";
public Form1() {
InitializeComponent();
InitializeMap();
}
void InitializeMap() {
// Create a map control and add it to the form.
MapControl map = new MapControl() { Dock = DockStyle.Fill };
this.Controls.Add(map);
// Create a layer to display vector data.
VectorItemsLayer itemsLayer = new VectorItemsLayer();
map.Layers.Add(itemsLayer);
// Generate a data storage for the layer.
itemsLayer.Data = CreateData();
// Create a colorizer for the layer.
itemsLayer.Colorizer = CreateColorizer();
// Create a legend for the layer.
map.Legends.Add(CreateLegend(itemsLayer));
// Specify tooltips for the map.
map.ToolTipController = new ToolTipController() { AllowHtmlText = true };
}
private MapItemStorage CreateData() {
MapItemStorage storage = new MapItemStorage();
// Create the first triangle.
storage.Items.Add(
CreatePolygon(800, "Small triangle",
new GeoPoint[] {
new GeoPoint(0, 0), new GeoPoint(0, 40),
new GeoPoint(40, 0), new GeoPoint(0, 0)
}
)
);
// Create the second triangle.
storage.Items.Add(
CreatePolygon(1800, "Large triangle",
new GeoPoint[] {
new GeoPoint(0, 0), new GeoPoint(0, -60),
new GeoPoint(-60, 0), new GeoPoint(0, 0)
}
)
);
return storage;
}
#region #CreatePolygon
private MapPolygon CreatePolygon(double areaValue, string polygonName, GeoPoint[] points) {
MapPolygon item = new MapPolygon();
item.Attributes.Add(new MapItemAttribute() {
Name = areaValueAttrName,
Type = typeof(double),
Value = areaValue
});
item.Attributes.Add(new MapItemAttribute() {
Name = polygonNameAttrName,
Type = typeof(string),
Value = polygonName
});
item.ToolTipPattern = "{" + polygonNameAttrName + "}=<b>{" + areaValueAttrName + "}</b>";
foreach (GeoPoint point in points) {
item.Points.Add(point);
}
return item;
}
#endregion #CreatePolygon
private MapColorizer CreateColorizer() {
ChoroplethColorizer colorizer = new ChoroplethColorizer();
colorizer.ValueProvider = new ShapeAttributeValueProvider {
AttributeName = areaValueAttrName
};
colorizer.RangeStops.AddRange(new List<double> { 0, 1000, 2000 });
colorizer.ColorItems.AddRange(new List<ColorizerColorItem> {
new ColorizerColorItem(Color.Yellow),
new ColorizerColorItem(Color.Red)
});
return colorizer;
}
private MapLegendBase CreateLegend(MapItemsLayerBase layer) {
ColorScaleLegend legend = new ColorScaleLegend();
legend.Header = "Area";
legend.Layer = layer;
return legend;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Manual_Colorization {
static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Imports DevExpress.Utils
Imports DevExpress.XtraMap
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms
Namespace Manual_Colorization
Partial Public Class Form1
Inherits Form
Private Const areaValueAttrName As String = "AreaValue"
Private Const polygonNameAttrName As String = "PolygonName"
Public Sub New()
InitializeComponent()
InitializeMap()
End Sub
Private Sub InitializeMap()
' Create a map control and add it to the form.
Dim map As New MapControl() With {.Dock = DockStyle.Fill}
Me.Controls.Add(map)
' Create a layer to display vector data.
Dim itemsLayer As New VectorItemsLayer()
map.Layers.Add(itemsLayer)
' Generate a data storage for the layer.
itemsLayer.Data = CreateData()
' Create a colorizer for the layer.
itemsLayer.Colorizer = CreateColorizer()
' Create a legend for the layer.
map.Legends.Add(CreateLegend(itemsLayer))
' Specify tooltips for the map.
map.ToolTipController = New ToolTipController() With {.AllowHtmlText = True}
End Sub
Private Function CreateData() As MapItemStorage
Dim storage As New MapItemStorage()
' Create the first triangle.
storage.Items.Add(CreatePolygon(800, "Small triangle", New GeoPoint() { _
New GeoPoint(0, 0), _
New GeoPoint(0, 40), _
New GeoPoint(40, 0), _
New GeoPoint(0, 0) _
}))
' Create the second triangle.
storage.Items.Add(CreatePolygon(1800, "Large triangle", New GeoPoint() { _
New GeoPoint(0, 0), _
New GeoPoint(0, -60), _
New GeoPoint(-60, 0), _
New GeoPoint(0, 0) _
}))
Return storage
End Function
#Region "#CreatePolygon"
Private Function CreatePolygon(ByVal areaValue As Double, ByVal polygonName As String, ByVal points() As GeoPoint) As MapPolygon
Dim item As New MapPolygon()
item.Attributes.Add(New MapItemAttribute() With {.Name = areaValueAttrName, .Type = GetType(Double), .Value = areaValue})
item.Attributes.Add(New MapItemAttribute() With {.Name = polygonNameAttrName, .Type = GetType(String), .Value = polygonName})
item.ToolTipPattern = "{" & polygonNameAttrName & "}=<b>{" & areaValueAttrName & "}</b>"
For Each point As GeoPoint In points
item.Points.Add(point)
Next point
Return item
End Function
#End Region ' #CreatePolygon
Private Function CreateColorizer() As MapColorizer
Dim colorizer As New ChoroplethColorizer()
colorizer.ValueProvider = New ShapeAttributeValueProvider With {.AttributeName = areaValueAttrName}
colorizer.RangeStops.AddRange(New List(Of Double) From {0, 1000, 2000})
colorizer.ColorItems.AddRange(New List(Of ColorizerColorItem) From { _
New ColorizerColorItem(Color.Yellow), _
New ColorizerColorItem(Color.Red) _
})
Return colorizer
End Function
Private Function CreateLegend(ByVal layer As MapItemsLayerBase) As MapLegendBase
Dim legend As New ColorScaleLegend()
legend.Header = "Area"
legend.Layer = layer
Return legend
End Function
End Class
End Namespace
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Windows.Forms
Namespace Manual_Colorization
Friend NotInheritable Class Program
Private Sub New()
End Sub
''' <summary>
''' The main entry point for the application.
''' </summary>
<STAThread> _
Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1())
End Sub
End Class
End Namespace
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Value 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.
winforms-map-load-data-from-a-sql-geometry-data-source/CS/SqlGeometry/Form1.cs#L38
foreach (MapPath path in e.Items) {
int id = Convert.ToInt32(path.Attributes["id"].Value);
string modified = path.ExportToWkt().ToString();
winforms-map-load-data-from-a-sql-geometry-data-source/VB/SqlGeometry/Form1.vb#L37
For Each path As DevExpress.XtraMap.MapPath In e.Items
Dim id As Integer = System.Convert.ToInt32(path.Attributes(CStr(("id"))).Value)
Dim modified As String = path.ExportToWkt().ToString()
See Also