FGB attach by group, highlightOptions, label as function
-
This changes the FGB attachments and uses
groupinstead oflayerId. AlthoughlayerIdcannot be a vector or formula withaddFgb, I think we should treat the leaflet arguments as similar as possible. But maybe in this case we could ignore that, or what if we expose a new argumentdataSrcfor example and set it to togroupif it is NULL? -
Update Flatgeobuf to '3.31.1' from '3.21.3'
-
expose highlightOptions for mouseover-effect. https://github.com/r-spatial/mapview/issues/415
-
mouseEvent will look if
layerIdis a property of the feature, otherwise just returnlayerIdas string. Fix #80 -
labelcan also be aJS()function. (see the shiny example below) -
Some JS-cleanup, fix indentation in
addFlatGeoBufFiltered, changedvartolet/const, etc..
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)
The commit 2300146 fixes the options.
Currently TRUE options are always removed (in my case contextmenu = TRUE and interactive = TRUE)
@tim-salabim How do you feel about this PR? Too many potential breaking changes?
@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.
Seems to not break anything as far as I can see. Is it safe to merge (wrt the layerviewcontrol PR)?
no worries :) Yes it should be safe, and it would make FGB the most feature-complete alternative to leaflets-functions.
Thanks!