Skip to content

Commit

Permalink
Merge pull request #3 from eodaGmbH/nfr
Browse files Browse the repository at this point in the history
Add marker update documentation
  • Loading branch information
Friessn authored Jan 10, 2024
2 parents 8073f5e + 474ace2 commit f11fe94
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 31 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ Depends:
R (>= 2.10)
URL: https://eodagmbh.github.io/r-maplibregl/
Imports:
htmlwidgets
geojsonsf,
htmlwidgets,
purrr
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 4 additions & 2 deletions R/layer.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
#' @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,
paint = paint,
layout = layout
) |>
purrr::compact()
class(lay) <- "MapLibreLayer"
return(lay)
}


Expand Down
13 changes: 6 additions & 7 deletions R/maplibre.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
mapOptions <- function(style = basemaps$carto$dark_matter, ...) {
list(style = style, ...)
}


#' <Add Title>
#'
#' <Add Description>
Expand All @@ -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)
}
Expand All @@ -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
Expand Down
38 changes: 38 additions & 0 deletions R/marker.R
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 3 additions & 2 deletions examples/basemap.R
Original file line number Diff line number Diff line change
@@ -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)

4 changes: 3 additions & 1 deletion examples/earthquakes.R → examples/layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -14,3 +14,5 @@ earthquakes_layer <- layer(

maplibre() |>
add_layer(earthquakes_layer)


9 changes: 9 additions & 0 deletions examples/markers.R
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 21 additions & 0 deletions man/Marker.Rd

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

14 changes: 14 additions & 0 deletions man/add_marker.Rd

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

14 changes: 0 additions & 14 deletions man/layer.Rd

This file was deleted.

7 changes: 4 additions & 3 deletions man/maplibre.Rd

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

0 comments on commit f11fe94

Please sign in to comment.