This adds the compass
Based on code from "Auxiliary Cartographic Functions in R: North Arrow, Scale Bar, and Label with a Leader Arrow"
generate_compass_overlay(
x = 0.85,
y = 0.15,
size = 0.05,
text_size = 1,
bearing = 0,
heightmap = NULL,
width = NA,
height = NA,
resolution_multiply = 1,
color1 = NA,
color2 = NA,
text_color = NA,
border_color = "black",
border_width = 1,
compass_type = c("classic", "split_arrow", "triangle_circle", "split_arrow_ring"),
halo_color = NA,
halo_expand = 2,
halo_alpha = 1,
halo_offset = c(0, 0),
halo_blur = 0,
halo_edge_softness = 0.1
)Default NULL. The horizontal percentage across the map (measured from the bottom-left corner) where
the compass is located.
Default NULL. The vertical percentage across the map (measured from the bottom-left corner) where
the compass is located.
Default 0.05. Size of the compass, in percentage of the map size..
Default 1. Text size.
Default 0. Angle (in degrees) of north.
Default NULL. The original height map. Pass this in to extract the dimensions of the resulting
RGB image array automatically.
Default NA. Width of the resulting image array. Default the same dimensions as height map.
Default NA. Width of the resulting image array. Default the same dimensions as height map.
Default 1. If passing in heightmap instead of width/height, amount to
increase the resolution of the overlay, which should make lines/polygons finer.
Should be combined with add_overlay(rescale_original = TRUE) to ensure those added details are captured
in the final map.
Default NA, white except for compass_type == "triangle_circle" . Primary color of the compass.
Default NA, black. Secondary color of the symcompass.
Default black. Text color.
Default black. Border color of the scale bar.
Default 1. Width of the scale bar border.
Default "classic". Set to "split_arrow", "triangle_circle", or
"split_arrow_ring" to draw simple polygon north arrows that match the styles shown above.
Default NA, no halo. If a color is specified, the compass will be surrounded by a halo
of this color.
Default 1. Number of pixels to expand the halo.
Default 1. Transparency of the halo.
Default c(0,0). Horizontal and vertical offset to apply to the halo, in percentage of the image.
Default 1. Amount of blur to apply to the halo. Values greater than 30 won't result in further blurring.
Default 0.1. Width of the softened halo edge transition, in pixels.
Semi-transparent overlay with a compass.
if(run_documentation()) {
#Create the water palette
water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200)
bathy_hs = height_shade(montereybay, texture = water_palette)
#Generate flat water heightmap
mbay = montereybay
mbay[mbay < 0] = 0
base_map = mbay |>
height_shade() |>
add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) |>
add_shadow(lamb_shade(montereybay,zscale=50),0.3)
#Plot a compass
base_map |>
add_overlay(generate_compass_overlay(heightmap = montereybay)) |>
plot_map()
}
if(run_documentation()) {
#Change the position to be over the water
base_map |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15)) |>
plot_map()
}
if(run_documentation()) {
#Change the type
base_map |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15,
compass_type = "split_arrow")) |>
plot_map()
}
if(run_documentation()) {
#Change the type
base_map |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15,
compass_type = "split_arrow_ring")) |>
plot_map()
}
if(run_documentation()) {
#Change the type
base_map |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15,
compass_type = "triangle_circle")) |>
plot_map()
}
if(run_documentation()) {
#Change the text color for visibility
base_map |>
add_overlay(generate_compass_overlay(heightmap = montereybay, compass_type = "split_arrow",
x = 0.15, text_color="white")) |>
plot_map()
}
if(run_documentation()) {
#Alternatively, add a halo color to improve contrast
base_map |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15,
compass_type = "split_arrow", halo_color="white", halo_expand = 2)) |>
plot_map()
}
if(run_documentation()) {
#Change the color scheme
base_map |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15,
compass_type = "split_arrow", halo_color="white",
halo_expand = 2, color1 = "purple", color2 = "red")) |>
plot_map()
}
if(run_documentation()) {
#Remove the inner border
base_map |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15,
border_color=NA,compass_type = "split_arrow",
halo_color="white", halo_expand = 2,
color1 = "darkolivegreen4", color2 = "burlywood3")) |>
plot_map()
}
if(run_documentation()) {
#Change the size of the compass and text
base_map |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.75, y=0.75,
halo_color="white", halo_expand = 2,compass_type = "classic",
size=0.075*2, text_size = 1.25)) |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.45, y=0.45,
halo_color="white", halo_expand = 2,compass_type = "split_arrow_ring",
size=0.075)) |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15,
halo_color="white", halo_expand = 2,compass_type = "split_arrow",
size=0.075/2, text_size = 0.75)) |>
plot_map()
}
if(run_documentation()) {
#Change the bearing of the compass
base_map |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15,
halo_color="white", halo_expand = 2, bearing=30, compass_type = "classic",
size=0.075)) |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.35, y=0.15,
halo_color="white", halo_expand = 2, bearing=15, compass_type = "triangle_circle",
size=0.075)) |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.35,
halo_color="white", halo_expand = 2, bearing=-45, compass_type = "split_arrow_ring",
size=0.075)) |>
plot_map()
}
if(run_documentation()) {
#Create a drop shadow effect
base_map |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.15,
text_color="white", halo_alpha=0.7, halo_blur=3,
halo_color="black", halo_expand = 2, halo_offset = c(0.002,-0.002))) |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.35, y=0.15,
text_color="white", halo_alpha=0.7, halo_blur=3,
compass_type = "split_arrow",
halo_color="black", halo_expand = 2, halo_offset = c(0.002,-0.002))) |>
add_overlay(generate_compass_overlay(heightmap = montereybay, x = 0.15, y=0.35,
text_color="white", halo_alpha=0.2, halo_blur=8,
compass_type = "split_arrow_ring",
halo_color="white", halo_expand = 2)) |>
plot_map()
}