windowsforms-devexpress-dot-xtramap-781db531.md
Represents the Graph colorizer utilized to paint shapes that have a common border using different colors.
Namespace : DevExpress.XtraMap
Assembly : DevExpress.XtraMap.v25.2.dll
NuGet Package : DevExpress.Win.Map
public class GraphColorizer :
GenericColorizer<ColorizerColorItem>
Public Class GraphColorizer
Inherits GenericColorizer(Of ColorizerColorItem)
To colorize vector items using this colorizer, assign a GraphColorizer object to the VectorItemsLayer.Colorizer property. Then, add ColorizerColorItem objects to the GraphColorizer.ColorItems.
For more information, refer to Colorizers.
This example paints map contours loaded from a Shapefile ( Countries.shp ) using the graph colorizer.
To accomplish this task, create a graph colorizer (the GraphColorizer object) and assign it to the VectorItemsLayer.Colorizer property.
Then, specify the desired set of colors in the GenericColorizerItemCollection<T> object that is accessed via the GraphColorizer.ColorItems property.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraMap;
namespace MapGraphColorizer {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
// Create a map control and specify its dock style.
MapControl map = new MapControl();
map.Dock = DockStyle.Fill;
// Specify the map's initial view.
map.ZoomLevel = 2;
map.CenterPoint = new GeoPoint(38, -100);
// Create a file layer and assign a shape loader to it.
map.Layers.Add(new VectorItemsLayer() {
Data = CreateData(),
Colorizer = CreateColorizer()
});
// Add the map control to the window.
this.Controls.Add(map);
}
private IMapDataAdapter CreateData() {
// Create an object to load data from a shapefile.
ShapefileDataAdapter loader = new ShapefileDataAdapter();
// Determine the path to the Shapefile.
Uri baseUri = new Uri(System.Reflection.Assembly.GetEntryAssembly().Location);
string shapefilePath = "../../Data/Countries.shp";
loader.FileUri = new Uri(baseUri, shapefilePath);
return loader;
}
private MapColorizer CreateColorizer() {
// Create a graph colorizer.
GraphColorizer colorizer = new GraphColorizer();
// Specify colors for the colorizer.
colorizer.ColorItems.AddRange(new List<ColorizerColorItem> {
new ColorizerColorItem(Color.FromArgb(0xF1, 0xC1, 0x49)),
new ColorizerColorItem(Color.FromArgb(0xE5, 0xA8, 0x4D)),
new ColorizerColorItem(Color.FromArgb(0xC5, 0x64, 0x50)),
new ColorizerColorItem(Color.FromArgb(0xD6, 0x86, 0x4E)),
new ColorizerColorItem(Color.FromArgb(0x79, 0x96, 0x89)),
new ColorizerColorItem(Color.FromArgb(0xA2, 0xA8, 0x75))
});
return colorizer;
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraMap
Namespace MapGraphColorizer
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
' Create a map control and specify its dock style.
Dim map As New MapControl()
map.Dock = DockStyle.Fill
' Specify the map's initial view.
map.ZoomLevel = 2
map.CenterPoint = New GeoPoint(38, -100)
' Create a file layer and assign a shape loader to it.
map.Layers.Add(New VectorItemsLayer() With {.Data = CreateData(), .Colorizer = CreateColorizer()})
' Add the map control to the window.
Me.Controls.Add(map)
End Sub
Private Function CreateData() As IMapDataAdapter
' Create an object to load data from a shapefile.
Dim loader As New ShapefileDataAdapter()
' Determine the path to the Shapefile.
Dim baseUri As New Uri(System.Reflection.Assembly.GetEntryAssembly().Location)
Dim shapefilePath As String = "../../Data/Countries.shp"
loader.FileUri = New Uri(baseUri, shapefilePath)
Return loader
End Function
Private Function CreateColorizer() As MapColorizer
' Create a graph colorizer.
Dim colorizer As New GraphColorizer()
' Specify colors for the colorizer.
colorizer.ColorItems.AddRange(New List(Of ColorizerColorItem) From { _
New ColorizerColorItem(Color.FromArgb(&HF1, &HC1, &H49)), _
New ColorizerColorItem(Color.FromArgb(&HE5, &HA8, &H4D)), _
New ColorizerColorItem(Color.FromArgb(&HC5, &H64, &H50)), _
New ColorizerColorItem(Color.FromArgb(&HD6, &H86, &H4E)), _
New ColorizerColorItem(Color.FromArgb(&H79, &H96, &H89)), _
New ColorizerColorItem(Color.FromArgb(&HA2, &HA8, &H75)) _
})
Return colorizer
End Function
End Class
End Namespace
Object MapDisposableObject ColorizerBase<IColorizerElement> MapColorizer PredefinedColorsColorizer GenericColorizer<ColorizerColorItem> GraphColorizer
See Also