if (FALSE) {
map_key <- 'your_api_key'
## coordinate columns
## plot polylines using default attributes
df <- tram_route
df$id <- c(rep(1, 27), rep(2, 28))
df$colour <- c(rep("#00FFFF", 27), rep("#FF00FF", 28))
google_map(key = map_key) %>%
add_polylines(data = df, lat = 'shape_pt_lat', lon = 'shape_pt_lon',
stroke_colour = "colour", id = 'id')
## specify width and colour attributes to update
df_update <- data.frame(id = c(1,2),
width = c(3,10),
colour = c("#00FF00", "#DCAB00"))
google_map(key = map_key) %>%
add_polylines(data = df, lat = 'shape_pt_lat', lon = 'shape_pt_lon',
stroke_colour = "colour", id = 'id') %>%
update_polylines(data = df_update, id = 'id', stroke_weight = "width",
stroke_colour = 'colour')
## encoded polylines
pl <- sapply(unique(df$id), function(x){
encode_pl(lat = df[ df$id == x , 'shape_pt_lat'], lon = df[ df$id == x, 'shape_pt_lon'])
})
df <- data.frame(id = c(1, 2), polyline = pl)
df_update <- data.frame(id = c(1,2),
width = c(3,10),
var = c("a","b"))
google_map(key = map_key) %>%
add_polylines(data = df, polyline = 'polyline')
google_map(key = map_key) %>%
add_polylines(data = df, polyline = 'polyline') %>%
update_polylines(data = df_update, id = 'id', stroke_weight = "width",
stroke_colour = 'var')
}
Run the code above in your browser using DataLab