Skip to content

Commit

Permalink
fourwings static layer state typing and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
j8seangel committed Aug 13, 2024
1 parent 4c9d5a8 commit 2322fb5
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const defaultProps: DefaultProps<FourwingsHeatmapStaticLayerProps> = {
export class FourwingsHeatmapStaticLayer extends CompositeLayer<FourwingsHeatmapTileLayerProps> {
static layerName = 'FourwingsHeatmapStaticLayer'
static defaultProps = defaultProps
state!: Omit<FourwingsTileLayerState, 'tilesCache'>

initializeState(context: LayerContext) {
super.initializeState(context)
Expand All @@ -76,16 +77,23 @@ export class FourwingsHeatmapStaticLayer extends CompositeLayer<FourwingsHeatmap
}

_getState() {
return this.state as FourwingsTileLayerState
return this.state
}

_getColorRanges = () => {
return this.props.sublayers.map(({ colorRamp }) =>
getColorRamp({ rampId: colorRamp as ColorRampId })
)
}

_onLayerError = (error: Error) => {
console.warn(error.message)
this.setState({ error: error.message })
return true
}

getError(): string {
return (this.state as FourwingsTileLayerState).error
return this.state.error
}
_calculateColorDomain = () => {
// TODO use to get the real bin value considering the NO_DATA_VALUE and negatives
Expand Down Expand Up @@ -160,7 +168,7 @@ export class FourwingsHeatmapStaticLayer extends CompositeLayer<FourwingsHeatmap
}

getFillColor = (feature: Feature<Geometry, FourwingsStaticFeatureProperties>) => {
const { scales } = this.state as FourwingsTileLayerState
const { scales } = this.state
const scale = scales?.[0]
if (
!scale ||
Expand Down Expand Up @@ -196,7 +204,7 @@ export class FourwingsHeatmapStaticLayer extends CompositeLayer<FourwingsHeatmap
renderLayers(): Layer<{}> | LayersList {
const { tilesUrl, sublayers, resolution, minVisibleValue, maxVisibleValue, maxZoom } =
this.props
const { colorDomain, colorRanges } = this.state as FourwingsTileLayerState
const { colorDomain, colorRanges } = this.state
const { zoom } = this.context.viewport
const params = {
datasets: sublayers.flatMap((sublayer) => sublayer.datasets),
Expand All @@ -214,6 +222,7 @@ export class FourwingsHeatmapStaticLayer extends CompositeLayer<FourwingsHeatmap
loaders: [GFWMVTLoader],
zoomOffset: getZoomOffsetByResolution(resolution!, zoom),
onTileLoad: this._onTileLoad,
onTileError: this._onLayerError,
onViewportLoad: this._onViewportLoad,
getPolygonOffset: (params) => getLayerGroupOffset(LayerGroup.HeatmapStatic, params),
getFillColor: this.getFillColor,
Expand Down Expand Up @@ -303,11 +312,11 @@ export class FourwingsHeatmapStaticLayer extends CompositeLayer<FourwingsHeatmap
}

getColorDomain = () => {
return (this.state as FourwingsTileLayerState).colorDomain
return this.state.colorDomain
}

getColorRange = () => {
return (this.state as FourwingsTileLayerState).colorRanges
return this.state.colorRanges
}

getColorScale = () => {
Expand Down

0 comments on commit 2322fb5

Please sign in to comment.