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

Not possible to recover layerID as in leaflet #77

Open
ischlo opened this issue Sep 14, 2022 · 7 comments · May be fixed by #95
Open

Not possible to recover layerID as in leaflet #77

ischlo opened this issue Sep 14, 2022 · 7 comments · May be fixed by #95
Assignees

Comments

@ischlo
Copy link

ischlo commented Sep 14, 2022

Hello,

I used your package for rendering a relatively big data set of polygons (12k) and it's impressive how faster and more fluid it is, so thanks for that !

I was wondering if the layerId are passed on with the shapes as well. In my shiny app, I use the layerID when a shape is clicked on. While the popups work as expected, I could not get the layerIDs as with the regular leaflet functions.

Thanks in advance,
Best,

@tim-salabim
Copy link
Member

Do you have a small reprex?

@ischlo
Copy link
Author

ischlo commented Sep 15, 2022

Hi ! thanks for the quick reply,
Here is a reprex, if you replace the leafgl functions by their leaflet equivalent, you should see the id and coordinates appear when clicking. it does not happen with leafgl functions...
Thanks in advance

library(shiny)
library(leaflet)
library(leafgl)
library(sf)

test_grid <- data.frame(
    id = 1:3
    ,geometry = c("POLYGON ((-0.08946933215777712 51.47411466935998, -0.08969000802663779 51.47598131471286, -0.08781123839374265 51.476842086027, -0.08507730250047442 51.47619388479495, -0.08485681363623958 51.4743272330522, -0.08673553872787136 51.47346650705812, -0.08946933215777712 51.47411466935998))"   
                  ,"POLYGON ((-0.08651493322924536 51.47159981398401, -0.08673553872787136 51.47346650705812, -0.08485681363623958 51.4743272330522, -0.08212314240894439 51.47367901320982, -0.08190272389120813 51.47181231375328, -0.08378140444241272 51.47095163307104, -0.08651493322924536 51.47159981398401))" 
                  ,"POLYGON ((-0.08817291831604734 51.4688722666752, -0.0883936404299329 51.47073900106984, -0.08651493322924536 51.47159981398401, -0.08378140444241272 51.47095163307104, -0.08356086928788481 51.46908489229133, -0.08543953196103615 51.46822412468794, -0.08817291831604734 51.4688722666752))" )) %>% 
    st_as_sf(wkt = 2,crs = 4326)

map <-  leaflet(data = test_grid) %>% 
    addTiles() %>% 
    addGlPolygons(data = test_grid
                ,color = "dimgray"
                ,popup = paste0("clicked shape: ", test_grid$id)
                ,weight = 5
                ,opacity = 1
                ,layerId = ~id
                ,fill = TRUE
                ,fillOpacity = .9
                ,fillColor = "dimgray"
    )

ui <- fluidPage(
    leafglOutput("map")
    ,textOutput("clicked_shape")
)

server <- function(input, output) {
    output$map <- renderLeaflet({
       map
    })
    
    observe({
        map_click <- reactive({input$map_shape_click})
        output$clicked_shape <- renderPrint({
            map_click()
            # input$map_shape_click
            })
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

@trafficonese
Copy link
Collaborator

@ischlo yeah, its a bit confusing.
LeafGl uses map_glify_click instead of map_shape_click.

@tim-salabim
Copy link
Member

@trafficonese should we align this with leaflet?

@trafficonese
Copy link
Collaborator

Good question.. Leaflet emits events with the following categories: marker, shape, geojson, and topojson. So somehow it makes sense to have the glify layers interact differently too or? That should probably be clearer in the docs.

I'm thinking that it could maybe be useful to have the glify events handled differently, especially if one has a map with multiple layers where only 1 is a LeafGL layer.

@ischlo
Copy link
Author

ischlo commented Sep 15, 2022

I see, it makes sense now! and , yes, it probably makes sense to have it as separate event. I just did not notice it in the docs.
the reprex works now.
Thanks !

@tim-salabim
Copy link
Member

Agreed. We should make it clearer in the docs. Would you have time for this @trafficonese ?

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