Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to have more than one pop-up in the same map? #92

Open
bmaparicio opened this issue Mar 18, 2024 · 2 comments · May be fixed by #95
Open

Is it possible to have more than one pop-up in the same map? #92

bmaparicio opened this issue Mar 18, 2024 · 2 comments · May be fixed by #95

Comments

@bmaparicio
Copy link

Hi,
I have a map with several layers. I want to display a pop-up with the data of the layer that is on, but I can't do it. The only pop-up that shows is from the last layer created (it overwrites the other). In the figure below, obj_1 does not show any pop-up when clicking, but obj_3 does (the last layer created).

image

Is there a way to have one pop-up per layer?
Thanks!

@tim-salabim
Copy link
Member

Can we get a reproducible example showing the issue?

@bmaparicio
Copy link
Author

Yes. Here is an open dataset:

library(leaflet)
library(leafgl)
library(sf)
library(spData)

data("hawaii")

my_data<-sf::st_cast(hawaii,"POLYGON")%>%
st_transform(crs = 4326)

set.seed(42)

#create data
my_data$obj_1 <- sample(1:500,nrow(my_data),replace=TRUE)
my_data$obj_3 <- sample(1000:10000,nrow(my_data),replace=TRUE)

#create palette
cols_obj1=colourvalues::colour_values_rgb(my_data$obj_1, palette = "cividis",include_alpha = FALSE)
cols_obj2=colourvalues::colour_values_rgb(my_data$obj_3, palette = "cividis",include_alpha = FALSE)

palFunc_objective_1 <- leaflet::colorNumeric(viridis::cividis(nrow(my_data)),
my_data$obj_1)

palFunc_objective_2 <- leaflet::colorNumeric(viridis::cividis(nrow(my_data)),
my_data$obj_3)

all_groups_leaflet<-c("obj_1","obj_3")

leaflet::leaflet() %>%
leaflet::addProviderTiles('Esri.NatGeoWorldMap', group = "Esri.NatGeoWorldMap") %>%
leafgl::addGlPolygons(data = my_data,
fillOpacity = 0.75,
color = cols_obj1,
opacity = 1,
popup = "obj_1",
weight = 0.1,
group = "obj_1") %>%
leaflet::addLegend(data=my_data, "topright",
pal = palFunc_objective_1,
values = ~my_data$obj_1 ,
title = "obj_1",
group = "obj_1",
opacity = 1)%>%

leafgl::addGlPolygons(data = my_data,
fillOpacity = 0.75,
color = cols_obj2,
opacity = 1,
popup = "obj_3",
weight = 0.1,
group = "obj_3") %>%
leaflet::addLegend(data=my_data, "topleft",
pal = palFunc_objective_2,
values = ~my_data$obj_3 ,
title = "obj_3",
group = "obj_3",
opacity = 1)%>%
leaflet::addLayersControl(overlayGroups = all_groups_leaflet,
options = leaflet::layersControlOptions(collapsed = F)) %>%

leaflet::hideGroup(all_groups_leaflet)%>%
leaflet.extras::addFullscreenControl(position = "topleft", pseudoFullscreen = FALSE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants