Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crash when trying to getError on static heatmap layer #2779

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ 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)
this.state = {
error: '',
colorDomain: [],
colorRanges: this._getColorRanges(),
scales: [],
Expand All @@ -75,7 +77,7 @@ export class FourwingsHeatmapStaticLayer extends CompositeLayer<FourwingsHeatmap
}

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

_getColorRanges = () => {
Expand All @@ -84,6 +86,15 @@ export class FourwingsHeatmapStaticLayer extends CompositeLayer<FourwingsHeatmap
)
}

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

getError(): string {
return this.state.error
}
_calculateColorDomain = () => {
// TODO use to get the real bin value considering the NO_DATA_VALUE and negatives
// NO_DATA_VALUE = 0
Expand Down Expand Up @@ -157,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 @@ -193,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 @@ -211,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 @@ -300,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
Loading