Closed Abhishek-Kar closed 2 years ago
Some special characters do not work in the "groups" name:
leaflet() |>
addTiles() |>
addLegendImage(
images = c("http://leafletjs.com/examples/custom-icons/leaf-green.png"),
labels = "",
labelStyle = "font-size: 12px; horizontal-align: middle;",
width = 350,
height = 350,
group ="AllTime"
) |>
addLayersControl(
overlayGroups =c("AllTime",
"TimeA Li850MA55 UV.BC",
"TimeB Li850MA55 UV.BC"
),
options = layersControlOptions(collapsed = F)
)
I'm having the same issue. The groups argument should allow the legend to turn on or off with that layer
If you use the above code with the special characters removed, does it work? The example worked for me.
Yes, it does. I have tried it after removing space & dots from the group name. Thank you for creating an amazing package and your problem solving for a bumbling idiot like me :)
Warm regards, Abhishek
On Thu, Dec 2, 2021 at 11:34 AM Thomas Roh @.***> wrote:
If you use the above code with the special characters removed, does it work? The example worked for me.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tomroh/leaflegend/issues/45#issuecomment-984793914, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIEQIMQAHQSZZI3RWJC2BFLUO6NXLANCNFSM5I6G6UCA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
No problem. Thanks for raising the issue. I'm going to keep this issue open for now because I believe base leaflet
groups can have special characters. The javascript code that adds the hide/show functionality for legend groups needs to be modified.
It did work in this example (and my code) with all spaces removed! Awesome package and much needed. THANK YOU
Special characters are now allowed for group names. 1aff4742da5ac5cad2eabebd7353628315391bfe
I have this problems with the latest CRAN version when I have underscores in the group name. For example, hideGroup does not remove the legend. Has this problem resurfaced ?
Actually, on further testing, hideGroup doesn't work whether the name has special characters or not.
I think hideGroup
is a different issue that this. Can you open a separate issue? Only this type of functionality is currently supported
library(leaflet)
library(leaflegend)
numPal <- colorNumeric('viridis', quakes$depth)
quantPal <- colorQuantile('viridis', quakes$mag, n = 5)
binPal <- colorBin('Set1', quakes$mag)
leaflet() %>%
addTiles() %>%
addLegendNumeric(
pal = numPal,
values = quakes$depth,
position = 'topright',
title = 'addLegendNumeric',
group = 'Numeric Data'
) %>%
addLegendQuantile(
pal = quantPal,
values = quakes$mag,
position = 'topright',
title = 'addLegendQuantile',
group = 'Quantile'
) %>%
addLegendBin(
pal = binPal,
values = quakes$mag,
position = 'bottomleft',
title = 'addLegendBin',
group = 'Bin'
) %>%
addLayersControl(
baseGroups = c('Numeric Data', 'Quantile'), overlayGroups = c('Bin'),
position = 'bottomright'
)
Actually, hideGroup works as well:
leaflet() %>%
addTiles() %>%
addLegendNumeric(
pal = numPal,
values = quakes$depth,
position = 'topright',
title = 'addLegendNumeric',
group = 'Numeric Data'
) %>%
addLegendQuantile(
pal = quantPal,
values = quakes$mag,
position = 'topright',
title = 'addLegendQuantile',
group = 'Quantile'
) %>%
addLegendBin(
pal = binPal,
values = quakes$mag,
position = 'bottomleft',
title = 'addLegendBin',
group = 'Bin'
) %>%
addLayersControl(
baseGroups = c('Numeric Data', 'Quantile'), overlayGroups = c('Bin'),
position = 'bottomright'
) %>%
leaflet::hideGroup('Bin')
This is an example of code that didn't work for me:
observeEvent({
aadf_edges_filtered()
}, {
if (input$aadf_edges == TRUE &&
input$aadf_region != "" && input$aadf_year != "") {
leafletProxy("map", data = aadf_edges_filtered()) %>%
clearGroup("mg_aadf_edges") %>%
leaflet.extras2::addSpinner() %>%
leaflet.extras2::startSpinner(options = list("lines" = 12, "length" = 15)) %>%
addPolylines(
options = pathOptions(pane = "mp_aadf_edges"),
group = "mg_aadf_edges",
layerId = ~ link_id,
weight = (
aadf_edges_filtered()$selected_class / map_edges_scaling_factor()
),
color = "firebrick",
opacity = 0.5,
highlightOptions = highlightOptions(
color = "firebrick",
bringToFront = F,
opacity = 0.9
)
) %>%
leaflegend::addLegendSize(
group = "mg_aadf_edges",
color = "firebrick",
shape = "rect",
baseSize = mean((
aadf_edges_filtered()$selected_class / map_edges_scaling_factor()
)
),
values = aadf_edges_filtered()$selected_class,
layerId = 1,
fillOpacity = 0.5,
strokeWidth = 0,
title = aadf_edges_legend_title(),
position = "topleft",
breaks = 4
) %>%
leaflet.extras2::stopSpinner()
}
})
Then, this code should hide or show the group depending on a checkbox state. It hid or showed the polyline layer but did nothing for the legend.
observeEvent(input$aadf_edges, {
if (input$aadf_edges == TRUE) {
leafletProxy("map") %>%
showGroup("mg_aadf_edges")
} else {
leafletProxy("map") %>%
hideGroup("mg_aadf_edges")
}
})
Underscores and other special characters in the name of the hidegroup used to be an issue. It may be resolved now
Underscores weren't working moved this to issue #75
Here is the code snippet
addLegendImage( images = c("http://leafletjs.com/examples/custom-icons/leaf-green.png"), labels = "", labelStyle = "font-size: 12px; horizontal-align: middle;", width = 350, height = 350, group ="AllTime" ) %>%
addLayersControl( overlayGroups =c("AllTime", "TimeA: Li850/MA55: UV.BC", "TimeB: Li850/MA55: UV.BC", ... ), options = layersControlOptions(collapsed = F) )
As you can see in the attached screenshot, even when the group "AllTime" is deselected, the image remains