Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add layerprops #6

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions R/layer.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#' @param paint
#' @param layout
#'
#' @example examples/layers.R
#'
#' @export
Layer <- function(type, id, source = NULL, paint = NULL, layout = NULL, ...) {
list(
Expand All @@ -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)
}
18 changes: 17 additions & 1 deletion R/marker.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
url: https://eodagmbh.github.io/r-maplibregl/
template:
bootstrap: 5
navbar:
structure:
left: [intro, reference]
right: [search, github]


10 changes: 9 additions & 1 deletion examples/layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

20 changes: 20 additions & 0 deletions man/Layer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions man/MarkerOptions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/add_layer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/add_popup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/add_tooltip.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.