Skip to main content

S2Layer

The S2Layer renders filled and/or stroked polygons based on the S2 geospatial indexing system.

S2Layer is a CompositeLayer.

import DeckGL from '@deck.gl/react';
import {S2Layer} from '@deck.gl/geo-layers';

function App({data, viewState}) {
/**
* Data format:
* [
* {
* // S2 Cell in SF Bay Area
* token: "80858004",
* value: 0.5979242952642347
* },
* {
* token: "8085800c",
* value: 0.5446256069712141
* },
* ...
* ]
*/
const layer = new S2Layer({
id: 's2-layer',
data,
pickable: true,
wireframe: false,
filled: true,
extruded: true,
elevationScale: 1000,
getS2Token: d => d.token,
getFillColor: d => [d.value * 255, (1 - d.value) * 255, (1 - d.value) * 128],
getElevation: d => d.value
});

return <DeckGL viewState={viewState}
layers={[layer]}
getTooltip={({object}) => object && `${object.token} value: ${object.value}`} />;
}

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 {S2Layer} from '@deck.gl/geo-layers';
new S2Layer({});

To use pre-bundled scripts:

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

Properties

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

Data Accessors

getS2Token (Function, optional) transition-enabled

Called for each data object to retrieve the identifier of the S2 cell. May return one of the following:

  • A string that is the cell's hex token
  • A string that is the Hilbert quad key (containing /)
  • A Long object that is the cell's id

Check S2 Cell for more details.

  • default: object => object.token

Sub Layers

The S2Layer renders the following sublayers:

Source

modules/geo-layers/src/s2-layer