Skip to content

Commit

Permalink
carto: RasterLayer fix perf issue caused by spurious data changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zbigg committed Oct 18, 2024
1 parent 065816e commit 90d2b08
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/carto/src/layers/raster-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ type _RasterLayerProps = {
tileIndex: bigint;
};

type RasterColumnLayerData = {
data: Raster;
length: number;
};

function wrappedDataComparator(oldData: RasterColumnLayerData, newData: RasterColumnLayerData) {
return oldData.data === newData.data && oldData.length === newData.length;
}

// Adapter layer around RasterColumnLayer that converts data & accessors into correct format
export default class RasterLayer<DataT = any, ExtraProps = {}> extends CompositeLayer<
Required<RasterLayerProps<DataT>> & ExtraProps
Expand All @@ -91,6 +100,7 @@ export default class RasterLayer<DataT = any, ExtraProps = {}> extends Composite
state!: {
highlightedObjectIndex: number;
highlightColor: number[];
dataWrapper?: {data: Raster; length: number};
};

renderLayers(): Layer | null | LayersList {
Expand Down Expand Up @@ -130,6 +140,7 @@ export default class RasterLayer<DataT = any, ExtraProps = {}> extends Composite
data, // Pass through data for getSubLayerAccessor()
length: blockSize * blockSize
},
dataComparator: wrappedDataComparator,
offset,
lineWidthScale, // Re-use widthScale prop to pass cell scale,
highlightedObjectIndex,
Expand Down

0 comments on commit 90d2b08

Please sign in to comment.