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