Skip to content

Commit 664415d

Browse files
authored
feat: Add a5 layer (#162)
1 parent 5483ac8 commit 664415d

File tree

3 files changed

+163
-1
lines changed

3 files changed

+163
-1
lines changed

packages/deck.gl-layers/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
"dist/",
3535
"src/"
3636
],
37-
"repository": "https://github.com/geoarrow/deck.gl-layers",
37+
"repository": {
38+
"type": "git",
39+
"url": "git+https://github.com/geoarrow/deck.gl-layers.git"
40+
},
3841
"author": "Kyle Barron <kylebarron2@gmail.com>",
3942
"license": "MIT",
4043
"peerDependencies": {

packages/deck.gl-layers/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// SPDX-License-Identifier: MIT
33
// Copyright (c) vis.gl contributors
44

5+
export type { GeoArrowA5LayerProps } from "./layers/a5-layer.js";
6+
export { GeoArrowA5Layer } from "./layers/a5-layer.js";
7+
58
export type { GeoArrowArcLayerProps } from "./layers/arc-layer.js";
69
export { GeoArrowArcLayer } from "./layers/arc-layer.js";
710

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// deck.gl-community
2+
// SPDX-License-Identifier: MIT
3+
// Copyright (c) vis.gl contributors
4+
5+
import {
6+
CompositeLayer,
7+
CompositeLayerProps,
8+
DefaultProps,
9+
GetPickingInfoParams,
10+
Layer,
11+
LayersList,
12+
} from "@deck.gl/core";
13+
import type { A5LayerProps } from "@deck.gl/geo-layers";
14+
import { A5Layer } from "@deck.gl/geo-layers";
15+
import * as arrow from "apache-arrow";
16+
17+
import { ColorAccessor, FloatAccessor, GeoArrowPickingInfo } from "../types";
18+
import { assignAccessor, extractAccessorsFromProps } from "../utils/utils";
19+
import { GeoArrowExtraPickingProps, getPickingInfo } from "../utils/picking";
20+
import { validateAccessors } from "../utils/validate";
21+
22+
/** All properties supported by GeoArrowA5Layer */
23+
export type GeoArrowA5LayerProps = Omit<
24+
A5LayerProps,
25+
| "data"
26+
| "getPentagon"
27+
| "getFillColor"
28+
| "getLineColor"
29+
| "getLineWidth"
30+
| "getElevation"
31+
> &
32+
_GeoArrowA5LayerProps &
33+
// Omit<GeoArrowPolygonLayerProps, "getPolygon"> &
34+
CompositeLayerProps;
35+
36+
/** Props added by the GeoArrowA5Layer */
37+
type _GeoArrowA5LayerProps = {
38+
data: arrow.RecordBatch;
39+
40+
/**
41+
* Called for each data object to retrieve the quadkey string identifier.
42+
*/
43+
getPentagon: arrow.Data<arrow.Utf8 | arrow.Uint64>;
44+
45+
/** Fill color accessor.
46+
* @default [0, 0, 0, 255]
47+
*/
48+
getFillColor?: ColorAccessor;
49+
50+
/** Stroke color accessor.
51+
* @default [0, 0, 0, 255]
52+
*/
53+
getLineColor?: ColorAccessor;
54+
55+
/**
56+
* Line width value of accessor.
57+
* @default 1
58+
*/
59+
getLineWidth?: FloatAccessor;
60+
61+
/**
62+
* Elevation value of accessor.
63+
*
64+
* Only used if `extruded: true`.
65+
*
66+
* @default 1000
67+
*/
68+
getElevation?: FloatAccessor;
69+
70+
/**
71+
* If `true`, validate the arrays provided (e.g. chunk lengths)
72+
* @default true
73+
*/
74+
_validate?: boolean;
75+
};
76+
77+
// Remove data from the upstream default props
78+
const {
79+
data: _data,
80+
getPentagon: _getPentagon,
81+
..._defaultProps
82+
} = A5Layer.defaultProps;
83+
84+
// Default props added by us
85+
const ourDefaultProps = {
86+
_validate: true,
87+
};
88+
89+
// @ts-expect-error getFillColor
90+
const defaultProps: DefaultProps<GeoArrowA5LayerProps> = {
91+
// ..._polygonDefaultProps,
92+
..._defaultProps,
93+
...ourDefaultProps,
94+
};
95+
96+
export class GeoArrowA5Layer<ExtraProps extends {} = {}> extends CompositeLayer<
97+
GeoArrowA5LayerProps & ExtraProps
98+
> {
99+
static defaultProps = defaultProps;
100+
static layerName = "GeoArrowA5Layer";
101+
102+
getPickingInfo(
103+
params: GetPickingInfoParams & {
104+
sourceLayer: { props: GeoArrowExtraPickingProps };
105+
},
106+
): GeoArrowPickingInfo {
107+
return getPickingInfo(params, this.props.data);
108+
}
109+
110+
renderLayers(): Layer<{}> | LayersList | null {
111+
return this._renderLayer();
112+
}
113+
114+
_renderLayer(): Layer<{}> | LayersList | null {
115+
const { data: batch, getPentagon } = this.props;
116+
117+
if (this.props._validate) {
118+
validateAccessors(this.props, batch);
119+
}
120+
121+
// Exclude manually-set accessors
122+
const [accessors, otherProps] = extractAccessorsFromProps(this.props, [
123+
"getPentagon",
124+
]);
125+
const pentagonVector = new arrow.Vector([getPentagon]);
126+
127+
const props: A5LayerProps = {
128+
// Note: because this is a composite layer and not doing the rendering
129+
// itself, we still have to pass in our defaultProps
130+
...ourDefaultProps,
131+
...otherProps,
132+
133+
id: `${this.props.id}-geoarrow-a5`,
134+
135+
data: {
136+
// @ts-expect-error passed through to enable use by function accessors
137+
data: batch,
138+
length: batch.numRows,
139+
},
140+
// We must load back to pure JS strings / bigint
141+
getPentagon: (_, objectInfo) => {
142+
return pentagonVector.get(objectInfo.index)!;
143+
},
144+
};
145+
146+
for (const [propName, propInput] of Object.entries(accessors)) {
147+
assignAccessor({
148+
props,
149+
propName,
150+
propInput,
151+
});
152+
}
153+
154+
return new A5Layer(this.getSubLayerProps(props));
155+
}
156+
}

0 commit comments

Comments
 (0)