Skip to content

Commit

Permalink
feat: rename make_img_leafpop to mapview_popup_img
Browse files Browse the repository at this point in the history
  • Loading branch information
elipousson committed Jul 19, 2023
1 parent 4a168ad commit bbb274f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ export(is_wgs84)
export(list_data_files)
export(lonlat_to_sfc)
export(make_filename)
export(make_img_leafpop)
export(make_sf_grid_list)
export(mapview_exif)
export(mapview_ext)
export(mapview_popup_img)
export(new_sf_list)
export(number_features)
export(number_sf)
Expand Down
61 changes: 33 additions & 28 deletions R/mapview_ext.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @inheritDotParams mapview::mapview
#' @param remove_na If TRUE and zcol is not `NULL`, filter `NA` values from the
#' zcol before passing to [mapview::mapview()]
#' @inheritParams make_img_leafpop
#' @inheritParams mapview_popup_img
#' @seealso
#' [mapview::mapview()]
#' @export
Expand Down Expand Up @@ -47,51 +47,60 @@ mapview_ext <- function(x, zcol = NULL, remove_na = FALSE, ...) {
mapview_exif <- function(path = NULL,
fileext = "jpeg",
popup = TRUE,
tooltip = FALSE,
images = NULL,
width = 320,
...) {
images <- images %||% read_sf_exif(
path = path,
fileext = fileext,
...
)

if (!is_sf(images)) {
images <-as_sf(images)
}
path = path,
fileext = fileext,
...
)

make_img_leafpop(
mapview_popup_img(
images = images,
width = width,
tooltip = tooltip,
popup = popup
)
}

#' @param popup If `TRUE`, add a popup image to a leaflet map; defaults `TRUE`.
#' @rdname mapview_ext
#' @param images A simple feature object with columns for the image path/url,
#' image width, and image height.
#' @name make_img_leafpop
#' @name mapview_popup_img
#' @rdname mapview_ext
#' @export
make_img_leafpop <- function(images,
popup = TRUE,
width = 320) {
check_installed("leaflet")
check_installed("leafpop")
mapview_popup_img <- function(images,
popup = TRUE,
tooltip = FALSE,
map = NULL,
width = 320,
...,
call = caller_env()) {
check_installed("leaflet", call = call)
check_installed("leafpop", call = call)

stopifnot(
all(has_name(images, c("img_width", "img_height"))),
any(has_name(images, c("path", "img_url"))),
is_sf(images)
)
if (!is_sf(images)) {
images <- as_sf(images, call = call)
}

leaflet_map <-
map <- map %||%
leaflet::addCircleMarkers(
leaflet::addTiles(leaflet::leaflet()),
data = images,
group = "images"
)

if (!popup) {
return(map)
}

stopifnot(
all(has_name(images, c("img_width", "img_height"))),
any(has_name(images, c("path", "img_url")))
)

if (has_name(images, "img_url")) {
image <- images$img_url
} else if (has_name(images, "path")) {
Expand All @@ -101,12 +110,8 @@ make_img_leafpop <- function(images,
asp <- images$img_width / images$img_height
height <- width / asp

if (!popup) {
return(leaflet_map)
}

leafpop::addPopupImages(
map = leaflet_map,
map = map,
image = image,
width = width,
height = height,
Expand Down
1 change: 0 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ reference:
- title: Helper functions for interactive mapping
contents:
- starts_with("mapview")
- '`make_img_leafpop`'
- starts_with("rdeck")
- '`editor_options`'
- title: Reference data for units, scales, and paper
Expand Down
15 changes: 13 additions & 2 deletions man/mapview_ext.Rd

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

0 comments on commit bbb274f

Please sign in to comment.