Skip to content

Commit

Permalink
tm_compass working in view mode again, improved tm_logo #1038
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Feb 12, 2025
1 parent f16fe59 commit f910e66
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ S3method(tmapLeafletCompHeight,tm_compass)
S3method(tmapLeafletCompHeight,tm_credits)
S3method(tmapLeafletCompHeight,tm_legend_standard_landscape)
S3method(tmapLeafletCompHeight,tm_legend_standard_portrait)
S3method(tmapLeafletCompHeight,tm_logo)
S3method(tmapLeafletCompHeight,tm_minimap)
S3method(tmapLeafletCompHeight,tm_mouse_coordinates)
S3method(tmapLeafletCompHeight,tm_scalebar)
Expand All @@ -83,6 +84,7 @@ S3method(tmapLeafletCompPrepare,tm_compass)
S3method(tmapLeafletCompPrepare,tm_credits)
S3method(tmapLeafletCompPrepare,tm_legend_standard_landscape)
S3method(tmapLeafletCompPrepare,tm_legend_standard_portrait)
S3method(tmapLeafletCompPrepare,tm_logo)
S3method(tmapLeafletCompPrepare,tm_minimap)
S3method(tmapLeafletCompPrepare,tm_mouse_coordinates)
S3method(tmapLeafletCompPrepare,tm_scalebar)
Expand All @@ -92,6 +94,7 @@ S3method(tmapLeafletCompWidth,tm_compass)
S3method(tmapLeafletCompWidth,tm_credits)
S3method(tmapLeafletCompWidth,tm_legend_standard_landscape)
S3method(tmapLeafletCompWidth,tm_legend_standard_portrait)
S3method(tmapLeafletCompWidth,tm_logo)
S3method(tmapLeafletCompWidth,tm_minimap)
S3method(tmapLeafletCompWidth,tm_mouse_coordinates)
S3method(tmapLeafletCompWidth,tm_scalebar)
Expand All @@ -102,6 +105,7 @@ S3method(tmapLeafletLegPlot,tm_compass)
S3method(tmapLeafletLegPlot,tm_credits)
S3method(tmapLeafletLegPlot,tm_legend_standard_landscape)
S3method(tmapLeafletLegPlot,tm_legend_standard_portrait)
S3method(tmapLeafletLegPlot,tm_logo)
S3method(tmapLeafletLegPlot,tm_minimap)
S3method(tmapLeafletLegPlot,tm_mouse_coordinates)
S3method(tmapLeafletLegPlot,tm_scalebar)
Expand Down
2 changes: 1 addition & 1 deletion R/tmapGridComp_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ tmapGridLegPlot.tm_compass = function(comp, o, fH, fW) {
fill = c(dark, light)
} else if (comp$type=="radar") {
cr = c(.45, .42, .2, .17, .1)
LWD = round(convertWidth(unit(.01, "npc"), "points", valueOnly=TRUE)) * comp$lwd
LWD = (o$lineH * 24) * comp$lwd

cd = seq(1/8, 15/8, by=.25) * pi
cd2 = seq(1/4, 7/4, by=.5) * pi
Expand Down
33 changes: 32 additions & 1 deletion R/tmapLeafletComp_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ tmapLeafletCompWidth.tm_compass = function(comp, o) {

#' @export
tmapLeafletLegPlot.tm_compass = function(comp, lf, o) {
lf %>% leafem::addLogo(system.file(paste0("img/compass_", comp$type, ".png"), package = "tmap"), position = leaflet_pos(comp$position), width = 120, height = 120)
lf %>% leafem::addLogo(system.file(paste0("img/compass_", comp$type, ".png"), package = "tmap"), src = "local", position = leaflet_pos(comp$position), width = 120, height = 120)
}


Expand Down Expand Up @@ -206,3 +206,34 @@ tmapLeafletLegPlot.tm_minimap = function(comp, lf, o) {
lf2
}

#' @export
tmapLeafletCompPrepare.tm_logo = function(comp, o) {
comp$logo = lapply(comp$file, function(lf){
tmap_icons(lf)
})
comp$asp = vapply(comp$logo, function(lg) {
lg$iconWidth / lg$iconHeight
}, FUN.VALUE = numeric(1))
comp$show = TRUE
comp
}


#' @export
tmapLeafletCompHeight.tm_logo = function(comp, o) {
comp
}

#' @export
tmapLeafletCompWidth.tm_logo = function(comp, o) {
comp
}

#' @export
tmapLeafletLegPlot.tm_logo = function(comp, lf, o) {
for (i in 1:length(comp$logo)) {
lf = lf %>% leafem::addLogo(comp$logo[[i]]$iconUrl, src = "local", position = leaflet_pos(comp$position))
}
lf
}

3 changes: 1 addition & 2 deletions examples/tm_logo.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ tm_shape(World) +
tm_logo(c("https://www.r-project.org/logo/Rlogo.png",
system.file("help", "figures", "logo.png", package = "tmap"))) +
tm_logo("http://blog.kulikulifoods.com/wp-content/uploads/2014/10/logo.png",
height=5, position = c("left", "top")) +
tm_format("World")
height=5, position = c("left", "top"))
3 changes: 1 addition & 2 deletions man/tm_logo.Rd

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

2 changes: 2 additions & 0 deletions man/tm_scale_intervals.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/tm_seq.Rd

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

0 comments on commit f910e66

Please sign in to comment.