-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.R
54 lines (49 loc) · 1.54 KB
/
map.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#' Create a MaplibreGL map widget
#' @param style A style object or URL to style json
#' @param width Width
#' @param height Height
#' @param element_id HTML Element ID
#' @param ... Additional options passed to maplibregl constructor
#' @importFrom htmlwidgets createWidget
#' @export
map <- function(style = openstreetmap(), width = NULL, height = NULL, element_id = NULL, ...) {
widget_data <- list(
props = list(style = style, ...),
calls = list()
)
# The `calls` element represents a list of methods defined in Typescript
# that are called by the underlying MaplibreGL Map object.
# These call functions need to be defined in the `methods.ts` file
htmlwidgets::createWidget(
name = "blaeu",
x = widget_data,
width = width,
height = height,
package = "blaeu",
elementId = element_id
)
}
#' Shiny bindings
#' @inheritParams htmlwidgets::shinyWidgetOutput
#' @importFrom htmlwidgets shinyWidgetOutput
#' @export
#' @rdname shiny
mapOutput <- function(outputId, width = "100%", height = "400px") {
htmlwidgets::shinyWidgetOutput(
outputId,
"map",
width,
height,
package = "blaeu"
)
}
#' @inheritParams htmlwidgets::shinyRenderWidget
#' @importFrom htmlwidgets shinyRenderWidget
#' @export
#' @rdname shiny
renderMap <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) {
expr <- substitute(expr)
}
htmlwidgets::shinyRenderWidget(expr, mapOutput, env, quoted = TRUE)
}