Skip to content

Instantly share code, notes, and snippets.

@Andrei-WongE
Forked from tim-salabim/layer_selector.R
Created February 28, 2023 15:31
Show Gist options
  • Save Andrei-WongE/8e6bb20e83054bb3751580276971e8a5 to your computer and use it in GitHub Desktop.
Save Andrei-WongE/8e6bb20e83054bb3751580276971e8a5 to your computer and use it in GitHub Desktop.
layer selector
library(mapview)
library(leafem)
library(leaflet)
library(sf)
library(geojsonsf)
franc_ext <- unname(as.vector(st_bbox(franconia)))
francgj = geojsonsf::sf_geojson(franconia)
leaflet() |>
addTiles() |>
addGeoJSON(francgj, layerId = "franc", group = "franc", weight = 1) |>
fitBounds(franc_ext[1], franc_ext[2], franc_ext[3], franc_ext[4]) |>
leafem:::addLayerSelector(colnames(franconia), "franc")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment