```{asis, echo = {{select_query_knit}}, eval = {{select_query_knit}}, include = {{select_query_knit}}}
Loads the raster image for the area selected on the map
```

```{r, echo = {{select_query_knit}}, include = {{select_query_knit}}}
poly <- {{select_query_poly}}
token <- {{select_query_token}}
raster <- select_query(poly, {{select_query_date}}, token)
raster_name <- {{select_query_name}}

raster_extent <- as.vector(terra::ext(raster))
map_pal <- RColorBrewer::brewer.pal(9, "Greens")
custom_greens <- colorRampPalette(map_pal)(10)
color_bins <- colorBin(custom_greens, domain = terra::values(raster), bins = 10, na.color = "pink")

leaflet() |>
  addProviderTiles("Esri.WorldTopoMap") |>
  addRasterImage(raster, colors = color_bins, group = raster_name) |>
  addTiles(urlTemplate = "", attribution = "MODIS data via LAADS DAAC") |>
  fitBounds(lng1 = raster_extent[[1]], lng2 = raster_extent[[2]], lat1 = raster_extent[[3]], lat2 = raster_extent[[4]]) |>
  addLegend(position = "bottomright", pal = color_bins, values = terra::values(raster),
            group = raster_name, title = raster_name, layer = raster_name)

```
