From 7c6140cef9a5161563a8c559f5aea870eb08ee28 Mon Sep 17 00:00:00 2001 From: Xiaoji Chen Date: Wed, 5 Apr 2023 08:02:04 -0700 Subject: [PATCH] Fix H3ClusterLayer accessors (#7812) --- .../src/h3-layers/h3-cluster-layer.ts | 9 +++++- test/modules/geo-layers/h3-layers.spec.js | 28 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/modules/geo-layers/src/h3-layers/h3-cluster-layer.ts b/modules/geo-layers/src/h3-layers/h3-cluster-layer.ts index a478fcf4511..98d7206a3a6 100644 --- a/modules/geo-layers/src/h3-layers/h3-cluster-layer.ts +++ b/modules/geo-layers/src/h3-layers/h3-cluster-layer.ts @@ -57,9 +57,16 @@ export default class H3ClusterLayer ext } indexToBounds(): Partial { + 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) }; } } diff --git a/test/modules/geo-layers/h3-layers.spec.js b/test/modules/geo-layers/h3-layers.spec.js index 96e933ae8ee..0477d52b9cc 100644 --- a/test/modules/geo-layers/h3-layers.spec.js +++ b/test/modules/geo-layers/h3-layers.spec.js @@ -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(); +});