From 7b71fb19fcb6b2ead25dafe843526726608b06af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Wed, 10 Jan 2024 21:52:37 +0100 Subject: [PATCH 1/8] update man page --- man/maplibre.Rd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/man/maplibre.Rd b/man/maplibre.Rd index ff1d48f..2517299 100644 --- a/man/maplibre.Rd +++ b/man/maplibre.Rd @@ -16,13 +16,14 @@ maplibre( } \examples{ -test <- mapOptions( +map_options <- mapOptions( center = c(-123.1256, 49.24658), hash = TRUE, pitch = 0, style = basemaps$carto$dark_matter, test = NULL ) -maplibre(test, zoom = 12) |> +maplibre(map_options, zoom = 12) |> add_control("NavigationControl", "top-left", showCompass = F) + } From b73910390588c855bbb39361c2269cd4b9d2157c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Wed, 10 Jan 2024 21:53:03 +0100 Subject: [PATCH 2/8] move code around --- R/maplibre.R | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/R/maplibre.R b/R/maplibre.R index edc2f29..c3d24f6 100644 --- a/R/maplibre.R +++ b/R/maplibre.R @@ -1,8 +1,3 @@ -mapOptions <- function(style = basemaps$carto$dark_matter, ...) { - list(style = style, ...) -} - - #' #' #' @@ -12,8 +7,7 @@ mapOptions <- function(style = basemaps$carto$dark_matter, ...) { #' @export #' @example examples/basemap.R #' - -maplibre <- function(map_options = mapOptions(), width = NULL, height = NULL, elementId = NULL, ...) { +maplibre <- function(map_options = mapOptions(), width = "100%", height = NULL, elementId = NULL, ...) { if (inherits(map_options$bounds, "bbox")) { map_options$bounds <- unname(map_options$bounds) } @@ -36,6 +30,11 @@ maplibre <- function(map_options = mapOptions(), width = NULL, height = NULL, el ) } +mapOptions <- function(style = basemaps$carto$dark_matter, ...) { + list(style = style, ...) +} + + #' Shiny bindings for maplibre #' #' Output and render functions for using maplibre within Shiny From a44cd22e31507e291791fc0a83e4b6f6acac8641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Wed, 10 Jan 2024 21:53:21 +0100 Subject: [PATCH 3/8] update examples --- examples/basemap.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/basemap.R b/examples/basemap.R index 4aca633..daf692b 100644 --- a/examples/basemap.R +++ b/examples/basemap.R @@ -1,9 +1,10 @@ -test <- mapOptions( +map_options <- mapOptions( center = c(-123.1256, 49.24658), hash = TRUE, pitch = 0, style = basemaps$carto$dark_matter, test = NULL ) -maplibre(test, zoom = 12) |> +maplibre(map_options, zoom = 12) |> add_control("NavigationControl", "top-left", showCompass = F) + From 1ffccdbd46eabeb21c2bf5554dde525d6756ab85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Wed, 10 Jan 2024 23:54:22 +0100 Subject: [PATCH 4/8] dependencies --- DESCRIPTION | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 65e87d7..6061899 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,4 +16,6 @@ Depends: R (>= 2.10) URL: https://eodagmbh.github.io/r-maplibregl/ Imports: - htmlwidgets + geojsonsf, + htmlwidgets, + purrr From 1c93a8bf94d5faf0acd157a2006b2bccd3a9120a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Wed, 10 Jan 2024 23:54:39 +0100 Subject: [PATCH 5/8] update NAMESPACE --- NAMESPACE | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index ce13f12..2ace7bc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,9 +1,11 @@ # Generated by roxygen2: do not edit by hand +export(Layer) +export(Marker) export(add_call) export(add_control) export(add_layer) -export(layer) +export(add_marker) export(maplibre) export(maplibreOutput) export(renderMaplibre) From f8fc3302ee9e1e790853895f3aff09dd04e1abf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Wed, 10 Jan 2024 23:54:50 +0100 Subject: [PATCH 6/8] add marker functions --- R/marker.R | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 R/marker.R diff --git a/R/marker.R b/R/marker.R new file mode 100644 index 0000000..ee8710c --- /dev/null +++ b/R/marker.R @@ -0,0 +1,38 @@ +#' Create a Marker +#' +#' @param lngLat +#' @param popup +#' @export +#' @example examples/markers.R +Marker <- function(lngLat, popup , ...) { + mark <- list( + lngLat = lngLat, + popup = popup, + options = MarkerOptions(...) + ) |> + purrr::compact() + class(mark) <- "MapLibreMarker" + return(mark) +} + +MarkerOptions <- function(...){ + marker_options <- list(...) + stopifnot(sapply(marker_options[c("anchor", "color", "pitchAlignment", "rotationAlignment")], function(x){is.null(x) | is.character(x)})) + stopifnot(sapply(marker_options["draggable"], function(x) {is.null(x) | is.logical(x)})) + stopifnot(sapply(marker_options[c("rotation", "scale")], function(x) {is.null(x) | is.numeric(x)})) + marker_options <- marker_options |> + purrr::compact() + class(marker_options) <- "MarkerOptions" + return(marker_options) +} + +#' Add a marker to map +#' +#' @param .map +#' @param marker +#' +#' @export +#' @example examples/markers.R +add_marker <- function(.map, marker) { + .map |> add_call("addMarker", marker) +} From dc4995e1769b05e61274411554c772b978b39d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Wed, 10 Jan 2024 23:55:00 +0100 Subject: [PATCH 7/8] update layer functions --- R/layer.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/layer.R b/R/layer.R index 73536d0..b5a8fb0 100644 --- a/R/layer.R +++ b/R/layer.R @@ -7,8 +7,8 @@ #' @param layout #' #' @export -layer <- function(type, id, source = NULL, paint = NULL, layout = NULL, ...) { - list( +Layer <- function(type, id, source = NULL, paint = NULL, layout = NULL, ...) { + lay <- list( type = type, id = id, source = source, @@ -16,6 +16,8 @@ layer <- function(type, id, source = NULL, paint = NULL, layout = NULL, ...) { layout = layout ) |> purrr::compact() + class(lay) <- "MapLibreLayer" + return(lay) } From 474ace257ee9233e78687cf8de4074d5c2860773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Wed, 10 Jan 2024 23:55:27 +0100 Subject: [PATCH 8/8] update documentation --- examples/{earthquakes.R => layers.R} | 4 +++- examples/markers.R | 9 +++++++++ man/Marker.Rd | 21 +++++++++++++++++++++ man/add_marker.Rd | 14 ++++++++++++++ man/layer.Rd | 14 -------------- man/maplibre.Rd | 2 +- 6 files changed, 48 insertions(+), 16 deletions(-) rename examples/{earthquakes.R => layers.R} (91%) create mode 100644 examples/markers.R create mode 100644 man/Marker.Rd create mode 100644 man/add_marker.Rd delete mode 100644 man/layer.Rd diff --git a/examples/earthquakes.R b/examples/layers.R similarity index 91% rename from examples/earthquakes.R rename to examples/layers.R index 0c579ac..6d2a3f1 100644 --- a/examples/earthquakes.R +++ b/examples/layers.R @@ -5,7 +5,7 @@ earthquakes_source <- list( data = "https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson" ) -earthquakes_layer <- layer( +earthquakes_layer <- Layer( id = "earthquakes", type = "circle", source = earthquakes_source, @@ -14,3 +14,5 @@ earthquakes_layer <- layer( maplibre() |> add_layer(earthquakes_layer) + + diff --git a/examples/markers.R b/examples/markers.R new file mode 100644 index 0000000..13cb1e3 --- /dev/null +++ b/examples/markers.R @@ -0,0 +1,9 @@ +library(maplibre) +marker = Marker( + lngLat = c(9.5,51.31667), + popup = list(text = "This is a marker",options = list(closeButton = F)), + color= "darkred" +) + +maplibre(mapOptions(center = c(9.5,51.31667)),zoom = 4) |> + add_marker(marker) diff --git a/man/Marker.Rd b/man/Marker.Rd new file mode 100644 index 0000000..152aef8 --- /dev/null +++ b/man/Marker.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/marker.R +\name{Marker} +\alias{Marker} +\title{Create a Marker} +\usage{ +Marker(lngLat, popup, ...) +} +\description{ +Create a Marker +} +\examples{ +marker = Marker( + lngLat = c(9.5,51.31667), + popup = list(text = "This is a marker",options = list(closeButton = F)), + color= "darkred" +) + +maplibre(mapOptions(center = c(9.5,51.31667)),zoom = 4) |> + add_marker(marker) +} diff --git a/man/add_marker.Rd b/man/add_marker.Rd new file mode 100644 index 0000000..70cb38c --- /dev/null +++ b/man/add_marker.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/marker.R +\name{add_marker} +\alias{add_marker} +\title{Add a marker to map} +\usage{ +add_marker(.map, marker) +} +\arguments{ +\item{marker}{} +} +\description{ +Add a marker to map +} diff --git a/man/layer.Rd b/man/layer.Rd deleted file mode 100644 index 02ff37c..0000000 --- a/man/layer.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/layer.R -\name{layer} -\alias{layer} -\title{Create a layer} -\usage{ -layer(type, id, source = NULL, paint = NULL, layout = NULL, ...) -} -\arguments{ -\item{layout}{} -} -\description{ -Create a layer -} diff --git a/man/maplibre.Rd b/man/maplibre.Rd index 2517299..974b048 100644 --- a/man/maplibre.Rd +++ b/man/maplibre.Rd @@ -6,7 +6,7 @@ \usage{ maplibre( map_options = mapOptions(), - width = NULL, + width = "100\%", height = NULL, elementId = NULL, ...