r-spatial / leafem

leaflet extensions for mapview
https://r-spatial.github.io/leafem/
Other
108 stars 30 forks source link

FGB attach by group, highlightOptions, label as function #85

Closed trafficonese closed 2 months ago

trafficonese commented 5 months ago

and sry for the git-commit-mess.. I rebased against master, but in the PR the individal commits are visible again.


Shiny-App

``` ## pkgs ############### library(leafem) library(leaflet) library(shiny) library(sf) ## Transform Data to FGB ############ options("shiny.autoreload" = TRUE) url = "https://flatgeobuf.org/test/data/UScounties.fgb" # fgb <- sf::st_read(dsn = url) # fgb <- st_cast(fgb, "POLYGON") # uscounties <- "./uscounties_polyon.fgb" # sf::st_write(obj = fgb, dsn = uscounties, driver = "FlatGeobuf", delete_dsn = TRUE) ## UI ################## ui <- fluidPage( actionButton("show", "show"), actionButton("hide", "hide"), actionButton("clearGroup", "clearGroup"), leafletOutput("map", height = 700), verbatimTextOutput("printclick") ) ## SERVER ################## server <- function(input, output){ output$map <- renderLeaflet({ leaflet("map") %>% setView(-104, 44, 7) %>% addTiles() %>% leafem::addMouseCoordinates() %>% addFgb( # file = uscounties url = url , fill = TRUE , group = "Lines_FGB" , layerId = "FIPS" , stroke = TRUE , color = "#41db5d" , fillOpacity = 0.3 , popup = TRUE # , label = "NAME" , label = JS("function (layer) { return(json2table(layer.feature.properties)); }") # , minZoom = 6 , highlightOptions = highlightOptions(color = "#207f01", fillOpacity=0.8) ) %>% addLayersControl(position = "topright", overlayGroups = c("Lines_FGB"), options = layersControlOptions(collapsed = F, autoZIndex = TRUE) ) }) ## Observer ############### observeEvent(input$show, { leafletProxy("map") %>% showGroup("Lines_FGB") }) observeEvent(input$hide, { leafletProxy("map") %>% hideGroup("Lines_FGB") }) observeEvent(input$clearGroup, { leafletProxy("map") %>% clearGroup("Lines_FGB") }) ## Ouputs ############### output$printclick <- renderPrint({ click <- req(input$map_shape_click) req(click$group == "Lines_FGB") print(click) }) } shinyApp(ui = ui, server = server) ```

trafficonese commented 4 months ago

The commit 2300146 fixes the options. Currently TRUE options are always removed (in my case contextmenu = TRUE and interactive = TRUE)

trafficonese commented 2 months ago

@tim-salabim How do you feel about this PR? Too many potential breaking changes?

tim-salabim commented 2 months ago

@trafficonese I am not sure about the breaking changes. In all honesty, I forgot about this PR... Let me see if mapview still works with it.

tim-salabim commented 2 months ago

Seems to not break anything as far as I can see. Is it safe to merge (wrt the layerviewcontrol PR)?

trafficonese commented 2 months ago

no worries :) Yes it should be safe, and it would make FGB the most feature-complete alternative to leaflets-functions.

tim-salabim commented 2 months ago

Thanks!