Skip to content

Commit

Permalink
Fix H3ClusterLayer accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Apr 3, 2023
1 parent 68ce09b commit f753f41
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
9 changes: 8 additions & 1 deletion modules/geo-layers/src/h3-layers/h3-cluster-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ export default class H3ClusterLayer<DataT = any, ExtraProps extends {} = {}> ext
}

indexToBounds(): Partial<GeoCellLayer['props']> {
const {getElevation, getFillColor, getLineColor, getLineWidth} = this.props;

return {
data: this.state.polygons,
getPolygon: d => d.polygon
getPolygon: d => d.polygon,

getElevation: this.getSubLayerAccessor(getElevation),
getFillColor: this.getSubLayerAccessor(getFillColor),
getLineColor: this.getSubLayerAccessor(getLineColor),
getLineWidth: this.getSubLayerAccessor(getLineWidth)
};
}
}
28 changes: 28 additions & 0 deletions test/modules/geo-layers/h3-layers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,31 @@ test('H3ClusterLayer', t => {

t.end();
});

/** Verify that accessors are properly wrapped to access the source object */
test('H3ClusterLayer#accessor', t => {
const elevations = [];

testLayer({
Layer: H3ClusterLayer,
onError: t.notOk,
testCases: [
{
props: {
data,
getHexagons: d => d.hexagons,
getElevation: d => {
const elevation = d.size;
elevations.push(elevation);
return elevation;
}
},
onAfterUpdate: () => {
t.ok(elevations.every(Number.isFinite), 'Elevations populated');
}
}
]
});

t.end();
});

0 comments on commit f753f41

Please sign in to comment.