Update Leaflet Map for a Clicked Region
map_region_clicked.Rd
This function updates an existing Leaflet map when a region is clicked, displaying the region and overlayers.
Usage
map_region_clicked(
map,
region_click,
selected_region_feature,
regions_data,
roe_region,
hydro_sites_region
)
Arguments
- map
An existing Leaflet map to be updated.
- region_click
A vector containing information about the clicked region.
- selected_region_feature
A sf data frame containing information about the selected region feature.
- regions_data
A sf data.frame with the hydrographic regions of the bassin selected.
- roe_region
sf data.frame ROE in selected region.
- hydro_sites_region
sf data.frame hydrometric sites in selected region.
Examples
library(leaflet)
library(dplyr)
library(sf)
# Create init bassin map
map_bassin <- map_init_bassins(bassins_data = bassin_hydrographique,
id_logo_ign_remonterletemps = "logo_ign_remonterletemps")
# simulate bassin selected
selected_bassin <- bassin_hydrographique
# get centroid coordinate (in shiny see leaflet mapid_shape_click)
centre <- sf::st_centroid(selected_bassin)
#> Warning: st_centroid assumes attributes are constant over geometries
centre_coord <- as.data.frame(st_coordinates(centre)) %>%
rename("lng" = X,
"lat" = Y)
# map region
map_region <- map_add_regions_in_bassin(map = map_bassin,
bassins_data = bassin_hydrographique,
bassin_click = centre_coord,
regions_data = region_hydrographique)
# simulate selected region
selected_region <- region_hydrographique
# get centroid coordinate (in shiny see leaflet mapid_shape_click)
centre_region <- sf::st_centroid(selected_bassin)
#> Warning: st_centroid assumes attributes are constant over geometries
centre_region_coord <- as.data.frame(st_coordinates(centre_region)) %>%
rename("lng" = X,
"lat" = Y)
centre_region_coord$id <- 11
con <- db_con()
#> Error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
#> Is the server running locally and accepting connections on that socket?
# get ROE in region
roe_region <- data_get_roe_in_region(centre_region_coord$id, con = con)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'conn' in selecting a method for function 'sqlInterpolate': object 'con' not found
# get hydro sites in region
hydro_sites_region <- data_get_hydro_sites(centre_region_coord$id, con = con)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'conn' in selecting a method for function 'sqlInterpolate': object 'con' not found
DBI::dbDisconnect(con)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'conn' in selecting a method for function 'dbDisconnect': object 'con' not found
# map the element in the region clicked
map <- map_region_clicked(map = map_region,
region_click = centre_region_coord,
selected_region_feature = selected_region,
regions_data = region_hydrographique,
roe_region = roe_region,
hydro_sites_region = hydro_sites_region)
#> Error in eval(expr, envir, enclos): object 'hydro_sites_region' not found
map
#> Error in eval(expr, envir, enclos): object 'map' not found