forked from IMERSS/xetthecum-storymap-scrolly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
community_map_script.R
66 lines (53 loc) · 2.54 KB
/
community_map_script.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
library(sf)
library(leaflet)
library(dplyr)
library(raster)
library(reshape2)
library(rjson)
library(scales)
library(stringr)
# Source dependencies
source("scripts/utils.R")
# import datasets
communityStyling <- timedFread("tabular_data/communityStyling.csv")
# set highlighting on one or more layers:
highlightedLayers <- c();
mx_community_map <- function () {
title <- "Community Connection";
boundingBox <- mx_read("spatial_data/vectors/ProjectBoundary") %>%
st_bbox() %>%
as.character();
# Plot map
sectionMap <- leaflet(options=list(mx_mapId="Community")) %>%
fitBounds(boundingBox[1],boundingBox[2],boundingBox[3],boundingBox[4], options = list(padding = c(-350,-350))) %>%
addProviderTiles(providers$CartoDB.Positron)
# loop through all the polygon layers and add them to the map
for (i in 1:nrow(communityStyling)) {
row <- communityStyling[i,]
# if the row isn't highlighted, add it to the map first
if (!(row$Layer %in% highlightedLayers)) {
sectionMap <- sectionMap %>% addPolygons(data = mx_read(paste("spatial_data/vectors/",row$Layer, sep="")),
fillColor = row$fillColor,
fillOpacity = as.numeric(row$fillOpacity),
stroke = TRUE,
color = row$outlineColor,
opacity = row$outlineOpacity,
weight = row$outlineWidth,
options = list(mx_layerId = row$Layer, className = row$ClassName))
};
# then if it should be highlighted, add it to the map. This is to ensure it's on top of the other layers.
if (row$Layer %in% highlightedLayers) {
sectionMap <- sectionMap %>% addPolygons(data = mx_read(paste("spatial_data/vectors/",row$Layer, sep="")),
fillColor = row$fillColor,
fillOpacity = as.numeric(row$fillOpacity),
stroke = TRUE,
color = "yellow",
opacity = 1,
weight = (row$outlineWidth+2),
options = list(mx_layerId = row$Layer, className = row$ClassName))
}
};
#Note that this statement is only effective in standalone R
print(sectionMap)
}
mx_community_map()