-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogbook_map.R
81 lines (58 loc) · 3.46 KB
/
logbook_map.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#' Logged dives map
#'
#' Creates a leaflet map of the logged dives
#'
#' This function creates a leaflet map to visualize the geographical coverage of the logbook together with some information on each dive such as
#' Bottom Time, Max Depth, Date and Divesite
#'
#' @param path directory location where the files will be read from or written into
#'
#' @author Ruben Perez Perez
#'
#' @import leaflet
#' @import htmltools
#'
#' @return Returns a map.
#'
#' @export
#.........................................................
logbook_map <- function (path = getwd()){
if(dir.exists(paste0(path, "/divewatchr_data"))){
load('divewatchr_data/scuba_clean.RData')
load('divewatchr_data/scuba_map.RData')
}
### MAKING MAP
#--------------------
# Labels use scuba_clean because it is not an sf object
labs <- lapply(seq(nrow(scuba_clean)), function(i) {
paste0('<p>', '<b> <font size = 3> Dive Log </font> </b>' ,'</p>',
'<p>', '<b> Date: </b>' ,scuba_clean[i, "eventDate"], '</p>',
'<b> Divesite: </b>', scuba_clean[i, "locationID"], ', ',
scuba_clean[i, "locality"],'</p><p>',
'<b> Max Depth: </b>', scuba_clean[i, "maximumDepthInMeters"], ' metres', '</p><p>',
'<b> Bottom Time: </b>', scuba_clean[i, "bottomTime"], ' minutes', '</p><p>',
'<b> Water Temperature: </b>', scuba_clean[i, "waterTemperature"], ' degrees celsius', '</p>')
})
# Leaflet uses scuba_map because it is an sf object
m <- leaflet(data = scuba_map)
m %>% addProviderTiles('Esri.WorldImagery') %>% # can also try CartoDB.VoyagerOnlyLabels OR CartoDB.PositronOnlyLabels in next line
addProviderTiles("CartoDB.DarkMatterOnlyLabels") %>% addMarkers(~as.numeric(decimalLongitude),
~as.numeric(decimalLatitude),
popup = ~as.character(paste0("Dive type: ", diveType,
ifelse(is.na(platformType), "", paste0(" - ", platformType)),
ifelse(is.na(diveType_3), "", paste0(" - ", diveType_3)))),
popupOptions = popupOptions(), # Change size, opacity, etc
label = lapply(labs, HTML),
labelOptions = labelOptions(direction = "left",
opacity = 0.9,
style = list(
"font-style" = "italic",
"box-shadow" = "3px 3px rgba(0,0,0,0.25)",
"font-size" = "14px",
"border-color" = "rgba(0,0,0,0.5)"
)),
clusterOptions = markerClusterOptions()
)
}
# can also use
# mapview::mapview(scuba_map)