Skip to content

Commit

Permalink
finished behavior of input/output od Leaflet map
Browse files Browse the repository at this point in the history
  • Loading branch information
osalamon committed Oct 24, 2024
1 parent 7ddd0e3 commit ec72f21
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 30 deletions.
52 changes: 26 additions & 26 deletions app/logic/disease_outbreaks/disease_leaflet_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,32 @@ disease_leaflet_map_basic <- function(map_raster,
return(leaflet_map)
}

#' @export
disease_leaflet_with_output_layer <- function(map_output_id, input_raster, output_raster) {
# #' @export
# disease_leaflet_with_output_layer <- function(map_output_id, input_raster, output_raster) {


leafletProxy(map_output_id) |> # hint: leafletProxy, removeImage, addRasterLegend, addLegend,
clearImages() |>
clearControls() |>
addRasterImage(
# input_raster,
opacity = 0.5,
project = FALSE,
options = tileOptions(zIndex = 100),
group = "Input layer",
layerId = "inputLayer"
) |>
addRasterImage(
output_raster,
opacity = 0.5,
project = FALSE,
options = tileOptions(zIndex = 101),
group = "Output layer",
layerId = "outputLayer"
) |>
addLayersControl(
overlayGroups = c("Input layer", "Output layer"),
options = layersControlOptions(collapsed = FALSE)
)
}
# leafletProxy(map_output_id) |> # hint: leafletProxy, removeImage, addRasterLegend, addLegend,
# clearImages() |>
# clearControls() |>
# addRasterImage(
# input_raster,
# opacity = 0.5,
# project = FALSE,
# options = tileOptions(zIndex = 100),
# group = "Input layer",
# layerId = "inputLayer"
# ) |>
# addRasterImage(
# output_raster,
# opacity = 0.5,
# project = FALSE,
# options = tileOptions(zIndex = 101),
# group = "Output layer",
# layerId = "outputLayer"
# ) |>
# addLayersControl(
# overlayGroups = c("Input layer", "Output layer"),
# options = layersControlOptions(collapsed = FALSE)
# )
# }

1 change: 1 addition & 0 deletions app/view/disease_outbreaks/disease_app/disease_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ disease_app_server <- function(id, tab_disease_selected) {

disease_map_server(
"disease_map",
map_original = map,
leaflet_map = leaflet_map,
new_tif_upload = new_tif_upload
)
Expand Down
30 changes: 26 additions & 4 deletions app/view/disease_outbreaks/disease_app/disease_map.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
box::use(
shiny[NS, moduleServer, tags, observeEvent, req],
bslib[card, card_header, card_body],
leaflet[leafletOutput, renderLeaflet, leafletProxy, addRasterImage],
leaflet[leafletOutput, renderLeaflet, leafletProxy, addRasterImage, addLayersControl, layersControlOptions, tileOptions, clearControls, clearImages],
)

box::use(
app / logic / disease_outbreaks / disease_leaflet_map[read_and_project_raster, disease_leaflet_with_output_layer]
app / logic / disease_outbreaks / disease_leaflet_map[read_and_project_raster]
)

#' @export
Expand All @@ -30,7 +30,7 @@ disease_map_ui <- function(id, i18n) {
}

#' @export
disease_map_server <- function(id, leaflet_map, new_tif_upload) {
disease_map_server <- function(id, map_original, leaflet_map, new_tif_upload) {
moduleServer(id, function(input, output, session) {
ns <- session$ns

Expand All @@ -45,7 +45,29 @@ disease_map_server <- function(id, leaflet_map, new_tif_upload) {
read_and_project_raster()

req(new_tif_raster)
disease_leaflet_with_output_layer("map_output", leaflet_map(), new_tif_raster)
leafletProxy("map_output") |>
clearImages() |>
clearControls() |>
addRasterImage(
map_original(),
opacity = 0.5,
project = FALSE,
options = tileOptions(zIndex = 100),
group = "Input layer",
layerId = "inputLayer"
) |>
addRasterImage(
new_tif_raster,
opacity = 0.5,
project = FALSE,
options = tileOptions(zIndex = 101),
group = "Output layer",
layerId = "outputLayer"
) |>
addLayersControl(
overlayGroups = c("Input layer", "Output layer"),
options = layersControlOptions(collapsed = FALSE)
)
})
})
}

0 comments on commit ec72f21

Please sign in to comment.