library(leaflet)
library(leafem)
library(sf)
library(geojsonsf)
# create some random data
che = st_as_sf(gadmCHE)
if (require(lwgeom)) {
pts = st_as_sf(st_sample(che, 200))
pts = st_join(pts, che[, "ID_1"])
che = sf_geojson(che)
leaflet() %>%
addTiles() %>%
addGeoJSON(che, group = "che") %>%
addReactiveFeatures(
pts
, srcLayer = "che"
, by = "ID_1"
, on = "click"
, group = "pts"
, style = list(color = "black", fillOpacity = 0.3)
, updateStyle = list(
opacity = 0.3
, fillOpacity = 0.3
, color = "forestgreen"
, fillColor = "forestgreen"
)
) %>%
addMouseCoordinates() %>%
setView(lng = 8.31, lat = 46.75, zoom = 8)
}
Run the code above in your browser using DataLab