Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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: 0 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ jobs:
uses: rstudio/shiny-workflows/.github/workflows/website.yaml@v1
routine:
uses: rstudio/shiny-workflows/.github/workflows/routine.yaml@v1
with:
node-version: '12'
R-CMD-check:
uses: rstudio/shiny-workflows/.github/workflows/R-CMD-check.yaml@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ Imports:
magrittr,
methods,
png,
raster (>= 3.6.3),
RColorBrewer,
rlang,
scales (>= 1.0.0),
Expand All @@ -73,12 +72,13 @@ Suggests:
maps,
purrr,
R6,
raster (>= 3.6-3),
RJSONIO,
rmarkdown,
s2,
shiny (>= 1.0.0),
sp,
terra,
terra (>= 1.6-3),
testthat (>= 3.0.0)
Config/Needs/website: dplyr, ncdf4, rnaturalearth, tidyverse/tidytemplate
Config/testthat/edition: 3
Expand Down
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# leaflet (development version)

* `{leaflet}` no longer installs `{raster}` `{terra}` by default (@olivroy, #943). If you are using leaflet interactively, you will receive a prompt to install it.

# leaflet 2.2.3

* `{leaflet}` is now licensed under the MIT license (was GPL-2) (#958).
Expand All @@ -14,8 +16,6 @@

* Updated vignettes to replace `{sp}`/`{raster}` usage with `{sf}`/`{terra}` and their corresponding examples. (@jack-davison, #928)

* Updated vignettes to replace `{sp}`/`{raster}` usage with `{sf}`/`{terra}` and their corresponding examples. (@jack-davison, #928)

* `addProviderTiles()` will now error if the chosen `provider` does not match any currently loaded provider (by default, those in `providers`). This behaviour can be toggled off by setting the new `check` argument to `FALSE` (@jack-davison, #929)

# leaflet 2.2.2
Expand Down
25 changes: 15 additions & 10 deletions R/layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ epsg3857 <- "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y
#' @param method the method used for computing values of the new, projected raster image.
#' `"bilinear"` (the default) is appropriate for continuous data,
#' `"ngb"` - nearest neighbor - is appropriate for categorical data.
#' Ignored if `project = FALSE`. See [raster::projectRaster()] for details.
#' Ignored if `project = FALSE`. See [terra::project()] for details.
#' @param maxBytes the maximum number of bytes to allow for the projected image
#' (before base64 encoding); defaults to 4MB.
#' @param options a list of additional options, intended to be provided by
Expand All @@ -250,12 +250,12 @@ epsg3857 <- "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y
#' @seealso [addRasterLegend()] for an easy way to add a legend for a
#' SpatRaster with a color table.
#'
#' @examples
#' \donttest{library(raster)
#' @examplesIf rlang::is_installed("terra")
#' \donttest{
#'
#' r <- raster(xmn = -2.8, xmx = -2.79, ymn = 54.04, ymx = 54.05, nrows = 30, ncols = 30)
#' values(r) <- matrix(1:900, nrow(r), ncol(r), byrow = TRUE)
#' crs(r) <- CRS("+init=epsg:4326")
#' r <- terra::rast(xmin = -2.8, xmax = -2.79, ymin = 54.04, ymax = 54.05, nrows = 30, ncols = 30)
#' terra::values(r) <- matrix(1:900, nrow(r), ncol(r), byrow = TRUE)
#' terra::crs(r) <- "epsg:4326"
#'
#' pal <- colorNumeric("Spectral", domain = c(0, 1000))
#' leaflet() %>% addTiles() %>%
Expand Down Expand Up @@ -324,7 +324,7 @@ addRasterImage <- function(
#' @param layer the layer of the raster to target
#' @param ... additional arguments to pass through to [addLegend()]
#' @seealso [addRasterImage()]
#' @examplesIf interactive()
#' @examplesIf interactive() && rlang::is_installed("terra")
#'
#' library(terra)
#'
Expand All @@ -346,6 +346,7 @@ addRasterImage <- function(
#' @export
addRasterLegend <- function(map, x, layer = 1, ...) {
stopifnot(inherits(x, "SpatRaster"))
rlang::check_installed("terra (>= 1.6-3)")
stopifnot(length(layer) == 1 && layer > 0 && layer <= terra::nlyr(x))

# might as well do this here and only once. Subsetting would otherwise have
Expand Down Expand Up @@ -419,6 +420,8 @@ addRasterImage_RasterLayer <- function(
options = gridOptions(),
data = getMapData(map)
) {
rlang::check_installed("raster")

options$opacity <- opacity
options$attribution <- attribution

Expand All @@ -442,8 +445,8 @@ addRasterImage_RasterLayer <- function(

bounds <- raster::extent(
raster::projectExtent(
raster::projectExtent(x, crs = sp::CRS(epsg3857)),
crs = sp::CRS(epsg4326)
raster::projectExtent(x, crs = raster::crs(epsg3857)),
crs = raster::crs(epsg4326)
)
)

Expand Down Expand Up @@ -652,6 +655,7 @@ addRasterImage_SpatRaster <- function(
#' @export
projectRasterForLeaflet <- function(x, method) {
if (inherits(x, "SpatRaster")) {
rlang::check_installed("terra (>= 1.6-3)")
if (method == "ngb") {
method = "near"
}
Expand All @@ -661,10 +665,11 @@ projectRasterForLeaflet <- function(x, method) {
method = method
)
} else {
rlang::check_installed("raster")
raster_is_factor <- raster::is.factor(x)
projected <- raster::projectRaster(
x,
raster::projectExtent(x, crs = sp::CRS(epsg3857)),
raster::projectExtent(x, crs = raster::crs(epsg3857)),
method = method
)
# if data is factor data, make the result factors as well.
Expand Down
11 changes: 7 additions & 4 deletions R/leaflet.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ leafletSizingPolicy <- function(

#' Create a Leaflet map widget
#'
#' This function creates a Leaflet map widget using \pkg{htmlwidgets}. The
#' @description
#' * `leaflet()` creates a Leaflet map widget using \pkg{htmlwidgets}. The
#' widget can be rendered on HTML pages generated from R Markdown, Shiny, or
#' other applications.
#' * `leafletOptions()`: options for map creation
#' * `leafletCRS()`: class to create custom CRS.
#'
#' @details
#' The `data` argument is only needed if you are going to reference
#' variables in this object later in map layers. For example, `data` can be
#' a data frame containing columns `latitude` and `longitude`, then
Expand Down Expand Up @@ -152,13 +156,12 @@ mapOptions <- function(map, zoomToLimits = c("always", "first", "never")) {
#' @param minZoom Minimum zoom level of the map. Overrides any `minZoom` set on map layers.
#' @param maxZoom Maximum zoom level of the map. This overrides any `maxZoom` set on map layers.
#' @param crs Coordinate Reference System to use. Don't change this if you're not sure what it means.
#' @seealso [leafletCRS()] for creating a custom CRS.
#' @param worldCopyJump With this option enabled, the map tracks when you pan
#' to another "copy" of the world and seamlessly jumps to the original
#' one so that all overlays like markers and vector layers are still visible.
#' @param preferCanvas Whether leaflet.js Paths should be rendered on a Canvas renderer.
#' @param ... other options used for leaflet.js map creation.
#' @describeIn leaflet Options for map creation
#' @rdname leaflet
#' @seealso See <https://web.archive.org/web/20220702182250/https://leafletjs.com/reference-1.3.4.html#map-option> for details and more options.
#' @export
leafletOptions <- function(
Expand Down Expand Up @@ -200,7 +203,7 @@ crsClasses <- list("L.CRS.EPSG3857", "L.CRS.EPSG4326", "L.CRS.EPSG3395",
#' Proj4Leaflet will use this in the getSize method, otherwise
#' defaulting to Leaflet's default CRS size
#' @param tileSize DEPRECATED! Specify the tilesize in the [tileOptions()] argument.
#' @describeIn leaflet class to create a custom CRS
#' @rdname leaflet
#' @export
leafletCRS <- function(
crsClass = "L.CRS.EPSG3857",
Expand Down
2 changes: 1 addition & 1 deletion R/normalize-terra.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ polygonData.SpatVector <- function(obj) {

# helpers -----------------------------------------------------------------
check_crs_terra <- function(x) {
rlang::check_installed("terra")
rlang::check_installed("terra (>= 1.6-3)")
crs <- terra::crs(x)

# Don't have enough information to check
Expand Down
9 changes: 4 additions & 5 deletions inst/examples/geojson.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
library(leaflet)
library(sp)
#' <br/><br/>
#' The V8 part is simply to read the JSON embeded in the Javascript.<br/>
#' For a geojson file `jsonlite::fromfromJSON()` or `geojsonio::regeojson_read()` will do
#' For a geojson file `jsonlite::fromJSON()` or `geojsonio::geojson_read()` will do
#'
jsURL <- "https://rawgit.com/Norkart/Leaflet-MiniMap/master/example/local_pubs_restaurant_norway.js"
v8 <- V8::v8()
v8$source(jsURL)
geoJson <- geojsonio::as.json(v8$get("pubsGeoJSON"))

# This is the kicker, convert geojson to a Spatial object.
# This is the kicker, convert geojson to a sf object.
# This then allows us to use formulas in our markers, polygons etc.
spdf <- geojsonio::geojson_sp(geoJson)
spdf <- geojsonio::geojson_sf(geoJson)

icons <- awesomeIconList(
pub = makeAwesomeIcon(icon = "glass", library = "fa", markerColor = "red"),
Expand All @@ -34,7 +33,7 @@ leaflet() %>%
#' Another examples this time with polygons
url <- "https://www.partners-popdev.org/wp-content/themes/original-child/vendor/Geojson/States/Maharashtra.geojson"

mhSPDF <- geojsonio::geojson_read(url, what = "sp")
mhSPDF <- sf::st_read(url)

cols <- colorFactor(topo.colors(nrow(mhSPDF)), mhSPDF$NAME_2)

Expand Down
1 change: 0 additions & 1 deletion inst/examples/leaflet.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,3 @@ m %>% addCircleMarkers(~lng, ~lat, radius = ~size,
color = ~greens(value), fillOpacity = 0.5)

}

1 change: 1 addition & 0 deletions inst/examples/normalize.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# obsolete
library(leaflet)
library(sp)
library(maps)
Expand Down
4 changes: 2 additions & 2 deletions inst/examples/proj4Leaflet-PolarProjections.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ resolutions <- c(8192, 4096, 2048, 1024, 512, 256)
zoom <- 0
maxZoom <- 5

border <- geojsonio::geojson_read(system.file("examples/Seamask_medium_res_polygon.kml", package = "leaflet"), what = "sp")
points <- geojsonio::geojson_read(system.file("examples/Historic_sites_and_monuments_point.kml", package = "leaflet"), what = "sp")
border <- sf::st_read(system.file("examples/Seamask_medium_res_polygon.kml", package = "leaflet"))
points <- sf::st_read(system.file("examples/Historic_sites_and_monuments_point.kml", package = "leaflet"))

crsAntartica <- leafletCRS(
crsClass = "L.Proj.CRS",
Expand Down
12 changes: 7 additions & 5 deletions man/addRasterImage.Rd

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

2 changes: 1 addition & 1 deletion man/addRasterLegend.Rd

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

16 changes: 5 additions & 11 deletions man/leaflet.Rd

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

1 change: 0 additions & 1 deletion scripts/raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ plot(r - invn)
r <- raster(xmn = -60, xmx = -25, ymn = 70, ymx = 81, nrows = 30, ncols = 30)
set.seed(0)
values(r) <- matrix(sample(1:5, 900, replace = TRUE), nrow(r), ncol(r), byrow = TRUE)
# crs(r) <- CRS("+init=epsg:4326")
l <- function(method = "auto") {
leaflet() %>%
addTiles() %>%
Expand Down
6 changes: 5 additions & 1 deletion tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ create_square <- function(width = 2, lng = 0, lat = 0, hole = FALSE, type = sp::
}
}


expect_maps_equal <- function(m1, m2) {
attr(m1$x, "leafletData") <- NULL
attr(m2$x, "leafletData") <- NULL
expect_equal(m1, m2, ignore_function_env = TRUE, ignore_formula_env = TRUE)
}
7 changes: 0 additions & 7 deletions tests/testthat/test-normalize-2.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@

expect_maps_equal <- function(m1, m2) {
attr(m1$x, "leafletData") <- NULL
attr(m2$x, "leafletData") <- NULL
expect_equal(m1, m2, ignore_function_env = TRUE, ignore_formula_env = TRUE)
}

normalize_multipolygon <- function(df) {
# A multipolygon is a nested list of lng/lat data frames. Each data frame
# represents a single polygon (may be an island or a hole), that is, a series
Expand Down
Loading
Loading