New to Telerik UI for WinFormsStart a free 30-day trial

Colorization

Updated over 6 months ago

When used with a shape file, the colorization feature of RadMap allows the data objects to be easily colorized on the basis of a certain condition.

RadMap utilizes three different colorization objects expecting a collection of colors which will be evaluated and assigned to the different shapes.

Graph Colorization

The GraphColorizationStrategy internally arranges the predefined colors so that there are no shapes with the same color next to each other.

Figure 1: Graph Colorization

WinForms RadMap Graph Colorization

Setting up GraphColorizationStrategy

C#
private void SetupGraphColorizationStrategy()
{
    GraphColorizationStrategy colorizer = new GraphColorizationStrategy();
    colorizer.Colors = new List<Color>() {
            Color.LightBlue,
            Color.LightCoral,
            Color.Coral,
            Color.LightGray,
            Color.LightGreen
    };
    this.radMap1.MapElement.Layers["World Layout"].ColorizationStrategy = colorizer;
}

Choropleth Colorization

The ChoroplethColorizationStrategy arranges the predefined colors according to a collection range stops against which each of the shape objects will be evaluated.

Figure 2: Choropleth Colorization

WinForms RadMap Choropleth Colorization

Setting up ChoroplethColorizationStrategy

C#
private void SetupChoroplethColorizationStrategy()
{
    ChoroplethColorizationStrategy colorizer = new ChoroplethColorizationStrategy();
    colorizer.Colors = new List<Color>() {
            Color.Red,
            Color.Blue,
            Color.Green,
            Color.Yellow,
            Color.Brown,
            Color.Gray,
            Color.LightBlue,
            Color.LightCoral,
            Color.Coral,
            Color.LightGray,
            Color.LightGreen
    };
    colorizer.ValueProvider = new MapGeometryPropertyValueProvider("POP_CNTRY");
    colorizer.ColorStops = new List<double>() { 0, 1000000, 5000000, 10000000, 15000000, 20000000, 30000000, 40000000, 50000000, 100000000, 200000000 };
    this.radMap1.MapElement.Layers["World Layout"].ColorizationStrategy = colorizer;
    this.radMap1.MapElement.LegendElement.LegendInfoProvider = colorizer;
}

Property Colorization

Figure 3: Property Colorization

The PropertyColorizationStrategy evaluates the values of a certain property defined in the shape file. Depending on the result the engine assigns one of the predefined colors.

WinForms RadMap Property Colorization

Setting up PropertyColorizationStrategy

C#
private void SetupPropertyColorizationStrategy()
{
    PropertyColorizationStrategy colorizer = new PropertyColorizationStrategy();
    colorizer.Colors = new List<Color>() {
            Color.LightBlue,
            Color.Coral
    };
    colorizer.PropertyValues.Add(new PropertyColorizerItem("N", "NOT LANDLOCKED"));
    colorizer.PropertyValues.Add(new PropertyColorizerItem("Y", "LANDLOCKED"));
    colorizer.ValueProvider = new MapGeometryPropertyValueProvider("LANDLOCKED");
    this.radMap1.MapElement.Layers["World Layout"].ColorizationStrategy = colorizer;
    this.radMap1.MapElement.LegendElement.LegendInfoProvider = colorizer;
}

Here is the required code to setup the provider and read the sample shape file used in the examples above.

Setting up EmptyMapProvider

C#
private void SetupProvider()
{
    EmptyMapProvider emptyProvider = new EmptyMapProvider();
    emptyProvider.InitializationComplete += emptyProvider_InitializationComplete;
    this.radMap1.Providers.Add(emptyProvider);
}
private void emptyProvider_InitializationComplete(object sender, EventArgs e)
{
    List<PointG> locations = new List<PointG>();
    foreach (MapVisualElement el in this.radMap1.Layers["World Layout"].Overlays)
    {
        locations.Add(el.Location);
    }
    this.radMap1.BringIntoView(RectangleG.GetBoundingRectangle(locations));
}

Setting up Layer

C#
private void SetupLayer()
{
    MapLayer worldLayer = new MapLayer("World Layout");
    this.radMap1.Layers.Add(worldLayer);
}

Setting up Data

C#
private void SetupData()
{
    using (MemoryStream worldStream = new MemoryStream(Properties.Resources.world))
    using (MemoryStream worlDataStream = new MemoryStream(Properties.Resources.world_data))
    {
        ShapeFileReaderParameters parameters = new ShapeFileReaderParameters();
        parameters.ShapeStream = worldStream;
        parameters.DbfStream = worlDataStream;
        ShapeFileReader reader = new ShapeFileReader();
        List<MapVisualElement> elements = reader.Read(parameters);
        Font elementFont = new Font("Arial", 7f, FontStyle.Bold);
        foreach (MapGeometry element in elements)
        {
            element.Font = elementFont;
            element.ForeColor = Color.Black;
            element.Text = (string)element.ExtendedData.GetValue("CNTRY_NAME");
            element.BorderWidth = 1;
        }
        this.radMap1.Layers["World Layout"].AddRange(elements);
    }
}

See Also