forked from healthinnovation/harmonize-visor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebmap.qmd
257 lines (237 loc) · 8.26 KB
/
webmap.qmd
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
---
page-layout: full
comments: false
css: css/map.css
---
```{r}
#| column: screen
#| echo: false
#| message: false
#| warning: false
#| out-height: 100vh
#| out-width: 100%
library(tidyverse)
library(leaflet)
library(htmltools)
library(leaflet.extras)
library(viridis)
library(sf)
processed_path <- "data/processed/"
ccpp_filename <- "ccpp-10km-strata-sample.csv"
ccpp_filepath <- fs::path(processed_path, ccpp_filename)
ccpp <- read_csv(ccpp_filepath) %>%
st_as_sf(coords = c("lng","lat"), crs = 4326)
innovalab <- ccpp %>%
filter(group != "DIRESA")
diresa <- ccpp %>%
filter(group == "DIRESA")
raw_path <- "data/processed/"
areas_filename <- "tracking_area_by_communities.gpkg"
areas_filepath <- fs::path(raw_path, areas_filename)
areas <- st_read(areas_filepath, quiet = TRUE)
metheoro_filename <- "metheorological_station_location.gpkg"
metheoro_filepath <- fs::path(raw_path, metheoro_filename)
metheoro <- st_read(metheoro_filepath, quiet = TRUE) %>%
st_cast("POINT")
drone_1km_filename <- "flying_mission_1km2.gpkg"
drone_1km_filepath <- fs::path(raw_path, drone_1km_filename)
drone_1km <- st_read(drone_1km_filepath, quiet = TRUE) %>%
st_transform(4326)
# my_icons <- iconList(
# circle <- makeIcon(
# iconUrl = "https://raw.githubusercontent.com/bzdjahna/legend_img/41d55a5a0a304e4faa6b6458a0a319aad72e1586/1circle.svg",
# iconWidth = 18,
# iconHeight = 18
# ),
# square <- makeIcon(
# iconUrl = "https://raw.githubusercontent.com/bzdjahna/legend_img/41d55a5a0a304e4faa6b6458a0a319aad72e1586/3square.svg",
# iconWidth = 18,
# iconHeight = 18
# ),
# triangle <- makeIcon(
# iconUrl = "https://raw.githubusercontent.com/bzdjahna/legend_img/41d55a5a0a304e4faa6b6458a0a319aad72e1586/2triangle.svg",
# iconWidth = 18, iconHeight = 18
# ),
# start <- makeIcon(
# iconUrl = "https://raw.githubusercontent.com/bzdjahna/legend_img/41d55a5a0a304e4faa6b6458a0a319aad72e1586/4star.svg",
# iconWidth = 18,
# iconHeight = 18
# )
# )
s10_pal <- colorFactor(
palette = viridis(n = 4),
domain = ccpp$hc_group_4
)
meteo_pal <- colorFactor(
palette = c("blue","red"),
domain = c("INSTITUCIÓN EDUCATIVA","PUESTOS DE SALUD O POSTAS DE SALUD")
)
map_layers <- function() {
#number of groups
k <- c(
"Innovalab villages",
"Diresa villages",
"Cluster 1",
"Cluster 2",
"Cluster 3",
"Cluster 4",
"Perimeter qfield",
"Metheorological station",
"Flying mission with a spaced of 1km hv"
)
#base map
map <- leaflet() %>%
addTiles(group = "Open.Street.Map") %>%
addProviderTiles(provider = providers$CartoDB,group = "CartoDB") %>%
addProviderTiles(provider = providers$CartoDB.DarkMatter,group = "CartoDB.DarkMatter") %>%
addProviderTiles(provider = providers$Esri.WorldImagery,group = "Esri.WorldImagery") %>%
setView(lng = -73.44775,lat = -4.08754,zoom = 10)
#loop through all groups and add a layer one at a time
for (i in 1:length(k)) {
if("Innovalab villages" == k[[i]]){
map <- map %>%
addPulseMarkers(
data = innovalab,
icon = makePulseIcon(heartbeat = 0.5),
group = k[[i]],
popup = ~paste0(
"<center><h3> 🏕️",innovalab$nomcp,"</h3></center>","<hr>",
"- ⛈️Precipitation: ",round(innovalab$pr_avg,4),"<br>",
"- 💧Runoff: ",round(innovalab$ro_avg,4),"<br>",
"- ♒Soil mousture: ", round(innovalab$soil_avg,4),"<br>",
"- 🌡️Maximum temperature: ",round(innovalab$tmmx_avg,4),"<br>",
"- 🧊Minimum temperature: ",round(innovalab$tmmn_avg,4),"<br>",
"- 💦Evapotranspiration: ", round(innovalab$etp_avg,4),"<br>",
"- ☁️Humidity: ", round(innovalab$humidity_avg,4),"<br>",
"- 🌳🪓Deforestation: ", round(innovalab$def_avg,4),"<br>",
"- 🛣️Global Superficie Human: ",round(innovalab$ghsl_avg,4),"<br>",
"- ✨Nigth lights: ", round(innovalab$ln_avg,4),"<br>",
"- 🏙Population: ",round(innovalab$pop_avg,4)
))
}
if("Diresa villages"==k[[i]]){
map <- map %>%
addPulseMarkers(
data = diresa,
icon = makePulseIcon(heartbeat = 0.5),
group = k[[i]],
popup = ~paste0(
"<center><h3> 🏕️",diresa$nomcp,"</h3></center>","<hr>",
"- ⛈️Precipitation: ",round(diresa$pr_avg,4),"<br>",
"- 💧Runoff: ",round(diresa$ro_avg,4),"<br>",
"- ♒Soil mousture: ", round(diresa$soil_avg,4),"<br>",
"- 🌡️Maximum temperature: ",round(diresa$tmmx_avg,4),"<br>",
"- 🧊Minimum temperature: ",round(diresa$tmmn_avg,4),"<br>",
"- 💦Evapotranspiration: ", round(diresa$etp_avg,4),"<br>",
"- ☁️Humidity: ", round(diresa$humidity_avg,4),"<br>",
"- 🌳🪓Deforestation: ", round(diresa$def_avg,4),"<br>",
"- 🛣️Global Superficie Human: ",round(diresa$ghsl_avg,4),"<br>",
"- ✨Nigth lights: ", round(diresa$ln_avg,4),"<br>",
"- 🏙Population: ",round(diresa$pop_avg,4)
))
}
if("Cluster 1" == k[[i]]){
map <- map %>%
addCircleMarkers(
data = ccpp %>% filter(hc_group_4 == 1),
group = k[[i]],
popup = paste0(
"<h3>","🏡",ccpp$population_center,"</h3>"),
fillColor = ~s10_pal(hc_group_4),
stroke = 0,
fillOpacity = 0.6
)
}
if ("Cluster 2" == k[[i]]){
map <- map %>%
addCircleMarkers(
data = ccpp %>% filter(hc_group_4 == 2),
group = k[[i]],
popup = paste0(
"<h3>","🏡",ccpp$population_center,"</h3>"),
fillColor = ~s10_pal(hc_group_4),
stroke = 0,
fillOpacity = 0.6
)
}
if ("Cluster 3" == k[[i]]){
map <- map %>%
addCircleMarkers(
data = ccpp %>% filter(hc_group_4 == 3),
group = k[[i]],
popup = paste0(
"<h3>","🏡",ccpp$population_center,"</h3>"),
fillColor = ~s10_pal(hc_group_4),
stroke = 0,
fillOpacity = 0.6
)
}
if ("Cluster 4" == k[[i]]){
map <- map %>%
addCircleMarkers(
data = ccpp %>% filter(hc_group_4 == 4),
group = k[[i]],
popup = paste0(
"<h3>","🏡",ccpp$population_center,"</h3>"),
fillColor = ~s10_pal(hc_group_4),
stroke = 0,
fillOpacity = 0.6
)
}
if("Perimeter qfield" == k[[i]]){
map <- map %>%
addPolygons(
data = areas,
stroke = 2,
fillOpacity = 0.8,
fillColor = "orange",
color = "orange",
opacity = 1,
popup = paste0(
"<h3>","🏡",areas$village,"</h3>","<hr>",
"- Area-Ha: ",round(areas$area_ha,4),"<br>",
"- Area-km2: ",round(areas$area_km2,4)),
group = k[[i]]
)
}
if("Metheorological station" == k[[i]]){
map <- map %>%
addCircleMarkers(
data = metheoro,
group = k[[i]],
popup = paste0(
"<h3>","🏡",metheoro$clasificacion,"</h3>"),
stroke = 0,
fillColor = ~meteo_pal(clasificacion),
fillOpacity = 0.6
)
}
if("Flying mission with a spaced of 1km hv" == k[[i]]){
map <- map %>%
addPolygons(
data = drone_1km,
stroke = 2,
fillOpacity = 0,
color = "#073b4c",
opacity = 1,
popup = paste0(
"<h3>","<img src='https://user-images.githubusercontent.com/23284899/209403801-c37d62d5-051c-49c5-a935-944f11df9b34.png' width='25px' align='center'> ",drone_1km$village,"</h3>","<hr>",
"- Area-Ha: ",round(drone_1km$area_ha,2),"<br>",
"- Area-km2: ",round(drone_1km$area_km2,2)),
group = k[[i]]
)
}
}
#create layer control
map <- map %>%
addLayersControl(
baseGroups = c("CartoDB","CartoDB.DarkMatter","Open.Street.Map","Esri.WorldImagery"),
overlayGroups = k[c(1:length(k))],
options = layersControlOptions(collapsed = FALSE)
) %>%
hideGroup(as.character(k[c(0:length(k))])) #hide all groups except the 1st one
map
}
#plot the map
map_layers()
```