Skip to contents

This function adds regions within a bassin to an existing Leaflet map.

Usage

map_add_regions_in_bassin(
  map,
  bassins_data,
  bassin_click = bassin_click,
  regions_data = region_hydro
)

Arguments

map

An existing Leaflet map to which regions will be added.

bassins_data

A sf data.frame with bassins data.

bassin_click

A vector containing information about the clicked bassin.

regions_data

A sf data.frame containing information about regions within the bassin.

Value

An updated Leaflet map with regions added.

Examples

library(leaflet)
library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
library(sf)
# Create init bassin map
my_map <- 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 <- map_add_regions_in_bassin(map = my_map,
                                 bassins_data = bassin_hydrographique,
                                 bassin_click = centre_coord,
                                 regions_data = region_hydrographique)
map