@@ -259,11 +259,13 @@ function(input, output, session) {
259
259
options = leafletOptions(pane = " maplabels" ),
260
260
group = " map labels" ) %> %
261
261
hideGroup(names(rehab_tiers )) %> %
262
+ hideGroup(paste0(" centres_" , names(rehab_tiers ))) %> %
263
+ hideGroup(paste0(" towns_" , names(rehab_tiers ))) %> %
262
264
addCircleMarkers(
263
- lng = df_locations $ x , lat = df_locations $ y ,
265
+ lng = df_rehab_map_locations $ x , lat = df_rehab_map_locations $ y ,
264
266
radius = 2 , fillOpacity = 0 ,
265
- popup = df_locations $ popup_rehab ,
266
- group = " Towns " ,
267
+ popup = df_rehab_map_locations $ popup_none ,
268
+ group = " towns_None " ,
267
269
options = leafletOptions(pane = " markers" )
268
270
) %> %
269
271
addLegendNumeric(
@@ -274,26 +276,47 @@ function(input, output, session) {
274
276
bins = 10 ,
275
277
value = c(- 0.01 , 0 : 20 , 20.1 ),
276
278
htmltools :: tagList(tags $ div(" Time to care (hours)" ), tags $ br())
277
- ) %> %
278
- addLayersControl(
279
- position = " topright" ,
280
- baseGroups = c(" None" , names(rehab_tiers )),
281
- overlayGroups = c(" Towns" ),
282
- options = layersControlOptions(collapsed = FALSE ))%> %
283
- htmlwidgets :: onRender("
284
- function() {
285
- $('.leaflet-control-layers-list').prepend('<label style=\" text-align:center\" >Markers</label>');
286
- }
287
- " )
279
+ )
288
280
rvs $ map_rehab
289
281
})
290
282
283
+ observeEvent(list (input $ rehab_layer_selection , input $ rehab_towns_checkbox ), {
284
+ rehab_base_groups <- c(" None" , names(rehab_tiers ))
285
+ rehab_towns_groups <- paste0(" towns_" , rehab_base_groups )
286
+
287
+ hide_base_groups <- rehab_base_groups [rehab_base_groups != input $ rehab_layer_selection ]
288
+ show_base_group <- input $ rehab_layer_selection
289
+
290
+ hide_centre_groups <- paste0(" centres_" , hide_base_groups )
291
+ show_centre_group <- paste0(" centres_" , show_base_group )
292
+
293
+ if (is.null(input $ rehab_towns_checkbox )) {
294
+ show_towns_group <- c()
295
+ hide_towns_groups <- rehab_towns_groups
296
+ } else {
297
+ show_towns_group <- rehab_towns_groups [which(rehab_base_groups == show_base_group )]
298
+ hide_towns_groups <- rehab_towns_groups [rehab_towns_groups != show_towns_group ]
299
+ }
300
+
301
+ show_ids <- c(show_base_group , show_centre_group , show_towns_group )
302
+ hide_ids <- c(hide_base_groups , hide_centre_groups , hide_towns_groups )
303
+
304
+ leafletProxy(" map_rehab" ) %> %
305
+ showGroup(show_ids ) %> %
306
+ hideGroup(hide_ids )
307
+ })
308
+
291
309
observeEvent(rvs $ to_load_rehab , {
292
310
req(rvs $ map_rehab )
293
311
if (is.null(isolate(rvs $ map_rehab )) | isolate(rvs $ map_rehab_complete ))return ()
294
312
for (group_name in names(rehab_tiers )){
295
313
new_layer <- readRDS(file.path(layers_dir , glue :: glue(" {rehab_tiers[[group_name]]$file}.rds" )))
296
314
centres_group <- df_centres [df_centres $ centre_name %in% rehab_tiers [[group_name ]]$ centres , ]
315
+
316
+ popup_col <- paste0(" popup_" ,tolower(group_name ))
317
+ popup_col <- str_replace_all(popup_col , " " , " _" )
318
+ town_popups <- df_rehab_map_locations %> % pull(!! {popup_col })
319
+
297
320
leafletProxy(" map_rehab" ) %> %
298
321
addRasterImage(
299
322
data = new_layer ,
@@ -306,7 +329,14 @@ function(input, output, session) {
306
329
lng = centres_group $ x , lat = centres_group $ y ,
307
330
icon = tier_icons [group_name ],
308
331
popup = centres_group $ popup ,
309
- group = group_name ,
332
+ group = paste0(" centres_" , group_name ),
333
+ options = leafletOptions(pane = " markers" )
334
+ ) %> %
335
+ addCircleMarkers(
336
+ lng = df_rehab_map_locations $ x , lat = df_rehab_map_locations $ y ,
337
+ radius = 2 , fillOpacity = 0 ,
338
+ popup = town_popups ,
339
+ group = paste0(" towns_" , group_name ),
310
340
options = leafletOptions(pane = " markers" )
311
341
)
312
342
}
0 commit comments