Web Components Displaying Heat Imagery
The Ignite UI for Web Components map control has the ability to show heat-map imagery through the use of the IgcShapefileRecord that are generated by a IgcShapeDataSource by loading geo-spatial data by loading shape files to a tile series.
It is highly recommended that you review the Binding Shape Files with Geo-Spatial Data topic as a pre-requisite to this topic.
Web Components Displaying Heat Imagery Example
When a IgcShapeDataSource loads its shape files, it converts that data into IgcShapefileRecord objects. These objects can be retrieved from the GetPointData() method of the IgcShapeDataSource and can then be used to create a heat-map through usage of a IgcTileGeneratorMapImagery object with a IgcHeatTileGenerator assigned to its IgcTileGeneratorMapImagery.tileGenerator property. This IgcTileGeneratorMapImagery can then be used in a IgcGeographicTileSeriesComponent as its tileImagery source.
The IgcHeatTileGenerator object works such that it has three value paths, xValues, yValues and values. As an example of how these could be used, in the case of a shape file that has information about population, you could consider the xValues to be longitude, yValues to be latitude, and values to be the population data. Each of these properties takes a number[].
The display of the geographic tile series when using the heat-map functionality can be customized by setting the minimumColor and maximumColor properties to “rgba” strings that describe colors that you wish to correspond to the minimum and maximum values of the collection that you assign to the values property of the IgcHeatTileGenerator. You can further customize this by setting the scaleColors property of the generator to contain a collection of strings that describe colors, as this will tell the IgcHeatTileGenerator what colors to use for the displayed values in the map. It is also possible to customize how colors in your scaleColors collection blur together by using the blurRadius, maxBlurRadius, and useBlurRadiusAdjustedForZoom properties.
The IgcHeatTileGenerator can also use a logarithmic scale. If you want to use this, you can set the useLogarithmicScale property to true.
Web Worker
The IgcHeatTileGenerator also has support for web workers to do the heavy lifting of the loading of the tile imagery from your shape file on a separate thread. This can greatly improve the performance of your geographic map when using the heat-map functionality. In order to use a web worker with the generator, you can set the useWebWorkers property to true and then set the webWorkerInstance property to an instance of your web worker.
// heatworker.worker.ts
import { HeatTileGeneratorWebWorker } from 'igniteui-webcomponents-core';
let worker: Worker = self as any;
worker.onmessage = HeatTileGeneratorWebWorker.onmessage;
HeatTileGeneratorWebWorker.postmessage = postMessageFunction;
HeatTileGeneratorWebWorker.start();
function postMessageFunction() {
self.postMessage.apply(self, Array.prototype.slice.call(arguments));
}
export default {} as typeof Worker & (new () => Worker);
Dependencies
import { ModuleManager } from 'igniteui-webcomponents-core';
import { IgcGeographicMapComponent } from 'igniteui-webcomponents-maps';
import { IgcGeographicTileSeriesComponent, IgcTileGeneratorMapImagery } from 'igniteui-webcomponents-maps';
import { IgcHeatTileGenerator, IgcShapeDataSource } from 'igniteui-webcomponents-core';
import { IgcGeographicMapModule } from 'igniteui-webcomponents-maps';
import { IgcDataChartInteractivityModule } from 'igniteui-webcomponents-charts';
// ...
ModuleManager.register(
IgcGeographicMapModule,
IgcDataChartInteractivityModule
);
Creating Heatmap
The following code snippet shows how to display a population based heat-map in the Ignite UI for Web Components map component:
<igc-geographic-map
id="map"
height="100%"
width="100%"
zoomable="true">
</igc-geographic-map>
import { IgcGeographicTileSeriesComponent, IgcTileGeneratorMapImagery } from 'igniteui-webcomponents-maps';
import { IgcHeatTileGenerator, IgcShapeDataSource } from 'igniteui-webcomponents-core';
private map: IgcGeographicMapComponent
// ...
var map = this.map;
map.zoomToGeographic({ left: -134.5, top: 16.0, width: 70.0, height: 37.0 });
var root = "https://static.infragistics.com/xplatform/shapes/";
var sds = new IgcShapeDataSource();
sds.importCompleted = () => {
var latitudes: number[] = [];
var longitudes: number[] = [];
var populations: number[] = [];
// parsing shapefile data and creating geographic locations
var pointData = sds.getPointData();
for (var i = 0; i < pointData.length; i++) {
var record = pointData[i];
for (var j = 0; j < record.points.length; j++) {
var pointsList = record.points[j];
for (var k = 0; k < pointsList.length; k++) {
latitudes.push(pointsList[k].y);
longitudes.push(pointsList[k].x);
}
}
// using field/column names from .DBF file
var value = record.fieldValues["POP_2010"];
populations.push(value >= 0 ? value : 0);
}
// the heat map's tiles are generated from the three parallel arrays: where each
// reading is, and how large it is
// generating heat map imagery tiles
var gen = new IgcHeatTileGenerator();
gen.xValues = longitudes;
gen.yValues = latitudes;
gen.values = populations;
gen.blurRadius = 6;
gen.maxBlurRadius = 20;
gen.useBlurRadiusAdjustedForZoom = true;
gen.minimumColor = "rgba(100, 255, 0, 0.5)";
gen.maximumColor = "rgba(255, 255, 0, 0.5)";
gen.useGlobalMinMax = true;
gen.useGlobalMinMaxAdjustedForZoom = true;
gen.useLogarithmicScale = true;
gen.scaleColors = [
"rgba(0, 0, 255, .251)",
"rgba(0, 255, 255, .3765)",
"rgba(50, 205, 50, .2675)",
"rgba(255, 255, 0, .7059)",
"rgba(255, 0, 0, .7843)"
];
// Generating the tiles on a worker keeps them off the thread the map draws on, which
// is worth doing for a heat map of any size. Wiring one up is not the same on every
// bundler, so the topic shows it separately — and workers are turned off here to
// match, since the generator asks for one by default and throws when neither a script
// path nor an instance was given.
gen.useWebWorkers = false;
var tileImagery = new IgcTileGeneratorMapImagery();
tileImagery.tileGenerator = gen;
// generating heat map series
var series = new IgcGeographicTileSeriesComponent();
series.tileImagery = tileImagery;
// adding the heat map series to the map
map.series.add(series);
};
sds.shapefileSource = root + "AmericanCities.shp";
sds.databaseSource = root + "AmericanCities.dbf";
sds.dataBind();