Skip to content

Commit

Permalink
Merge pull request #6 from eodaGmbH/feature/add_layerprops
Browse files Browse the repository at this point in the history
Feature/add layerprops
  • Loading branch information
Friessn authored Jan 11, 2024
2 parents 385d9a5 + 4e0747d commit 890b357
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 4 deletions.
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.

0 comments on commit 890b357

Please sign in to comment.