trafficonese / leaflet.extras

Extra functionality for leaflet R package.
https://trafficonese.github.io/leaflet.extras/
GNU General Public License v3.0
211 stars 74 forks source link

Function to convert feature collection in list to geojson #197

Closed woodwards closed 4 months ago

woodwards commented 3 years ago

I am using addDrawToolbar to draw polygons on my leaflet("map"), and then I want to capture them (ideally to sf) using input$map_draw_all_features.

However it seems the returned list is not compatible with geojson_list. Am I doing something wrong or is this a "feature request"?

Thanks so much for this excellent tool(bar).


data <- input$map_draw_all_features # list
data <- geojson_list(data)
data <- geojson_sf(data)
woodwards commented 3 years ago

This seems to work? I'll test it more.


data <- input$map_draw_all_features # list
data <- jsonlite::toJSON(data, auto_unbox = TRUE) # string
data <- geojsonio::geojson_sf(data) # sf
trafficonese commented 4 months ago

This seems to work well! I have included this approach in this example: browseURL(system.file("examples/shiny/draw-events/app.R", package = "leaflet.extras"))