Skip to main content

H3ClusterLayer

The H3ClusterLayer renders regions represented by hexagon sets from the H3 geospatial indexing system.

H3ClusterLayer is a CompositeLayer.

import {Deck} from '@deck.gl/core';
import {H3ClusterLayer} from '@deck.gl/geo-layers';

const layer = new H3ClusterLayer({
id: 'H3ClusterLayer',
data: 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/sf.h3clusters.json',

stroked: true,
getHexagons: d => d.hexIds,
getFillColor: d => [255, (1 - d.mean / 500) * 255, 0],
getLineColor: [255, 255, 255],
lineWidthMinPixels: 2,
pickable: true
});

new Deck({
initialViewState: {
longitude: -122.4,
latitude: 37.74,
zoom: 11
},
controller: true,
getTooltip: ({object}) => object && `density: ${object.mean}`,
layers: [layer]
});

Installation

To install the dependencies from NPM:

npm install deck.gl
# or
npm install @deck.gl/core @deck.gl/layers @deck.gl/geo-layers
import {H3ClusterLayer} from '@deck.gl/geo-layers';
import type {H3ClusterLayerProps} from '@deck.gl/geo-layers';

new H3ClusterLayer<DataT>(...props: H3ClusterLayerProps<DataT>[]);

To use pre-bundled scripts:

<script src="https://unpkg.com/h3-js@^4.0.0"></script>
<script src="https://unpkg.com/deck.gl@^9.0.0/dist.min.js"></script>
<!-- or -->
<script src="https://unpkg.com/@deck.gl/core@^9.0.0/dist.min.js"></script>
<script src="https://unpkg.com/@deck.gl/layers@^9.0.0/dist.min.js"></script>
<script src="https://unpkg.com/@deck.gl/geo-layers@^9.0.0/dist.min.js"></script>
new deck.H3ClusterLayer({});

Note that h3-js must be included before deck.gl.

Properties

Inherits from all Base Layer, CompositeLayer, and PolygonLayer properties, plus the following:

Data Accessors

getHexagons (Accessor<string[]>, optional)

Method called to retrieve the hexagon cluster from each object, as an array of H3 hexagon indices. These hexagons are joined into polygons that represent the geospatial outline of the cluster.

Sub Layers

The H3ClusterLayer renders the following sublayers:

Source

modules/geo-layers/src/h3-layers/h3-cluster-layer.ts