diff --git a/DESCRIPTION b/DESCRIPTION index cecb01c..dad687a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,8 +13,8 @@ Encoding: UTF-8 LazyData: true RoxygenNote: 7.2.3 Depends: - R (>= 4.1.0) -URL: https://eodagmbh.github.io/r-maplibregl/ + R (>= 4.1.0) +URL: https://eodagmbh.github.io/r-maplibregl, https://github.com/eodaGmbH/r-maplibregl Imports: geojsonsf, htmlwidgets, 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 df8a1d6..c214b08 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, ...) { list( @@ -25,7 +27,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) +} diff --git a/R/marker.R b/R/marker.R index ee3a88a..78eb576 100644 --- a/R/marker.R +++ b/R/marker.R @@ -14,7 +14,23 @@ Marker <- function(lngLat, popup = NULL, ...) { set_maplibre_class("MapLibreMarker") } -MarkerOptions <- function(...) { +#' Title +#' +#' @param ... +#' @param anchor +#' @param color +#' @param pitchAlignment +#' @param rotationAlignment +#' @param draggable +#' @param rotation +#' @param scale +#' +#' @return +#' @export +#' +#' @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) 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] + 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") 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) + + +}