Skip to content

Commit a4467a1

Browse files
authored
improved type for picking info (#50)
1 parent b604199 commit a4467a1

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

src/path-layer.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,13 @@ export class GeoArrowPathLayer<
165165
const offsets: number[] = table._offsets;
166166
const currentBatchOffset = offsets[recordBatchIdx];
167167

168-
info.object = row;
169168
// Update index to be _global_ index, not within the specific record batch
170169
index += currentBatchOffset;
171-
info.index = index;
172-
return info;
170+
return {
171+
...info,
172+
index,
173+
object: row,
174+
};
173175
}
174176

175177
renderLayers(): Layer<{}> | LayersList | null {

src/scatterplot-layer.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
validatePointType,
2727
validateVectorAccessors,
2828
} from "./utils.js";
29-
import { MultiPointVector, PointVector } from "./types.js";
29+
import { GeoArrowPickingInfo, MultiPointVector, PointVector } from "./types.js";
3030
import { EXTENSION_NAME } from "./constants.js";
3131

3232
const DEFAULT_COLOR: [number, number, number, number] = [0, 0, 0, 255];
@@ -171,7 +171,10 @@ export class GeoArrowScatterplotLayer<
171171
static defaultProps = defaultProps;
172172
static layerName = "GeoArrowScatterplotLayer";
173173

174-
getPickingInfo({ info, sourceLayer }: GetPickingInfoParams): PickingInfo {
174+
getPickingInfo({
175+
info,
176+
sourceLayer,
177+
}: GetPickingInfoParams): GeoArrowPickingInfo {
175178
const { data: table } = this.props;
176179

177180
// Geometry index as rendered
@@ -195,11 +198,13 @@ export class GeoArrowScatterplotLayer<
195198
const offsets: number[] = table._offsets;
196199
const currentBatchOffset = offsets[recordBatchIdx];
197200

198-
info.object = row;
199201
// Update index to be _global_ index, not within the specific record batch
200202
index += currentBatchOffset;
201-
info.index = index;
202-
return info;
203+
return {
204+
...info,
205+
index,
206+
object: row,
207+
};
203208
}
204209

205210
renderLayers(): Layer<{}> | LayersList | null {

src/solid-polygon-layer.ts

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ import {
3030
validatePolygonType,
3131
validateVectorAccessors,
3232
} from "./utils.js";
33-
import { MultiPolygonVector, PolygonVector } from "./types.js";
33+
import {
34+
GeoArrowPickingInfo,
35+
MultiPolygonVector,
36+
PolygonVector,
37+
} from "./types.js";
3438
import { EXTENSION_NAME } from "./constants.js";
3539

3640
const DEFAULT_COLOR: [number, number, number, number] = [0, 0, 0, 255];
@@ -142,7 +146,10 @@ export class GeoArrowSolidPolygonLayer<
142146
static defaultProps = defaultProps;
143147
static layerName = "GeoArrowSolidPolygonLayer";
144148

145-
getPickingInfo({ info, sourceLayer }: GetPickingInfoParams): PickingInfo {
149+
getPickingInfo({
150+
info,
151+
sourceLayer,
152+
}: GetPickingInfoParams): GeoArrowPickingInfo {
146153
const { data: table } = this.props;
147154

148155
// Geometry index as rendered
@@ -166,11 +173,13 @@ export class GeoArrowSolidPolygonLayer<
166173
const offsets: number[] = table._offsets;
167174
const currentBatchOffset = offsets[recordBatchIdx];
168175

169-
info.object = row;
170176
// Update index to be _global_ index, not within the specific record batch
171177
index += currentBatchOffset;
172-
info.index = index;
173-
return info;
178+
return {
179+
...info,
180+
index,
181+
object: row,
182+
};
174183
}
175184

176185
renderLayers(): Layer<{}> | LayersList | null {
@@ -390,10 +399,19 @@ export class GeoArrowSolidPolygonLayer<
390399
startIndices: resolvedPolygonToCoordOffsets,
391400
attributes: {
392401
getPolygon: { value: flatCoordinateArray, size: nDim },
402+
instancePickingColors: {
403+
value: encodePickingColors(
404+
resolvedMultiPolygonToCoordOffsets,
405+
this.encodePickingColor
406+
),
407+
size: 3,
408+
},
393409
},
394410
},
395411
};
396412

413+
console.log(resolvedMultiPolygonToCoordOffsets);
414+
397415
assignAccessor({
398416
props,
399417
propName: "getElevation",
@@ -423,3 +441,29 @@ export class GeoArrowSolidPolygonLayer<
423441
return layers;
424442
}
425443
}
444+
445+
function encodePickingColors(
446+
geomToCoordOffsets: Int32Array,
447+
encodePickingColor: (id: number, result: number[]) => void
448+
): Uint8ClampedArray {
449+
const largestOffset = geomToCoordOffsets[geomToCoordOffsets.length - 1];
450+
const pickingColors = new Uint8ClampedArray(largestOffset);
451+
452+
const pickingColor = [];
453+
for (let arrayIdx = 0; arrayIdx < geomToCoordOffsets.length - 1; arrayIdx++) {
454+
const thisOffset = geomToCoordOffsets[arrayIdx];
455+
const nextOffset = geomToCoordOffsets[arrayIdx + 1];
456+
457+
// Note: we encode the picking color once per _feature_, but then assign it
458+
// to the color array once per _vertex_
459+
encodePickingColor(arrayIdx, pickingColor);
460+
for (let offset = thisOffset; offset < nextOffset; offset++) {
461+
pickingColors[offset * 3] = pickingColor[0];
462+
pickingColors[offset * 3 + 1] = pickingColor[1];
463+
pickingColors[offset * 3 + 2] = pickingColor[2];
464+
}
465+
}
466+
467+
console.log(pickingColors);
468+
return pickingColors;
469+
}

src/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { PickingInfo } from "@deck.gl/core/typed";
12
import * as arrow from "apache-arrow";
23

3-
export type InterleavedCoord = arrow.FixedSizeList<arrow.Float>;
4+
export type InterleavedCoord = arrow.FixedSizeList<arrow.Float64>;
45
export type SeparatedCoord = arrow.Struct<{
56
x: arrow.Float;
67
y: arrow.Float;
@@ -27,3 +28,7 @@ export type PolygonData = arrow.Data<Polygon>;
2728
export type MultiPointData = arrow.Data<MultiPoint>;
2829
export type MultiLineStringData = arrow.Data<MultiLineString>;
2930
export type MultiPolygonData = arrow.Data<MultiPolygon>;
31+
32+
export type GeoArrowPickingInfo = PickingInfo & {
33+
object: arrow.StructRowProxy
34+
}

0 commit comments

Comments
 (0)