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

popup not working if Polylines are added twice #48

Open
trafficonese opened this issue Sep 21, 2020 · 5 comments · May be fixed by #95
Open

popup not working if Polylines are added twice #48

trafficonese opened this issue Sep 21, 2020 · 5 comments · May be fixed by #95

Comments

@trafficonese
Copy link
Collaborator

I want to overlay an already visible Polyline with another one, with a different popup. Interestingly that does not work if the data is part of the already visible layer. I tried the CRAN and current github versions without success.
The click event stops here

if (map.hasLayer(lineslayer.glLayer)) {

Interestingly, if the 2nd Polyline uses data = data[11:nrow(data),] instead, the example will work.

Here is an example to illustrate the problem.

library(leaflet)
library(leafgl)

data <- sf::st_as_sf(leaflet::atlStorms2005)

leaflet() %>% 
  addTiles() %>% 
  addGlPolylines(
    data = data[1:10,],
    group = "base", 
    color = "red", 
    popup = TRUE) %>% 
  addGlPolylines(
    data = data[1:10,],
    # data = data[11:nrow(data),],
    color = "blue",
    group = "base2",
    popup = ~sprintf("I am a special Popup<br><b>Name :</b> %s<br><b>MaxWind :</b> %s",
                     Name , MaxWind)) %>% 
  hideGroup("base") %>% 
  addLayersControl(overlayGroups = "base")
@trafficonese trafficonese changed the title popup not working if Polylines is added twice popup not working if Polylines are added twice Sep 21, 2020
@tim-salabim
Copy link
Member

I'll try to have a look soon. My current focus is not on leafgl though, so it may take a while (also regarding your PRs)

@trafficonese
Copy link
Collaborator Author

It seems that both layers are still active, and glify only "sees" the first one.

Manually setting the first one to active = false with

      L.glify.instances.forEach(e => {
        if (e.settings.className === "base") {
            e.active = false;
        }
      });

seems to work. I think this might be a Glify issue, by not handling showing/hiding correctly, but I also might be totally wrong.

@paragemini
Copy link

paragemini commented May 2, 2022

@trafficonese Were you able to solve the problem ? Does the forEach function goes before the popup block ?

if (addpopup) {
       var content = popup === true ? '<pre>'+JSON.stringify(feature.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>' : popup[idx].toString();
       L.popup({ maxWidth: 2000 })
       .setLatLng(e.latlng)
       .setContent(content)
       .openOn(map);

@trafficonese
Copy link
Collaborator Author

@paragemini I managed to get it to work with the hack mentioned above, but it's not really a fix.
I run this JavaScript snippet from within my shinyapp.

Otherwise I think this has to be fixed in Leaflet Glify and cannot be solved here.

@tim-salabim
Copy link
Member

@paragemini if that hack does not work for you, you should consider raising this issue at https://github.com/robertleeplummerjr/Leaflet.glify

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.

3 participants