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

Markup
XAML |
<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
C# |
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;
}
}
}
}
|
VB |
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Windows
Imports System.Xml.Serialization
Namespace Heatmap
Public Partial Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
End Class
Public Class EarthquakeViewModel
<XmlElement("glat")>
Public Property Latitude As Double
<XmlElement("glon")>
Public Property Longitude As Double
End Class
<XmlRoot("Data")>
Public Class EarthquakesData
Shared instance As EarthquakesData
Public Shared ReadOnly Property DataItems As List(Of EarthquakeViewModel)
Get
Return Instance.Items
End Get
End Property
Public Shared ReadOnly Property Instance As EarthquakesData
Get
Return If(instance, (CSharpImpl.__Assign(instance, CreateInstance())))
End Get
End Property
Private Shared Function CreateInstance() As EarthquakesData
Dim serializer As XmlSerializer = New XmlSerializer(GetType(EarthquakesData))
Dim documentStream As Stream = LoadStreamFromResources("/Data/Earthquakes.xml")
Return CType(serializer.Deserialize(documentStream), EarthquakesData)
End Function
<XmlElement("Row")>
Public Property Items As List(Of EarthquakeViewModel)
Public Shared Function LoadStreamFromResources(ByVal fileName As String) As Stream
Try
Dim uri As Uri = New Uri(fileName, UriKind.RelativeOrAbsolute)
Return Application.GetResourceStream(uri).Stream
Catch
Return Nothing
End Try
End Function
Private Class CSharpImpl
Shared Function __Assign(Of T)(ByRef target As T, value As T) As T
target = value
Return value
End Function
End Class
End Class
End Namespace
|