Skip to content

fix: pass simplify=FALSE to sf_geojson for geometry-only sf objects#214

Merged
walkerke merged 1 commit into
walkerke:mainfrom
Cidree:fix/geojsonsf
Jul 1, 2026
Merged

fix: pass simplify=FALSE to sf_geojson for geometry-only sf objects#214
walkerke merged 1 commit into
walkerke:mainfrom
Cidree:fix/geojsonsf

Conversation

@Cidree

@Cidree Cidree commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

This issue closes #212.

It adds simplify = FALSE in every geojsonsf::sf_geojson() call, to ensure that the geometry and properties are always serialized as a FeatureCollection, regardless of whether the sf has property columns.

Using the example that failed in #212:

devtools::load_all()

map_dat <- data.frame(lat = c(45, 50), lon = c(-45, 50)) |>
  sf::st_as_sf(coords = c("lon", "lat"), crs = 4326) 

maplibre(projection = "mercator") |>
  add_circle_layer(id = "poi-layer", source = map_dat) 
image

…alkerke#212)

geojsonsf::sf_geojson() with simplify=TRUE (default) atomizes sf objects
that have no non-geometry columns into a vector of individual geometry
strings rather than a FeatureCollection. htmlwidgets cannot serialize a
length-n json-class vector, causing a serialization error. Passing
simplify=FALSE consistently returns a FeatureCollection regardless of
whether the sf has property columns.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@walkerke

walkerke commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Thank you! This has been a long-needed fix.

@walkerke walkerke merged commit e3de797 into walkerke:main Jul 1, 2026
2 of 3 checks passed
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 this pull request may close these issues.

Error in vapply() when trying to use add_circle_layer() on data containing lat/lon only

2 participants