The GeoJson Layer takes in GeoJson formatted data and renders it as interactive polygons, lines and points
add_geojson( map, data = get_map_data(map), layer_id = NULL, stroke_colour = NULL, stroke_opacity = NULL, stroke_width = NULL, dash_size = NULL, dash_gap = NULL, fill_colour = NULL, fill_opacity = NULL, radius = NULL, elevation = NULL, extruded = FALSE, light_settings = list(), legend = F, legend_options = NULL, legend_format = NULL, auto_highlight = FALSE, tooltip = NULL, highlight_colour = "#AAFFFFFF", palette = "viridis", na_colour = "#808080FF", line_width_units = c("metres", "pixels"), line_width_scale = 1, line_width_min_pixels = 0, elevation_scale = 1, point_radius_scale = 1, point_radius_min_pixels = 1, update_view = TRUE, focus_layer = FALSE, digits = 6, transitions = NULL )
map | a mapdeck map object |
---|---|
data | data to be used in the layer. Can be a url to GeoJSON |
layer_id | single value specifying an id for the layer. Use this value to distinguish between shape layers of the same type. Layers with the same id are likely to conflict and not plot correctly |
stroke_colour | column of an |
stroke_opacity | column of an |
stroke_width | column of an |
dash_size | size of each dash, relative to the width of the stroke |
dash_gap | size of the gap between dashes, relative to the width of the stroke |
fill_colour | column of an |
fill_opacity | column of an |
radius | radius of points in meters. Default 1. See details |
elevation | elevation of polygons. Default 0. See details |
extruded | logical indicating if polygons should extrude from the map.
If |
light_settings | list of light setting parameters. See light_settings |
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. A legend is only shown if you supply one of the colour arguments (fill or stroke) |
legend_options | A list of options for controlling the legend. |
legend_format | A list containing functions to apply to legend values. See section legend |
auto_highlight | logical indicating if the shape under the mouse should auto-highlight |
tooltip | variable of |
highlight_colour | hex string colour to use for highlighting. Must contain the alpha component. |
palette | string or matrix. String will be one of |
na_colour | hex string colour to use for NA values |
line_width_units | The units of the line width, one of 'meters', 'pixels'. When zooming in and out, meter sizes scale with the base map, and pixel sizes remain the same on screen. |
line_width_scale | The line width multiplier that multiplied to all lines, including the LineString and MultiLineString features and also the outline for Polygon and MultiPolygon features if the stroked attribute is true |
line_width_min_pixels | The minimum line width in pixels. |
elevation_scale | Elevation multiplier. The final elevation is calculated by elevationScale * getElevation(d). elevationScale is a handy property to scale all polygon elevation without updating the data |
point_radius_scale | A global radius multiplier for all points. |
point_radius_min_pixels | The minimum radius in pixels. |
update_view | logical indicating if the map should update the bounds to include this layer |
focus_layer | logical indicating if the map should update the bounds to only include this layer |
digits | number of digits for rounding coordinates |
transitions | list specifying the duration of transitions. |
The transitions argument lets you specify the time it will take for the shapes to transition from one state to the next. Only works in an interactive environment (Shiny) and on WebGL-2 supported browsers and hardware.
The time is in milliseconds
Available transitions for geojson
list( fill_colour = 0, stroke_colour = 0, stroke_width = 0, elevation = 0, radius = 0 )
If using a GeoJSON string, and you do not suppply one of the colouring arguments, the
function will look for these fields inside the properties
field of the Geojson
fill_colour
fill_colour
fillColour
fill_color
fillColor
fill
stroke_colour
stroke_colour
strokeColour
stroke_color
strokeColor
stroke
line_colour
lineColour
line_color
lineColor
line
stroke_width
stroke_width
strokeWdith
line_width
lineWidth
width
elevation
radius
These colour values should be valid hex-colour strings.
If you do provide values for the colouring arguments, the function will assume
you want to use specific fields in the geojson for colouring. However, if you only supply a
fill_colour
value, the function will not automatically detect the stroke_colour
(and vice versa)
If the data
is a simple feature object, the geometry column is automatically
detected. If the sf object contains more than one geometry column and you want to use a specific one,
you'll need to set the active geometry using sf::st_geometry( x ) <- "your_column"
,
where "your_column"
is the name of the column you're activating. See ?sf::st_geometry
The legend_options
can be used to control the appearance of the legend.
This should be a named list, where the names are one of
css - a string of valid css
for controlling the appearance of the legend
title - a string to use for the title of the legend
digits - number to round the legend values to
If the layer allows different fill and stroke colours, you can use different options for each. See examples in add_arc.
The legend_format
can be used to control the format of the values in the legend.
This should be a named list, where the names are one of
fill_colour
stroke_colour
depending on which type of colouring the layer supports.
The list elements must be functions to apply to the values in the legend.
# \donttest{ ## You need a valid access token from Mapbox key <- 'abc' set_token( key ) ## Not supplying colouring arguments, the function will try and find them in the GeoJSON mapdeck( , location = c(145, -37.9) , zoom = 8 , style = mapdeck_style("dark") , pitch = 35 ) %>% add_geojson( data = geojson , auto_highlight = TRUE )#> Error in add_geojson(., data = geojson, auto_highlight = TRUE): unused argument (auto_highlight = TRUE)## only supplying values to use for fill, the stroke will be default mapdeck( , location = c(145, -37.9) , zoom = 8 , style = mapdeck_style("dark") , pitch = 35 ) %>% add_geojson( data = geojson , fill_colour = "random" )#> Error in add_geojson(., data = geojson, fill_colour = "random"): unused argument (fill_colour = "random")mapdeck( , location = c(145, -37.9) , zoom = 8 , style = mapdeck_style("dark") , pitch = 35 ) %>% add_geojson( data = geojson , fill_colour = "random" , stroke_colour = "random" )#> Error in add_geojson(., data = geojson, fill_colour = "random", stroke_colour = "random"): unused arguments (fill_colour = "random", stroke_colour = "random")mapdeck( , location = c(145, -37.9) , zoom = 8 , style = mapdeck_style("dark") , pitch = 35 ) %>% add_geojson( data = geojson , fill_colour = "random" , stroke_colour = "random" , elevation = 300 )#> Error in add_geojson(., data = geojson, fill_colour = "random", stroke_colour = "random", elevation = 300): unused arguments (fill_colour = "random", stroke_colour = "random", elevation = 300)#> #>#>#> #>sf <- geojsonsf::geojson_sf( geojson ) sf$width <- sample(1:100, size = nrow(sf), replace = TRUE) sf$elevation <- sample(100:1000, size = nrow(sf), replace = T) geo <- geojsonsf::sf_geojson( sf ) mapdeck( , location = c(145, -37.9) , zoom = 8 , style = mapdeck_style("dark") , pitch = 35 ) %>% add_geojson( data = geo )#> Error in google_dispatch(map, method, google_map = { x = map$x$calls if (is.null(x)) x = list() n = length(x) x[[n + 1]] = list(functions = method, args = args) map$x$calls = x map}, google_map_update = { invoke_remote(map, method, args)}): Invalid map parameter# }