From 402cf8f359500a315abbd3b94333f169e20703b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Thu, 11 Jan 2024 09:19:50 +0100 Subject: [PATCH 1/5] add github to pkgdown --- DESCRIPTION | 2 +- _pkgdown.yml | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6061899..420db4f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,7 +14,7 @@ LazyData: true RoxygenNote: 7.2.3 Depends: R (>= 2.10) -URL: https://eodagmbh.github.io/r-maplibregl/ +URL: https://eodagmbh.github.io/r-maplibregl, https://github.com/eodaGmbH/r-maplibregl Imports: geojsonsf, htmlwidgets, diff --git a/_pkgdown.yml b/_pkgdown.yml index b42b387..2a46d1d 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,4 +1,9 @@ url: https://eodagmbh.github.io/r-maplibregl/ template: bootstrap: 5 +navbar: + structure: + left: [intro, reference] + right: [search, github] + From 051e976f4cddc8dc3a6f42944f77b67cc0370ecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Thu, 11 Jan 2024 09:20:06 +0100 Subject: [PATCH 2/5] add layer functions --- NAMESPACE | 2 ++ R/layer.R | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 71ca3db..ca87a1b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,6 +7,8 @@ export(add_call) export(add_control) export(add_layer) export(add_marker) +export(add_popup) +export(add_tooltip) export(mapOptions) export(maplibre) export(maplibreOutput) diff --git a/R/layer.R b/R/layer.R index b5a8fb0..a453345 100644 --- a/R/layer.R +++ b/R/layer.R @@ -6,6 +6,8 @@ #' @param paint #' @param layout #' +#' @example examples/layers.R +#' #' @export Layer <- function(type, id, source = NULL, paint = NULL, layout = NULL, ...) { lay <- list( @@ -26,7 +28,39 @@ Layer <- function(type, id, source = NULL, paint = NULL, layout = NULL, ...) { #' @param .map #' @param layer #' +#' @example examples/layers.R #' @export add_layer <- function(.map, layer) { .map |> add_call("addLayer", layer) } + + +#' Add popup property to layer +#' +#' @param .map +#' @param layer_id +#' @param prop +#' +#' @return +#' @export +#' +#' @example examples/layers.R +add_popup <- function(.map, layer_id, prop){ + .map |> add_call("addPopup", layer_id, prop) +} + + +#' Title +#' +#' @param .map +#' @param layer_id +#' @param prop +#' +#' @return +#' @export +#' +#' @examples +#' @example examples/layers.R +add_tooltip <- function(.map, layer_id, prop){ + .map |> add_call("addTooltip", layer_id, prop) +} From b9442a5182f0d4de780962c1908b3bbcba2fce7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Thu, 11 Jan 2024 09:20:24 +0100 Subject: [PATCH 3/5] update MarkerOptions params --- R/marker.R | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/R/marker.R b/R/marker.R index 12c44f5..b45c79b 100644 --- a/R/marker.R +++ b/R/marker.R @@ -4,7 +4,7 @@ #' @param popup #' @export #' @example examples/markers.R -Marker <- function(lngLat, popup , ...) { +Marker <- function(lngLat, popup, ...) { mark <- list( lngLat = lngLat, popup = popup, @@ -18,12 +18,20 @@ Marker <- function(lngLat, popup , ...) { #' Title #' #' @param ... +#' @param anchor +#' @param color +#' @param pitchAlignment +#' @param rotationAlignment +#' @param draggable +#' @param rotation +#' @param scale #' #' @return #' @export #' -#' @examples -MarkerOptions <- function(...){ +#' @example examples/markers.R +MarkerOptions <- function(anchor = NULL, color = NULL, pitchAlignment = NULL, rotationAlignment = NULL, + draggable = NULL, rotation = NULL, scale = NULL,...){ 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)})) From 5c4ff3e0a54ca82fddf854fa808fb442ad868225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Thu, 11 Jan 2024 09:20:34 +0100 Subject: [PATCH 4/5] update documentation --- man/Layer.Rd | 20 ++++++++++++++++++++ man/MarkerOptions.Rd | 11 +++++++++++ man/add_layer.Rd | 20 ++++++++++++++++++++ man/add_popup.Rd | 34 ++++++++++++++++++++++++++++++++++ man/add_tooltip.Rd | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 man/add_popup.Rd create mode 100644 man/add_tooltip.Rd diff --git a/man/Layer.Rd b/man/Layer.Rd index 29f912d..d626361 100644 --- a/man/Layer.Rd +++ b/man/Layer.Rd @@ -12,3 +12,23 @@ Layer(type, id, source = NULL, paint = NULL, layout = NULL, ...) \description{ Create a layer } +\examples{ +library(maplibre) + +earthquakes_source <- list( + type = "geojson", + data = "https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson" +) + +earthquakes_layer <- Layer( + id = "earthquakes", + type = "circle", + source = earthquakes_source, + paint = list("circle-color" = "yellow", "circle-radius" = 2) +) + +maplibre() |> + add_layer(earthquakes_layer) + + +} diff --git a/man/MarkerOptions.Rd b/man/MarkerOptions.Rd index 0ec4eb1..867dd21 100644 --- a/man/MarkerOptions.Rd +++ b/man/MarkerOptions.Rd @@ -12,3 +12,14 @@ MarkerOptions(...) \description{ Title } +\examples{ +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/add_layer.Rd b/man/add_layer.Rd index 024ff4b..797d787 100644 --- a/man/add_layer.Rd +++ b/man/add_layer.Rd @@ -12,3 +12,23 @@ add_layer(.map, layer) \description{ Add a layer to map } +\examples{ +library(maplibre) + +earthquakes_source <- list( + type = "geojson", + data = "https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson" +) + +earthquakes_layer <- Layer( + id = "earthquakes", + type = "circle", + source = earthquakes_source, + paint = list("circle-color" = "yellow", "circle-radius" = 2) +) + +maplibre() |> + add_layer(earthquakes_layer) + + +} diff --git a/man/add_popup.Rd b/man/add_popup.Rd new file mode 100644 index 0000000..8095fa9 --- /dev/null +++ b/man/add_popup.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/layer.R +\name{add_popup} +\alias{add_popup} +\title{Add popup property to layer} +\usage{ +add_popup(.map, layer_id, prop) +} +\arguments{ +\item{prop}{} +} +\description{ +Add popup property to layer +} +\examples{ +library(maplibre) + +earthquakes_source <- list( + type = "geojson", + data = "https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson" +) + +earthquakes_layer <- Layer( + id = "earthquakes", + type = "circle", + source = earthquakes_source, + paint = list("circle-color" = "yellow", "circle-radius" = 2) +) + +maplibre() |> + add_layer(earthquakes_layer) + + +} diff --git a/man/add_tooltip.Rd b/man/add_tooltip.Rd new file mode 100644 index 0000000..aff84f6 --- /dev/null +++ b/man/add_tooltip.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/layer.R +\name{add_tooltip} +\alias{add_tooltip} +\title{Title} +\usage{ +add_tooltip(.map, layer_id, prop) +} +\arguments{ +\item{prop}{} +} +\description{ +Title +} +\examples{ +library(maplibre) + +earthquakes_source <- list( + type = "geojson", + data = "https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson" +) + +earthquakes_layer <- Layer( + id = "earthquakes", + type = "circle", + source = earthquakes_source, + paint = list("circle-color" = "yellow", "circle-radius" = 2) +) + +maplibre() |> + add_layer(earthquakes_layer) + + +} From 0de040e11223bc74091d024c1966b4627fe0bc1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Frie=C3=9F?= Date: Thu, 11 Jan 2024 09:20:41 +0100 Subject: [PATCH 5/5] update layer example --- examples/layers.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/layers.R b/examples/layers.R index 6d2a3f1..fda7975 100644 --- a/examples/layers.R +++ b/examples/layers.R @@ -12,7 +12,15 @@ earthquakes_layer <- Layer( paint = list("circle-color" = "yellow", "circle-radius" = 2) ) +# Adds a tooltip that appears when hovering over it + maplibre() |> - add_layer(earthquakes_layer) + add_layer(earthquakes_layer) |> + add_tooltip("earthquakes", prop = "mag") + +# Adds a popup that appears when clicking on the layer +maplibre() |> + add_layer(earthquakes_layer) |> + add_popup("earthquakes", prop = "mag")