# NOT RUN {
map_key <- 'your_api_key'
## polygon with a hole - Bermuda triangle
## using one row per polygon, and a list-column of encoded polylines
pl_outer <- encode_pl(lat = c(25.774, 18.466,32.321),
lon = c(-80.190, -66.118, -64.757))
pl_inner <- encode_pl(lat = c(28.745, 29.570, 27.339),
lon = c(-70.579, -67.514, -66.668))
df <- data.frame(id = c(1, 1),
polyline = c(pl_outer, pl_inner),
stringsAsFactors = FALSE)
df <- aggregate(polyline ~ id, data = df, list)
google_map(key = map_key, height = 800) %>%
add_polygons(data = df, polyline = "polyline")
## the same polygon, but using an 'id' to specify the polygon
df <- data.frame(id = c(1,1),
polyline = c(pl_outer, pl_inner),
stringsAsFactors = FALSE)
google_map(key = map_key, height = 800) %>%
add_polygons(data = df, polyline = "polyline", id = "id")
## the same polygon, specified using coordinates, and with a second independent
## polygon
df <- data.frame(myId = c(1,1,1,1,1,1,2,2,2),
lineId = c(1,1,1,2,2,2,1,1,1),
lat = c(26.774, 18.466, 32.321, 28.745, 29.570, 27.339, 22, 23, 22),
lon = c(-80.190, -66.118, -64.757, -70.579, -67.514, -66.668, -50, -49, -51),
colour = c(rep("#00FF0F", 6), rep("#FF00FF", 3)),
stringsAsFactors = FALSE)
google_map(key = map_key) %>%
add_polygons(data = df, lat = 'lat', lon = 'lon', id = 'myId', pathId = 'lineId',
fill_colour = 'colour')
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab