MapItem.ToolTipPattern Property
Gets or sets a string which represents the pattern specifying the text to be displayed within a tooltip that appears for a map item.
Namespace: DevExpress.XtraMap
Assembly: DevExpress.XtraMap.v24.2.dll
NuGet Package: DevExpress.Win.Map
#Declaration
#Property Value
Type | Default | Description |
---|---|---|
String | String. |
A string value that is the tooltip pattern. |
#Remarks
The pattern string can contain placeholders that the Map Control replaces with specific values when generating tooltip text for a map item. The tooltip pattern supports the following groups of placeholders:
Attribute Placeholders
These placeholders define values of map item attributes and enclosed with braces (“{“, “}”). For example the “{NAME}: ${GDP_MD_EST:#,0}M” pattern utilizes two placeholders. The first placeholder is for the NAME attribute and the second placeholder is for the GDP_MD_EST attribute. Note that the second placeholder has the #,0 format string that goes after the “:” symbol.
Map Chart Value Placeholders
The Map Control uses this placeholder group to display map bubbles’ and map pies’ arguments and values in the tooltip. The “%” symbol encloses these placeholders. The following table lists available placeholders:
Placeholder | Placeholder’s meaning for Map Bubbles | Placeholder’s meaning for Map Pies |
---|---|---|
A | A map bubble’s argument. | Data objects’ Pie |
V | A map bubble’s value. | A map pie’s total value. |
A |
Is not supported. | An argument of a map pie segment with the specified index. |
V |
Is not supported. | A value of a map pie segment with the specified index. |
For example, the “%A0%: %V0%\r\n%A1%: %V1%\r\n%A2%: %V2%” pattern generates the text that displays the first three segments’ arguments and values.
The chart value attributes with indices are useful when all map pies have a similar number of segments. You can use the ToolTip Controller to manage the tooltip’s content when map pies have various segment counts:
private void Form1_Load(object sender, EventArgs e) {
ToolTipController toolTipController = new ToolTipController();
toolTipController.BeforeShow += OnBeforeShowToolTip;
mapControl.ToolTipController = toolTipController;
}
private void OnBeforeShowToolTip(object sender, ToolTipControllerShowEventArgs e) {
if (!(e.SelectedObject is MapPie mapPie)) return;
e.Title = mapPie.Argument.ToString();
e.ToolTip = BuildSegmentsTooltip(mapPie.Segments);
}
private string BuildSegmentsTooltip(PieSegmentCollection segments) {
if (segments.Count == 0) return String.Empty;
var segment = segments[0];
var builder = new StringBuilder()
.Append(segment.Argument)
.Append(": ")
.Append(segment.Value);
for (int i = 1; i < segments.Count; i++) {
segment = segments[i];
builder.Append(Environment.NewLine)
.Append(segment.Argument)
.Append(": ")
.Append(segment.Value);
}
return builder.ToString();
}
The code above utilizes the following classes and members:
Symbol | Description |
---|---|
Tool |
A tooltip controller for individual UI controls. |
Tool |
Fires when a tooltip is about to be displayed. Allows you to dynamically specify the tooltip text, image, and appearance settings. |
Map |
The class used to draw a pie chart on a map. |
Map |
Gets or sets an object, which provides arguments for the Map |
Map |
Gets or sets segments of a map pie. |
Pie |
A segment of a pie chart item. |
Pie |
Gets or sets an object, which provides arguments for the Pie |
Pie |
Gets or sets the value of the pie segment. |
#Example
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;
}