-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_zone_leaflet.R
More file actions
75 lines (43 loc) · 1.56 KB
/
map_zone_leaflet.R
File metadata and controls
75 lines (43 loc) · 1.56 KB
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
# Install and load the necessary packages
library(leaflet)
library(sf)
# Read your shapefile
# Replace 'path_to_shapefile' with the actual path to your shapefile
map_zones <- st_read("data/conus_mapzones_102611.shp")
# Transform the coordinate system to WGS84
map_zones <- st_transform(map_zones, crs = 4326)
# Create the leaflet map
leaflet(map_zones) %>%
addTiles() %>%
addPolygons(
fillColor = "transparent", # No fill
weight = 2,
opacity = 1,
color = "black", # Solid black border
label = ~ZONE_NUM, # Labels for ZONE_NUM attribute
labelOptions = labelOptions(
noHide = TRUE, # Always show labels
direction = "auto",
textOnly = TRUE,
style = list(
"color" = "black",
"font-weight" = "bold",
"font-size" = "12px"
)
),
popup = ~paste("Map Zone:", ZONE_NUM) # Popups for ZONE_NUM attribute
)
# Replace 'path_to_map_zones_shapefile' and 'path_to_additional_shapefile' with the actual paths to your shapefiles
map_zones <- st_read("data/conus_mapzones_102611.shp")
additional_shape <- st_read("data/ely_blm.shp")
map_zones <- st_transform(map_zones, crs = 4326)
additional_shape <- st_transform(additional_shape, crs = 4326)
# Create the tmap
tm_shape(map_zones) +
tm_borders(col = "black", lwd = 2) +
tm_text("ZONE_NUM", size = 1, col = "black", fontface = "bold") +
tm_shape(additional_shape) +
tm_borders(col = "green", lwd = 2) +
tm_fill(fill = "green", fill_alpha = 0.5) +
tm_view(bbox = st_bbox(additional_shape)) +
tm_layout(legend.show = FALSE)