|
| 1 | +# GlobalGridLayer |
| 2 | + |
| 3 | +<!-- |
| 4 | +import {GlobalGridLayerDemo} from '@site/src/doc-demos/geo-layers'; |
| 5 | +<GlobalGridLayerDemo /> |
| 6 | +--> |
| 7 | + |
| 8 | +The `GlobalGridLayer` renders filled and/or stroked polygons based on the specified DGGS geospatial indexing system. |
| 9 | + |
| 10 | +`GlobalGridLayer` is a [CompositeLayer](https://deck.gl/docs/api-reference/core/composite-layer). |
| 11 | + |
| 12 | + |
| 13 | +import Tabs from '@theme/Tabs'; |
| 14 | +import TabItem from '@theme/TabItem'; |
| 15 | + |
| 16 | +<Tabs groupId="language"> |
| 17 | + <TabItem value="js" label="JavaScript"> |
| 18 | + |
| 19 | +```js |
| 20 | +import {Deck} from '@deck.gl/core'; |
| 21 | +import {GlobalGridLayer, A5Decoder} from '@deck.gl/geo-layers'; |
| 22 | + |
| 23 | +const layer = new SGGSLayer({ |
| 24 | + id: 'GlobalGridLayer', |
| 25 | + data: 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/sf.bike.parking.a5.json', |
| 26 | + globalGrid: A5Decoder, |
| 27 | + |
| 28 | + extruded: true, |
| 29 | + getPentagon: f => f.pentagon, |
| 30 | + getFillColor: f => { |
| 31 | + const value = f.count / 211; |
| 32 | + return [(1 - value) * 235, 255 - 85 * value, 255 - 170 * value]; |
| 33 | + }, |
| 34 | + getElevation: f => f.count, |
| 35 | + elevationScale: 10, |
| 36 | + pickable: true |
| 37 | +}); |
| 38 | + |
| 39 | +new Deck({ |
| 40 | + initialViewState: { |
| 41 | + longitude: -122.4, |
| 42 | + latitude: 37.74, |
| 43 | + zoom: 11 |
| 44 | + }, |
| 45 | + controller: true, |
| 46 | + getTooltip: ({object}) => object && `${object.pentagon} count: ${object.count}`, |
| 47 | + layers: [layer] |
| 48 | +}); |
| 49 | +``` |
| 50 | + |
| 51 | + </TabItem> |
| 52 | + <TabItem value="ts" label="TypeScript"> |
| 53 | + |
| 54 | +```ts |
| 55 | +import {Deck, PickingInfo} from '@deck.gl/core'; |
| 56 | +import {GlobalGridLayer} from '@deck.gl/geo-layers'; |
| 57 | + |
| 58 | +type DataType = { |
| 59 | + pentagon: string; |
| 60 | + count: number; |
| 61 | +}; |
| 62 | + |
| 63 | +const layer = new GlobalGridLayer<DataType>({ |
| 64 | + id: 'GlobalGridLayer', |
| 65 | + data: 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/sf.bike.parking.a5.json', |
| 66 | + globalGrid: A5Decoder, |
| 67 | + |
| 68 | + extruded: true, |
| 69 | + getPentagon: (f: DataType) => f.pentagon, |
| 70 | + getFillColor: (f: DataType) => { |
| 71 | + const value = f.count / 211; |
| 72 | + return [(1 - value) * 235, 255 - 85 * value, 255 - 170 * value]; |
| 73 | + }, |
| 74 | + getElevation: (f: DataType) => f.count, |
| 75 | + elevationScale: 10, |
| 76 | + pickable: true |
| 77 | +}); |
| 78 | + |
| 79 | +new Deck({ |
| 80 | + initialViewState: { |
| 81 | + longitude: -122.4, |
| 82 | + latitude: 37.74, |
| 83 | + zoom: 11 |
| 84 | + }, |
| 85 | + controller: true, |
| 86 | + getTooltip: ({object}: PickingInfo<DataType>) => object && `${object.pentagon} count: ${object.count}`, |
| 87 | + layers: [layer] |
| 88 | +}); |
| 89 | +``` |
| 90 | + |
| 91 | + </TabItem> |
| 92 | + <TabItem value="react" label="React"> |
| 93 | + |
| 94 | +```tsx |
| 95 | +import React from 'react'; |
| 96 | +import {DeckGL} from '@deck.gl/react'; |
| 97 | +import {GlobalGridLayer} from '@deck.gl/geo-layers'; |
| 98 | +import type {PickingInfo} from '@deck.gl/core'; |
| 99 | + |
| 100 | +type DataType = { |
| 101 | + pentagon: string; |
| 102 | + count: number; |
| 103 | +}; |
| 104 | + |
| 105 | +function App() { |
| 106 | + const layer = new GlobalGridLayer<DataType>({ |
| 107 | + id: 'GlobalGridLayer', |
| 108 | + data: 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/sf.bike.parking.a5.json', |
| 109 | + globalGrid: A5Decoder, |
| 110 | + |
| 111 | + extruded: true, |
| 112 | + getPentagon: (f: DataType) => f.pentagon, |
| 113 | + getFillColor: (f: DataType) => { |
| 114 | + const value = f.count / 211; |
| 115 | + return [(1 - value) * 235, 255 - 85 * value, 255 - 170 * value]; |
| 116 | + }, |
| 117 | + getElevation: (f: DataType) => f.count, |
| 118 | + elevationScale: 10, |
| 119 | + pickable: true |
| 120 | + }); |
| 121 | + |
| 122 | + return <DeckGL |
| 123 | + initialViewState={{ |
| 124 | + longitude: -122.4, |
| 125 | + latitude: 37.74, |
| 126 | + zoom: 11 |
| 127 | + }} |
| 128 | + controller |
| 129 | + getTooltip={({object}: PickingInfo<DataType>) => object && `${object.pentagon} count: ${object.count}`} |
| 130 | + layers={[layer]} |
| 131 | + />; |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | + </TabItem> |
| 136 | +</Tabs> |
| 137 | + |
| 138 | + |
| 139 | +## Installation |
| 140 | + |
| 141 | +To install the dependencies from NPM: |
| 142 | + |
| 143 | +```bash |
| 144 | +npm install deck.gl |
| 145 | +# or |
| 146 | +npm install @deck.gl/core @deck.gl/layers @deck.gl/geo-layers |
| 147 | +``` |
| 148 | + |
| 149 | +```ts |
| 150 | +import {GlobalGridLayer} from '@deck.gl/geo-layers'; |
| 151 | +import type {GlobalGridLayerProps} from '@deck.gl/geo-layers'; |
| 152 | + |
| 153 | +new GlobalGridLayer<DataT>(...props: GlobalGridLayerProps<DataT>[]); |
| 154 | +``` |
| 155 | + |
| 156 | +To use pre-bundled scripts: |
| 157 | + |
| 158 | +```html |
| 159 | +<script src="https://unpkg.com/deck.gl@^9.0.0/dist.min.js"></script> |
| 160 | +<!-- or --> |
| 161 | +<script src="https://unpkg.com/@deck.gl/core@^9.0.0/dist.min.js"></script> |
| 162 | +<script src="https://unpkg.com/@deck.gl/layers@^9.0.0/dist.min.js"></script> |
| 163 | +<script src="https://unpkg.com/@deck.gl/geo-layers@^9.0.0/dist.min.js"></script> |
| 164 | +``` |
| 165 | + |
| 166 | +```js |
| 167 | +new deck.GlobalGridLayer({}); |
| 168 | +``` |
| 169 | + |
| 170 | + |
| 171 | +## Properties |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | +Inherits from all [Base Layer](https://deck.gl/docs/api-reference/core/layer), [CompositeLayer](https://deck.gl/docs/api-reference/core/composite-layer), and [PolygonLayer](https://deck.gl/docs/api-reference/layers/polygon-layer) properties, plus the following: |
| 177 | + |
| 178 | +### Data Accessors |
| 179 | + |
| 180 | +#### `getPentagon` (Accessor<bigint | string>]  {#getpentagon} |
| 181 | + |
| 182 | +Called for each data object to retrieve the identifier of the DGGS cell id. May return one of the following: |
| 183 | + |
| 184 | +- A 64-bit [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) identifier for the cell. |
| 185 | +- A string token representing the DGGS-specific string encoding of the 64-bit integer |
| 186 | + |
| 187 | + |
| 188 | +* default: `object => object.pentagon` |
| 189 | + |
| 190 | + |
| 191 | +## Sub Layers |
| 192 | + |
| 193 | +The `GlobalGridLayer` renders the following sublayers: |
| 194 | + |
| 195 | +* `cell` - a [PolygonLayer](https://deck.gl/docs/api-reference/layers/polygon-layer) rendering the DGGS cells. |
| 196 | + |
| 197 | + |
| 198 | +## Source |
| 199 | + |
| 200 | +[modules/geo-layers/src/global-grid-layer](https://github.com/visgl/deck.gl/tree/master/modules/geo-layers/src/global-grid-layer) |
0 commit comments