Add a metric layer with custom symbology to a map.
map_metric.Rd
This function adds a metric layer with custom symbology to a leaflet map. It allows you to specify custom parameters for the Web Map Service (WMS) request, apply a CQL (Common Query Language) filter, and provide a custom SLD (Styled Layer Descriptor) body for styling the layer. Additionally, you can specify the data axis to display on the map.
Usage
map_metric(
map,
wms_params = params_wms()$metric,
cql_filter = "",
sld_body = "",
data_axis
)
Arguments
- map
A leaflet map object to which the metric layer will be added.
- wms_params
A list containing WMS parameters for the metric layer. If not provided, default parameters are retrieved using the
params_wms
function.- cql_filter
A character string representing a CQL filter to apply to the metric layer.
- sld_body
A character string representing the SLD (Styled Layer Descriptor) body for custom styling of the metric layer.
- data_axis
A data axis to display on the map.
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
# 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
# build geoserver WMS filter
cql_filter=paste0("gid_region=", selected_region[["gid"]])
# build geoserver SLD symbology
sld_body <- sld_get_style(breaks = sld_get_quantile_metric(
selected_region_id = selected_region[["gid"]],
selected_metric = "active_channel_width",
con = con),
colors = sld_get_quantile_colors(
quantile_breaks = sld_get_quantile_metric(
selected_region_id = selected_region[["gid"]],
selected_metric = "active_channel_width",
con = con)),
metric = "active_channel_width")
#> 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
# Network axis by region
network_region_axis <- network_axis %>%
filter(gid_region == selected_region[["gid"]])
# Add metric with quantile symbology
# wms_params = params_wms()$metric_basic with sld_body = NULL for default blue style$
map_metric <- map_metric(map = map,
wms_params = params_wms()$metric,
cql_filter = cql_filter,
sld_body = sld_body,
data_axis = network_region_axis)
#> Error in eval(expr, envir, enclos): object 'sld_body' not found
map_metric
#> function (map, wms_params = params_wms()$metric, cql_filter = "",
#> sld_body = "", data_axis)
#> {
#> map %>% clearGroup(params_map_group()[["axis"]]) %>% clearGroup(params_map_group()[["metric"]]) %>%
#> map_wms_metric(wms_params = wms_params, cql_filter = cql_filter,
#> sld_body = sld_body) %>% map_axis(data_axis = data_axis)
#> }
#> <bytecode: 0x55db87de7438>
#> <environment: namespace:mapdoapp>