Open ivanlambert1975 opened 1 year ago
@ivanlambert1975, I'm not following the example here. Are these two separate documents? Can you reconfigure into one quarto doc?
Closing due to inactivity.
I just ran into this issue today, and am attaching a reproducible example below
When creating multiple leaflet maps (in a Quarto doc, or an Rmarkdown doc) with leaflegend, and I have the same group name across multiple maps, the group functionality will not work correctly within the addLayersControl()
function. Only the last map's Layer Control will control the layer plotting, and will affect all layers across all maps.
I am guessing this is related to Issue #25 and PR #27
1) Open a new quarto document, and create one code chunk.
2) Paste the following into the code chunk
#| echo: false
#| message: false
library(leaflet)
library(leaflegend)
library(sf)
library(mapview)
dc_libraries = st_read("https://maps2.dcgis.dc.gov/dcgis/rest/services/DCGIS_DATA/Cultural_and_Society_WebMercator/MapServer/4/query?outFields=*&where=1%3D1&f=geojson")
library_map = leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addCircles(data = dc_libraries, group = "DC Libraries")
# Make first map
library_map %>%
addLegendFactor(pal = colorFactor("blue", "Libraries"),
shape = 'circle',
opacity = 1,
values = "Libraries",
position = 'topright',
group = 'Libraries'
) %>%
addLayersControl(overlayGroups = c("Libraries"),
position = "bottomleft")
# Make second map, with same group name
library_map %>%
addLegendFactor(pal = colorFactor("red", "Libraries"),
shape = 'circle',
opacity = 1,
values = "Libraries",
position = 'topright',
group = 'Libraries'
) %>%
addLayersControl(overlayGroups = c("Libraries"),
position = "bottomleft")
3) Render the code chunk, and play with the Layer Controls on map 1 and map 2. You will notice that only the Layer Control on map 2 works, and will affect the "Libraries" group in map 1.
Similar to Layer Controls in leaflet, layer controls should only affect the layers on the current map. And reusing layer names across different names should be supported.
Hi Thomas,
thank you very much for a very useful leaflet library. Thank you for your time and effort in developing leaflegend !
I think I've found an issue with leaflegand. I'm rendering many maps (tens of them) within one Quarto document. I use a standard function to output one of many thousands of leaflet maps over many geographies.
I've noticed that the group names when refenced in a leaflegend object appear shared over all chunks? This means that leaflegend works really great in a single map, but over subsequent maps in Quarto documents, the controls don't work or the groups cannot be reliably interacted within an addLayersControl - which appears an issue to me.
Please see the simplest example below I could make to demonstrate this unexpected behaviour. See how the lower map's controls affect the layers in the separate map above when this QMD is rendered. When more and more maps are added beyond these, the layersControl simply doesn't respond at all. I've tried many different workarounds over the last few hours and haven't succeeded in finding a scalable solution to resolve the issue. Please can you advise?
many thanks, ivan
title: "Test6" author: "BI" date: "04/10/2023" execute: echo: false format: html: fig-width: 12 fig-height: 10 code-fold: true embed-resources: false css: styles.css grid: sidebar-width: 220px body-width: 1400px margin-width: 150px gutter-width: 1.5rem