Skip to content

Commit

Permalink
Make interactive map smoother.
Browse files Browse the repository at this point in the history
  • Loading branch information
darrennorris committed Jul 7, 2024
1 parent 98c3c07 commit 238bbaf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Suggests:
knitr,
kableExtra,
leaflet,
leafem,
leafem,
htmltools,
dplyr,
rmarkdown
VignetteBuilder: knitr
Expand Down
15 changes: 12 additions & 3 deletions vignettes/Interactive-map.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ library(leafem)
library(sf)
library(knitr)
library(kableExtra)
library(htmltools)
```
Use the interactive map below to check population changes. Zoom in to see
where *Podocnemis unilfilis* is Endangered based on IUCN Redlist criteria - A3bd.
Expand All @@ -46,6 +47,10 @@ points_bau4326 <- points_bau |>
filter(row_number() %% 5 == 1) |> st_as_sf(crs = 3395) |> st_transform(4326)
levels(points_bau4326$flag_50_42y) <- c("No", "Yes")
points_bau4326_low <- points_bau4326
# label to plot with circle
points_bau4326_low$label <- paste("Prot = ", points_bau4326_low$Protected,
"Acc = ", points_bau4326_low$Accessible,
"Free = ", points_bau4326_low$Free.flowing)
# colour palette
leaf_pal <- colorFactor(
palette = c("#7274C1", "#A3720E"),
Expand Down Expand Up @@ -78,10 +83,14 @@ basemap <- leaflet::leaflet() %>%
position = "topleft"
)
# interactive map
leaflet::leaflet(points_bau4326_low) |>
addTiles() |>
# interactive map. Optins added to make panning smoother....
leaflet::leaflet(points_bau4326_low,
options = leafletOptions(preferCanvas = TRUE)) |>
addTiles(options = tileOptions(
updateWhenZooming = FALSE, # map won't update tiles until zoom is done
updateWhenIdle = TRUE)) |>
addCircles(color = ~leaf_pal(flag_50_42y),
popup = ~htmlEscape(label),
group = "points_bau4326_low"
) |>
addCircleMarkers(color = ~leaf_pal(flag_50_42y),
Expand Down

0 comments on commit 238bbaf

Please sign in to comment.