IColorizerElement.ColorizerColor Property
Gets or sets a color to colorize a map element.
Namespace: DevExpress.XtraMap
Assembly: DevExpress.XtraMap.v18.2.dll
Declaration
Property Value
Type | Description |
---|---|
Color | A Color object that represents a color to colorize the map element. |
Example
This example demonstrates how to create a custom colorizer and use it for implementing a progress bar on a map.
The colorizer fills bars with colors according to the specified power value stored as a shape attribute.
To implement a custom colorizer, create a class inherited from the MapColorizer base class and implement the ColorizerBase<T>.ColorizeElement method according to your custom rules.
For example, in this case, the custom colorizer does the following:
Obtains the power value from the shape attribute (via the MapItem.Attributes property);
Selects a color that corresponds to this value (e.g., from the predefined array of Color objects);
Assigns this color to the
IColorizerElement.ColorizerColor
property of the element passed to the ColorizerBase<T>.ColorizeElement method.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-implement-a-custom-colorizer-e4753
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraMap;
namespace CustomColorizer {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
const string powerAttrName = "PowerValue";
const double maxPower = 1000;
const int rectNumber = 50;
private void Form1_Load(object sender, EventArgs e) {
// Create a map control, set its dock style and add it to the form.
MapControl map = new MapControl();
map.Dock = DockStyle.Fill;
this.Controls.Add(map);
// Create a vector items layer and add it to the map.
VectorItemsLayer itemsLayer = new VectorItemsLayer();
map.Layers.Add(itemsLayer);
MapItemStorage storage = new MapItemStorage();
itemsLayer.Data = storage;
// Generate map polygons.
GenerateVectorItems(storage.Items);
// Specify the tooltip content.
itemsLayer.ToolTipPattern = "{" + powerAttrName + "}";
// Create a custom colorizer.
itemsLayer.Colorizer = new CustomColorizer();
}
private void GenerateVectorItems(MapItemCollection col) {
int width = 5;
double singlePower = maxPower / rectNumber;
for (int i = 0; i < rectNumber; i++) {
MapPolygon polygon = CreatePolygon(i * singlePower,
new GeoPoint[] { new GeoPoint(0, width * i),
new GeoPoint(0, width * (i + 1)),
new GeoPoint(40, width * (i + 1)),
new GeoPoint(40, width * i),
new GeoPoint(0, width * i) });
col.Add(polygon);
}
}
private MapPolygon CreatePolygon(double power, GeoPoint[] points) {
MapPolygon item = new MapPolygon();
foreach (GeoPoint point in points) {
item.Points.Add(point);
}
item.Attributes.Add(new MapItemAttribute() { Name = powerAttrName, Type = typeof(Double), Value = power });
return item;
}
private class CustomColorizer : MapColorizer {
Color[] colors = {Color.Violet, Color.Blue, Color.LightBlue, Color.Green,Color.Yellow, Color.Orange, Color.Red};
public override void ColorizeElement(IColorizerElement element) {
MapPolygon polygon = element as MapPolygon;
if (polygon != null) {
double power = (double)polygon.Attributes[powerAttrName].Value;
int linearizedPower = (int)Math.Truncate(power * colors.Length / maxPower);
element.ColorizerColor = colors[linearizedPower];
}
}
}
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ColorizerColor 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.