Chevron DownAPI Reference
S2Layer
i

Explore S2Layer's API
Sample data


_normalize: true
autoHighlight: false
elevationScale: 1000
extruded: true
filled: true
getLineColor: #000000
getLineWidth: 1
highlightColor: #000080
lineJointRounded: false
lineMiterLimit: 4
lineWidthMaxPixels: 9007199254740991
lineWidthMinPixels: 0
lineWidthScale: 1
material: true
opacity: 1
pickable: true
stroked: true
visible: true
wireframe: false
wrapLongitude: false
View Code ↗

lighting

S2Layer

The S2Layer renders filled and/or stroked polygons, with geometry automatically calculated based on an S2 token (geospatial index). It uses Uses the s2-geometry library for S2 polygon calculations.

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