Skip to content
Open
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Imports:
methods
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
RoxygenNote: 7.2.3
Suggests:
knitr,
rmarkdown,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ export(mapbox_source)
export(mapboxer)
export(mapboxerOutput)
export(mapboxer_proxy)
export(mapboxer_use_v2)
export(mapboxer_use_version)
export(renderMapboxer)
export(set_data)
export(set_filter)
export(set_fog)
export(set_layout_property)
export(set_paint_property)
export(set_style)
export(set_terrain)
export(set_view_state)
export(stamen_raster_tiles)
export(update_mapboxer)
Expand Down
100 changes: 100 additions & 0 deletions R/deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,103 @@ add_deps <- function(widget, deps) {
widget$dependencies <- c(widget$dependencies, deps)
widget
}


#' Switch between Mapbox GL JS v1 or v2 in a mapboxer project
#'
#' @param use_v2 If \code{TRUE}, mapboxer will use Mapbox GL JS version 2, which includes new features (such as Globe view and non-Mercator projections) but is less permissively licensed than Mapbox GL JS v1. Please review the Mapbox terms of service at https://www.mapbox.com/legal/tos/ for more information.
#'
#' @return Returns the vale of \code{use_v2} invisibly.
#' @export
#' @examples \dontrun{
#'
#' library(mapboxer)
#' mapboxer_use_v2(TRUE)
#'
#' # Globe view is only available in V2
#' mapboxer(
#' center = c(-73.9165, 40.7114),
#' style = basemaps$Mapbox$streets_v11,
#' zoom = 2,
#' projection = "globe"
#' )
#'
#' }
mapboxer_use_v2 <- function(use_v2) {

current_opt <- getOption("mapbox_version", default = "mapbox-gl")

if (use_v2) {

if (current_opt != "mapbox-gl2") {
options(mapbox_version = "mapbox-gl2")
message("Using Mapbox GL JS v2.\nPlease review the Mapbox terms of service for version 2\nat https://www.mapbox.com/legal/tos/.")
invisible(use_v2)

}

} else {
if (current_opt != "mapbox-gl") {
options(mapbox_version = "mapbox-gl")
message("Using Mapbox GL JS v1.")
invisible(use_v2)
}
}

}


#' Switch between Mapbox GL JS versions in a mapboxer project
#'
#' @param version The version to use
#'
#' @return Returns the value of \code{version} invisibly.
#' @export
#' @examples \dontrun{
#'
#' library(mapboxer)
#' mapboxer_use_version("mapbox-gl3")
#'
#' # Globe view is only available in V2
#' mapboxer(
#' center = c(-73.9165, 40.7114),
#' style = basemaps$Mapbox$streets_v11,
#' zoom = 2,
#' projection = "globe"
#' )
#'
#' }
mapboxer_use_version <- function(version = c("mapbox-gl", "mapbox-gl2", "mapbox-gl3")) {

version <- match.arg(version)

current_opt <- getOption("mapbox_version", default = "mapbox-gl")

if (version == "mapbox-gl2") {

if (current_opt != "mapbox-gl2") {
options(mapbox_version = "mapbox-gl2")
message("Using Mapbox GL JS v2.\nPlease review the Mapbox terms of service for version 2\nat https://www.mapbox.com/legal/tos/.")
invisible(version)

}

} else if (version == "mapbox-gl3") {

if (current_opt != "mapbox-gl3") {
options(mapbox_version = "mapbox-gl3")
message("Using Mapbox GL JS v3.\nPlease review the Mapbox terms of service for version 3\nat https://www.mapbox.com/legal/tos/.")
invisible(version)

}


} else {
if (current_opt != "mapbox-gl") {
options(mapbox_version = "mapbox-gl")
message("Using Mapbox GL JS v1.")
invisible(version)
}
}

}
19 changes: 19 additions & 0 deletions R/fog_terrain.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' Set the fog properties for a map
#' @param map A \link{mapboxer} object.
#' @param ... Optional arguments, see \url{https://docs.mapbox.com/mapbox-gl-js/api/map/#map#setfog}.
#' @export
set_fog <- function(map, ...) {
invoke_method(map, "setFog", options = list(...))
}

#' Set the terrain properties for a map
#' @param map A \link{mapboxer} object.
#' @param terrain_source A Mapbox source of type 'raster-dem'
#' @param exaggeration The exaggeration factor
#' @param ... Optional arguments, see \url{https://docs.mapbox.com/mapbox-gl-js/example/add-terrain/}.
#' @export
set_terrain <- function(map, terrain_source, exaggeration = 1.5, ...) {
invoke_method(map, "setTerrain", source = terrain_source,
exaggeration = exaggeration, options = list(...))
}

14 changes: 12 additions & 2 deletions R/mapboxer.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ mapboxer <- function(source = NULL, style = basemaps$Carto$dark_matter, ...,
accessToken = token
)

mb_version <- getOption("mapbox_version", "mapbox-gl")

htmlwidgets::createWidget(
name = "mapboxer",
x = widget_data,
width = width,
height = height,
package = "mapboxer",
elementId = element_id,
dependencies = use_deps("mapbox-gl")
dependencies = use_deps(mb_version)
)
}

Expand All @@ -54,7 +56,15 @@ mapboxer <- function(source = NULL, style = basemaps$Carto$dark_matter, ...,
#' @example examples/api-reference/shiny.R
#' @export
mapboxerOutput <- function(outputId, width = "100%", height = "400px") {
htmlwidgets::shinyWidgetOutput(outputId, "mapboxer", width, height, package = "mapboxer")

mb_version <- getOption("mapbox_version", "mapbox-gl")

htmltools::attachDependencies(
htmlwidgets::shinyWidgetOutput(outputId, "mapboxer", width, height, package = "mapboxer"),
use_deps(mb_version),
append = TRUE
)

}

#' @rdname mapboxer-shiny
Expand Down
3 changes: 2 additions & 1 deletion examples/vector-layer-filled-polygons.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ layer_style <- list(
mapboxer(
style = basemaps$Carto$positron,
center = c(0, 0),
projection = "globe",
zoom = 1
) %>%
add_source(vector_src, id = SRC_ID) %>%
add_layer(layer_style)
add_layer(layer_style, popup = "Hiya!")
18 changes: 17 additions & 1 deletion inst/htmlwidgets/deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,27 @@ mapbox-gl:
stylesheet: "mapbox-gl.css"
all_files: false
package: "mapboxer"
mapbox-gl2:
name: "mapbox-gl"
version: "2.11.0"
src:
href: "https://api.mapbox.com/mapbox-gl-js/v2.11.0"
script: "mapbox-gl.js"
stylesheet: "mapbox-gl.css"
all_files: false
mapbox-gl3:
name: "mapbox-gl"
version: "3.0.0"
src:
href: "https://api.mapbox.com/mapbox-gl-js/v3.0.0-beta.1"
script: "mapbox-gl.js"
stylesheet: "mapbox-gl.css"
all_files: false
mapbox-gl-draw:
name: "mapbox-gl-draw"
version: "1.2.0"
src:
href: "https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.2.0/"
href: "https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.2.0"
script: "mapbox-gl-draw.js"
stylesheet: "mapbox-gl-draw.css"
all_files: false
28 changes: 20 additions & 8 deletions man/add_circle_layer.Rd

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

22 changes: 16 additions & 6 deletions man/add_fill_layer.Rd

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

10 changes: 8 additions & 2 deletions man/add_filter_control.Rd

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

32 changes: 24 additions & 8 deletions man/add_line_layer.Rd

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

8 changes: 6 additions & 2 deletions man/add_mouse_position_control.Rd

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

3 changes: 1 addition & 2 deletions man/as_mapbox_source.Rd

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

6 changes: 4 additions & 2 deletions man/basemap_raster_style.Rd

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

4 changes: 3 additions & 1 deletion man/basemaps.Rd

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

Loading