diff --git a/DESCRIPTION b/DESCRIPTION index 917e302..62d94bf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,7 +20,7 @@ Imports: methods Encoding: UTF-8 LazyData: true -RoxygenNote: 6.1.1 +RoxygenNote: 7.2.3 Suggests: knitr, rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index e17cb26..d41ab21 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/deps.R b/R/deps.R index a6b227a..8318fc6 100644 --- a/R/deps.R +++ b/R/deps.R @@ -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) + } + } + +} diff --git a/R/fog_terrain.R b/R/fog_terrain.R new file mode 100644 index 0000000..03308da --- /dev/null +++ b/R/fog_terrain.R @@ -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(...)) +} + diff --git a/R/mapboxer.R b/R/mapboxer.R index d88a4bf..a2b7fce 100644 --- a/R/mapboxer.R +++ b/R/mapboxer.R @@ -27,6 +27,8 @@ 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, @@ -34,7 +36,7 @@ mapboxer <- function(source = NULL, style = basemaps$Carto$dark_matter, ..., height = height, package = "mapboxer", elementId = element_id, - dependencies = use_deps("mapbox-gl") + dependencies = use_deps(mb_version) ) } @@ -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 diff --git a/examples/vector-layer-filled-polygons.R b/examples/vector-layer-filled-polygons.R index a9ab4a8..f086d82 100644 --- a/examples/vector-layer-filled-polygons.R +++ b/examples/vector-layer-filled-polygons.R @@ -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!") diff --git a/inst/htmlwidgets/deps.yaml b/inst/htmlwidgets/deps.yaml index b6c5a2f..7f69a3b 100644 --- a/inst/htmlwidgets/deps.yaml +++ b/inst/htmlwidgets/deps.yaml @@ -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 diff --git a/man/add_circle_layer.Rd b/man/add_circle_layer.Rd index 52f04a3..83cb300 100644 --- a/man/add_circle_layer.Rd +++ b/man/add_circle_layer.Rd @@ -4,14 +4,26 @@ \alias{add_circle_layer} \title{Add a circle layer to the map} \usage{ -add_circle_layer(map, source = NULL, filter = NULL, - circle_blur = NULL, circle_color = NULL, circle_opacity = NULL, - circle_pitch_alignment = NULL, circle_pitch_scale = NULL, - circle_radius = NULL, circle_sort_key = NULL, - circle_stroke_color = NULL, circle_stroke_opacity = NULL, - circle_stroke_width = NULL, circle_translate = NULL, - circle_translate_anchor = NULL, visibility = TRUE, popup = NULL, - id = "circle-layer") +add_circle_layer( + map, + source = NULL, + filter = NULL, + circle_blur = NULL, + circle_color = NULL, + circle_opacity = NULL, + circle_pitch_alignment = NULL, + circle_pitch_scale = NULL, + circle_radius = NULL, + circle_sort_key = NULL, + circle_stroke_color = NULL, + circle_stroke_opacity = NULL, + circle_stroke_width = NULL, + circle_translate = NULL, + circle_translate_anchor = NULL, + visibility = TRUE, + popup = NULL, + id = "circle-layer" +) } \arguments{ \item{map}{A \link{mapboxer} object.} diff --git a/man/add_fill_layer.Rd b/man/add_fill_layer.Rd index eadb12d..c3bfa09 100644 --- a/man/add_fill_layer.Rd +++ b/man/add_fill_layer.Rd @@ -4,12 +4,22 @@ \alias{add_fill_layer} \title{Add a fill layer to the map} \usage{ -add_fill_layer(map, source = NULL, filter = NULL, - fill_antialias = TRUE, fill_color = NULL, fill_opacity = NULL, - fill_outline_color = NULL, fill_pattern = NULL, - fill_sort_key = NULL, fill_translate = NULL, - fill_translate_anchor = NULL, visibility = TRUE, popup = NULL, - id = "fill-layer") +add_fill_layer( + map, + source = NULL, + filter = NULL, + fill_antialias = TRUE, + fill_color = NULL, + fill_opacity = NULL, + fill_outline_color = NULL, + fill_pattern = NULL, + fill_sort_key = NULL, + fill_translate = NULL, + fill_translate_anchor = NULL, + visibility = TRUE, + popup = NULL, + id = "fill-layer" +) } \arguments{ \item{map}{A \link{mapboxer} object.} diff --git a/man/add_filter_control.Rd b/man/add_filter_control.Rd index 32594a0..9f4d19f 100644 --- a/man/add_filter_control.Rd +++ b/man/add_filter_control.Rd @@ -4,8 +4,14 @@ \alias{add_filter_control} \title{Add a filter control to the map} \usage{ -add_filter_control(map, layer_id, filter = NULL, pos = NULL, - rows = 1, cols = 20) +add_filter_control( + map, + layer_id, + filter = NULL, + pos = NULL, + rows = 1, + cols = 20 +) } \arguments{ \item{map}{A \link{mapboxer} object.} diff --git a/man/add_line_layer.Rd b/man/add_line_layer.Rd index a6b209f..e8d78f0 100644 --- a/man/add_line_layer.Rd +++ b/man/add_line_layer.Rd @@ -4,14 +4,30 @@ \alias{add_line_layer} \title{Add a line layer to the map} \usage{ -add_line_layer(map, source = NULL, filter = NULL, line_blur = NULL, - line_cap = NULL, line_color = NULL, line_dasharray = NULL, - line_gap_width = NULL, line_gradient = NULL, line_join = NULL, - line_miter_limit = NULL, line_offset = NULL, line_opacity = NULL, - line_pattern = NULL, line_round_limit = NULL, line_sort_key = NULL, - line_translate = NULL, line_translate_anchor = NULL, - line_width = NULL, visibility = NULL, popup = NULL, - id = "line-layer") +add_line_layer( + map, + source = NULL, + filter = NULL, + line_blur = NULL, + line_cap = NULL, + line_color = NULL, + line_dasharray = NULL, + line_gap_width = NULL, + line_gradient = NULL, + line_join = NULL, + line_miter_limit = NULL, + line_offset = NULL, + line_opacity = NULL, + line_pattern = NULL, + line_round_limit = NULL, + line_sort_key = NULL, + line_translate = NULL, + line_translate_anchor = NULL, + line_width = NULL, + visibility = NULL, + popup = NULL, + id = "line-layer" +) } \arguments{ \item{map}{A \link{mapboxer} object.} diff --git a/man/add_mouse_position_control.Rd b/man/add_mouse_position_control.Rd index 44847e7..6ee374e 100644 --- a/man/add_mouse_position_control.Rd +++ b/man/add_mouse_position_control.Rd @@ -4,8 +4,12 @@ \alias{add_mouse_position_control} \title{Add a mouse position control to the map} \usage{ -add_mouse_position_control(map, mustache_template = NULL, pos = NULL, - css_text = NULL) +add_mouse_position_control( + map, + mustache_template = NULL, + pos = NULL, + css_text = NULL +) } \arguments{ \item{map}{A \link{mapboxer} object.} diff --git a/man/as_mapbox_source.Rd b/man/as_mapbox_source.Rd index d9584ab..31291fc 100644 --- a/man/as_mapbox_source.Rd +++ b/man/as_mapbox_source.Rd @@ -11,8 +11,7 @@ as_mapbox_source(data, ...) \method{as_mapbox_source}{json}(data, ...) -\method{as_mapbox_source}{data.frame}(data, lng = "lng", lat = "lat", - ...) +\method{as_mapbox_source}{data.frame}(data, lng = "lng", lat = "lat", ...) \method{as_mapbox_source}{sf}(data, ...) } diff --git a/man/basemap_raster_style.Rd b/man/basemap_raster_style.Rd index c26ed53..3e3aecc 100644 --- a/man/basemap_raster_style.Rd +++ b/man/basemap_raster_style.Rd @@ -4,8 +4,10 @@ \alias{basemap_raster_style} \title{Create a raster style} \usage{ -basemap_raster_style(tiles = stamen_raster_tiles("terrain"), - attribution = NULL) +basemap_raster_style( + tiles = stamen_raster_tiles("terrain"), + attribution = NULL +) } \arguments{ \item{tiles}{A list of tile URLs.} diff --git a/man/basemaps.Rd b/man/basemaps.Rd index 913f356..0c4dd0b 100644 --- a/man/basemaps.Rd +++ b/man/basemaps.Rd @@ -4,7 +4,9 @@ \name{basemaps} \alias{basemaps} \title{A list of basemap style URLs} -\format{An object of class \code{list} of length 2.} +\format{ +An object of class \code{list} of length 2. +} \usage{ basemaps } diff --git a/man/mapboxer.Rd b/man/mapboxer.Rd index be6de3d..22ab53e 100644 --- a/man/mapboxer.Rd +++ b/man/mapboxer.Rd @@ -4,9 +4,15 @@ \alias{mapboxer} \title{Create a mapboxer widget} \usage{ -mapboxer(source = NULL, style = basemaps$Carto$dark_matter, ..., - width = NULL, height = NULL, element_id = NULL, - token = Sys.getenv("MAPBOX_API_TOKEN")) +mapboxer( + source = NULL, + style = basemaps$Carto$dark_matter, + ..., + width = NULL, + height = NULL, + element_id = NULL, + token = Sys.getenv("MAPBOX_API_TOKEN") +) } \arguments{ \item{source}{A \link{mapbox_source} that is added to the map with the ID \code{MAPBOXER}.} diff --git a/man/mapboxer_use_v2.Rd b/man/mapboxer_use_v2.Rd new file mode 100644 index 0000000..3b76d2d --- /dev/null +++ b/man/mapboxer_use_v2.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/deps.R +\name{mapboxer_use_v2} +\alias{mapboxer_use_v2} +\title{Switch between Mapbox GL JS v1 or v2 in a mapboxer project} +\usage{ +mapboxer_use_v2(use_v2) +} +\arguments{ +\item{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.} +} +\value{ +Returns the vale of \code{use_v2} invisibly. +} +\description{ +Switch between Mapbox GL JS v1 or v2 in a mapboxer project +} +\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" +) + +} +} diff --git a/man/mapboxer_use_version.Rd b/man/mapboxer_use_version.Rd new file mode 100644 index 0000000..95c0e48 --- /dev/null +++ b/man/mapboxer_use_version.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/deps.R +\name{mapboxer_use_version} +\alias{mapboxer_use_version} +\title{Switch between Mapbox GL JS versions in a mapboxer project} +\usage{ +mapboxer_use_version(version = c("mapbox-gl", "mapbox-gl2", "mapbox-gl3")) +} +\arguments{ +\item{version}{The version to use} +} +\value{ +Returns the value of \code{version} invisibly. +} +\description{ +Switch between Mapbox GL JS versions in a mapboxer project +} +\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" +) + +} +} diff --git a/man/motor_vehicle_collisions_nyc.Rd b/man/motor_vehicle_collisions_nyc.Rd index 65c1a5f..f17e7f6 100644 --- a/man/motor_vehicle_collisions_nyc.Rd +++ b/man/motor_vehicle_collisions_nyc.Rd @@ -4,7 +4,8 @@ \name{motor_vehicle_collisions_nyc} \alias{motor_vehicle_collisions_nyc} \title{Motor Vehicle Collisions in NYC} -\format{A data frame with 1601 rows and 6 variables, +\format{ +A data frame with 1601 rows and 6 variables, where each row is a Motor Vehicle Collision: \describe{ \item{date}{occurrence date of collision} @@ -13,7 +14,8 @@ \item{lat}{longitude coordinate for Global Coordinate System, WGS 1984, decimal degrees (EPSG 4326)} \item{injured}{number of persons injured} \item{killed}{number of persons killed} -}} +} +} \source{ \url{https://opendata.cityofnewyork.us/} } diff --git a/man/reexports.Rd b/man/reexports.Rd index 0dbb135..827b8e0 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -12,6 +12,6 @@ These objects are imported from other packages. Follow the links below to see their documentation. \describe{ - \item{magrittr}{\code{\link[magrittr]{\%>\%}}, \code{\link[magrittr]{\%<>\%}}} + \item{magrittr}{\code{\link[magrittr:compound]{\%<>\%}}, \code{\link[magrittr:pipe]{\%>\%}}} }} diff --git a/man/set_data.Rd b/man/set_data.Rd index 4081636..87c1ccf 100644 --- a/man/set_data.Rd +++ b/man/set_data.Rd @@ -14,8 +14,7 @@ set_data(map, data, source_id = NULL, ...) \method{set_data}{json}(map, data, source_id = NULL, ...) -\method{set_data}{data.frame}(map, data, source_id = NULL, lng = "lng", - lat = "lat", ...) +\method{set_data}{data.frame}(map, data, source_id = NULL, lng = "lng", lat = "lat", ...) \method{set_data}{sf}(map, data, source_id, ...) } diff --git a/man/set_fog.Rd b/man/set_fog.Rd new file mode 100644 index 0000000..553009a --- /dev/null +++ b/man/set_fog.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fog_terrain.R +\name{set_fog} +\alias{set_fog} +\title{Set the fog properties for a map} +\usage{ +set_fog(map, ...) +} +\arguments{ +\item{map}{A \link{mapboxer} object.} + +\item{...}{Optional arguments, see \url{https://docs.mapbox.com/mapbox-gl-js/api/map/#map#setfog}.} +} +\description{ +Set the fog properties for a map +} diff --git a/man/set_layer_properties.Rd b/man/set_layer_properties.Rd index bae1025..38f3306 100644 --- a/man/set_layer_properties.Rd +++ b/man/set_layer_properties.Rd @@ -24,8 +24,8 @@ Update layer properties } \section{Functions}{ \itemize{ -\item \code{set_paint_property}: Update a paint property of a layer. +\item \code{set_paint_property()}: Update a paint property of a layer. -\item \code{set_layout_property}: Update a layout property of a layer. -}} +\item \code{set_layout_property()}: Update a layout property of a layer. +}} diff --git a/man/set_terrain.Rd b/man/set_terrain.Rd new file mode 100644 index 0000000..7df291e --- /dev/null +++ b/man/set_terrain.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fog_terrain.R +\name{set_terrain} +\alias{set_terrain} +\title{Set the terrain properties for a map} +\usage{ +set_terrain(map, terrain_source, exaggeration = 1.5, ...) +} +\arguments{ +\item{map}{A \link{mapboxer} object.} + +\item{terrain_source}{A Mapbox source of type 'raster-dem'} + +\item{exaggeration}{The exaggeration factor} + +\item{...}{Optional arguments, see \url{https://docs.mapbox.com/mapbox-gl-js/example/add-terrain/}.} +} +\description{ +Set the terrain properties for a map +}