Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

HeatmapDensityBasedAlgorithm Class

The algorithm that allows the Map Control to plot a heatmap based on the density of heatmap points.

Namespace: DevExpress.Xpf.Map

Assembly: DevExpress.Xpf.Map.v24.2.dll

NuGet Package: DevExpress.Wpf.Map

#Declaration

public class HeatmapDensityBasedAlgorithm :
    HeatmapAlgorithmBase,
    IDensityBasedAlgorithm,
    IHeatmapAlgorithm

#Remarks

When you use the HeatmapDensityBasedAlgorithm to create a heatmap, the Map Control aggregates points into areas of different colors. An area with high point density is painted red. A green area indicates that this region contains a low number of points. The Map Control re-aggregates heatmap points when you zoom in/out of a map. For this reason, areas of aggregated points can change their colors.

To change the predefined color scheme, specify the HeatmapProvider.Colorizer property. The first item in the ChoroplethColorizer.Colors collection defines a color for areas with low point density, the last item specifies the color of areas with high point density.

#Example

This example shows how to create a heatmap layer for the Map Control.

Markup

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Heatmap"
        xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map" 
        x:Class="Heatmap.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.DataContext>
        <local:EarthquakesData/>
    </Window.DataContext>
    <Grid>
        <dxm:MapControl ZoomLevel="2">
            <dxm:ImageLayer>
                <dxm:BingMapDataProvider BingKey="Your Bing Maps key here."/>
            </dxm:ImageLayer>
            <!-- The heatmap layer configuration -->
            <dxm:ImageLayer Name="heatmapLayer" Opacity="0.75">
                <dxm:HeatmapProvider>
                    <dxm:HeatmapProvider.Colorizer>
                        <dxm:ChoroplethColorizer RangeStops="0.1, 0.2, 0.7, 1.0" 
                                                 ApproximateColors="True">
                            <dxm:ChoroplethColorizer.Colors>
                                <Color A="50"  R="128"  G="255"  B="0"/>
                                <Color A="255" R="255"  G="255"  B="0"/>
                                <Color A="255" R="234"  G="72"   B="58"/>
                                <Color A="255" R="162"  G="36"   B="25"/>
                            </dxm:ChoroplethColorizer.Colors>
                        </dxm:ChoroplethColorizer>
                    </dxm:HeatmapProvider.Colorizer>
                    <dxm:HeatmapProvider.PointSource>
                        <dxm:HeatmapDataSourceAdapter DataSource="{Binding Path=DataItems}">
                            <dxm:HeatmapDataSourceAdapter.Mappings>
                                <dxm:HeatmapPointMappingInfo XCoordinate="Longitude" 
                                                             YCoordinate="Latitude"/>
                            </dxm:HeatmapDataSourceAdapter.Mappings>
                        </dxm:HeatmapDataSourceAdapter>
                    </dxm:HeatmapProvider.PointSource>
                    <dxm:HeatmapProvider.Algorithm>
                        <dxm:HeatmapDensityBasedAlgorithm PointRadius="10"/>
                    </dxm:HeatmapProvider.Algorithm>
                </dxm:HeatmapProvider>
            </dxm:ImageLayer>
            <!--...-->
        </dxm:MapControl>
    </Grid>
</Window>

Code-Behind

using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Xml.Serialization;
namespace Heatmap {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }
    }
    public class EarthquakeViewModel {
        [XmlElement("glat")]
        public double Latitude { get; set; }
        [XmlElement("glon")]
        public double Longitude { get; set; }
    }
    [XmlRoot("Data")]
    public class EarthquakesData {
        static EarthquakesData instance;
        public static List<EarthquakeViewModel> DataItems {
            get { return Instance.Items; }
        }
        public static EarthquakesData Instance {
            get { return instance ?? (instance = CreateInstance()); }
        }
        static EarthquakesData CreateInstance() {
            XmlSerializer serializer = new XmlSerializer(typeof(EarthquakesData));
            Stream documentStream = LoadStreamFromResources("/Data/Earthquakes.xml");
            return (EarthquakesData)serializer.Deserialize(documentStream);
        }
        [XmlElement("Row")]
        public List<EarthquakeViewModel> Items { get; set; }
        public static Stream LoadStreamFromResources(string fileName) {
            try {
                Uri uri = new Uri(fileName, UriKind.RelativeOrAbsolute);
                return Application.GetResourceStream(uri).Stream;
            }
            catch {
                return null;
            }
        }
    }
}
See Also