View source: R/google_map_layer_polyline.R
update_polylines | R Documentation |
Updates specific attributes of polylines. Designed to be used in a shiny application.
update_polylines(
map,
data,
id,
stroke_colour = NULL,
stroke_weight = NULL,
stroke_opacity = NULL,
info_window = NULL,
layer_id = NULL,
palette = NULL,
legend = F,
legend_options = NULL
)
map |
a googleway map object created from |
data |
data frame containing the data to use in the layer. If Null, the
data passed into |
id |
string representing the column of |
stroke_colour |
either a string specifying the column of |
stroke_weight |
either a string specifying the column of |
stroke_opacity |
either a string specifying the column of |
info_window |
string specifying the column of data to display in an info window when a shape is clicked. |
layer_id |
single value specifying an id for the layer. Use this value to
distinguish between shape layers for when using any |
palette |
a function, or list of functions, that generates hex colours given a single number as an input. See details. |
legend |
either a logical indiciating if the legend(s) should be displayed, or a named list indicating which colour attributes should be included in the legend. |
legend_options |
A list of options for controlling the legend. |
Any polylines (as specified by the id
argument) that do not exist
in the data
passed into add_polylines()
will not be added to the
map. This function will only update the polylines that currently exist on
the map when the function is called.
## Not run:
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')
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.