From 910f96ca3d642fe97842a7b0d7e7d1babdc51d27 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Mon, 27 Feb 2023 12:00:04 +0100 Subject: [PATCH] Add notebook for leaflet.extras2 issue * https://github.com/trafficonese/leaflet.extras2/issues/55 --- .gitignore | 2 + leaflet_issue_notebook.Rmd | 93 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 leaflet_issue_notebook.Rmd diff --git a/.gitignore b/.gitignore index 37bc665..e08a81f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .Rproj.user/ .Rhistory +*.html +*.zip diff --git a/leaflet_issue_notebook.Rmd b/leaflet_issue_notebook.Rmd new file mode 100644 index 0000000..72a6f1c --- /dev/null +++ b/leaflet_issue_notebook.Rmd @@ -0,0 +1,93 @@ +--- +title: "Leaflet reprex for issue in leaflet.extras2" +author: "Floris Vanderhaeghe" +date: "2023-02-27" +output: html_notebook +editor_options: + chunk_output_type: inline +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE) +``` + +```{r} +library(magrittr) +library(leaflet) +library(leaflet.extras2) +attrib_digvl <- "© Digitaal Vlaanderen" +``` + +```{r} +add_wms_forestnature <- function(map, + layers = "am:am_patdat", + transparent = TRUE, + options = WMSTileOptions( + format = "image/png", + transparent = transparent + ), + ...) { + addWMSTiles( + map = map, + baseUrl = "https://www.mercator.vlaanderen.be/raadpleegdienstenmercatorpubliek/wms", + layers = layers, + options = options, + attribution = attrib_digvl, + ... + ) +} +``` + +```{r} +add_wms_forestnature_2 <- function(map, + layers = "am:am_patdat", + transparent = TRUE, + options = WMSTileOptions( + format = "image/png", + transparent = transparent + ), + ...) { + addWMS( + map = map, + baseUrl = "https://www.mercator.vlaanderen.be/raadpleegdienstenmercatorpubliek/wms", + layers = layers, + options = options, + attribution = attrib_digvl, + ... + ) +} +``` + + +## Map with `leaflet::addWMSTiles()` + +```{r} +leaflet() %>% + setView(lng = 4.68, lat = 50.82, zoom = 12) %>% + addTiles() %>% + add_wms_forestnature(group = "Forest_Nature") %>% + addLayersControl( + overlayGroups = "Forest_Nature", + options = layersControlOptions(collapsed = FALSE) + ) +``` + + +## Map with `leaflet.extras2::addWMS()` + +```{r} +leaflet() %>% + setView(lng = 4.68, lat = 50.82, zoom = 12) %>% + addTiles() %>% + add_wms_forestnature_2(group = "Forest_Nature") %>% + addLayersControl( + overlayGroups = "Forest_Nature", + options = layersControlOptions(collapsed = FALSE) + ) +``` + +```{r} +sessioninfo::session_info() +``` + +