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