diff --git a/src/main/scala/org/globalforestwatch/summarystats/gfwpro_dashboard/GfwProDashboardGridSources.scala b/src/main/scala/org/globalforestwatch/summarystats/gfwpro_dashboard/GfwProDashboardGridSources.scala index 13458e53..b7ecbb83 100644 --- a/src/main/scala/org/globalforestwatch/summarystats/gfwpro_dashboard/GfwProDashboardGridSources.scala +++ b/src/main/scala/org/globalforestwatch/summarystats/gfwpro_dashboard/GfwProDashboardGridSources.scala @@ -22,33 +22,10 @@ case class GfwProDashboardGridSources(gridTile: GridTile, kwargs: Map[String, An windowLayout: LayoutDefinition ): Either[Throwable, Raster[GfwProDashboardTile]] = { - for { - // Integrated alerts are Optional Tiles, but we keep it this way to avoid signature changes - integratedAlertsTile <- Either - .catchNonFatal(integratedAlerts.fetchWindow(windowKey, windowLayout)) - .right - tcd2000Tile <- Either - .catchNonFatal(treeCoverDensity2000.fetchWindow(windowKey, windowLayout)) - .right - sbtnNaturalForestTile <- Either - .catchNonFatal(sbtnNaturalForest.fetchWindow(windowKey, windowLayout)) - .right - jrcForestCoverTile <- Either - .catchNonFatal(jrcForestCover.fetchWindow(windowKey, windowLayout)) - .right - gadm0Tile <- Either - .catchNonFatal(gadmAdm0.fetchWindow(windowKey, windowLayout)) - .right - gadm1Tile <- Either - .catchNonFatal(gadmAdm1.fetchWindow(windowKey, windowLayout)) - .right - gadm2Tile <- Either - .catchNonFatal(gadmAdm2.fetchWindow(windowKey, windowLayout)) - .right - } yield { - val tile = GfwProDashboardTile(integratedAlertsTile, tcd2000Tile, sbtnNaturalForestTile, jrcForestCoverTile, gadm0Tile, gadm1Tile, gadm2Tile) - Raster(tile, windowKey.extent(windowLayout)) - } + val tile = GfwProDashboardTile( + windowKey, windowLayout, this + ) + Right(Raster(tile, windowKey.extent(windowLayout))) } } diff --git a/src/main/scala/org/globalforestwatch/summarystats/gfwpro_dashboard/GfwProDashboardTile.scala b/src/main/scala/org/globalforestwatch/summarystats/gfwpro_dashboard/GfwProDashboardTile.scala index 02bcd5c1..f4fa78a9 100644 --- a/src/main/scala/org/globalforestwatch/summarystats/gfwpro_dashboard/GfwProDashboardTile.scala +++ b/src/main/scala/org/globalforestwatch/summarystats/gfwpro_dashboard/GfwProDashboardTile.scala @@ -1,7 +1,7 @@ package org.globalforestwatch.summarystats.gfwpro_dashboard import geotrellis.raster.{CellGrid, CellType, IntCellType} -import org.globalforestwatch.layers._ +import geotrellis.layer.{LayoutDefinition, SpatialKey} /** * @@ -9,15 +9,19 @@ import org.globalforestwatch.layers._ * We can not use GeoTrellis MultibandTile because it requires all bands share a CellType. */ case class GfwProDashboardTile( - integratedAlerts: IntegratedAlerts#OptionalITile, - tcd2000: TreeCoverDensityPercent2000#ITile, - sbtnNaturalForest: SBTNNaturalForests#OptionalITile, - jrcForestCover: JRCForestCover#OptionalITile, - gadm0: GadmAdm0#OptionalITile, - gadm1: GadmAdm1#OptionalITile, - gadm2: GadmAdm2#OptionalITile + windowKey: SpatialKey, + windowLayout: LayoutDefinition, + sources: GfwProDashboardGridSources, ) extends CellGrid[Int] { + lazy val integratedAlerts = sources.integratedAlerts.fetchWindow(windowKey, windowLayout) + lazy val tcd2000 = sources.treeCoverDensity2000.fetchWindow(windowKey, windowLayout) + lazy val sbtnNaturalForest = sources.sbtnNaturalForest.fetchWindow(windowKey, windowLayout) + lazy val jrcForestCover = sources.jrcForestCover.fetchWindow(windowKey, windowLayout) + lazy val gadm0 = sources.gadmAdm0.fetchWindow(windowKey, windowLayout) + lazy val gadm1 = sources.gadmAdm1.fetchWindow(windowKey, windowLayout) + lazy val gadm2 = sources.gadmAdm2.fetchWindow(windowKey, windowLayout) + def cellType: CellType = integratedAlerts.cellType.getOrElse(IntCellType) def cols: Int = integratedAlerts.cols.getOrElse(GfwProDashboardGrid.blockSize)