add_geojson: Add Geojson

Description Usage Arguments transitions Raw Geojson data legend Examples

View source: R/map_layer_geojson.R

Description

The GeoJson Layer takes in GeoJson formatted data and renders it as interactive polygons, lines and points

Usage

 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
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
)

Arguments

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 sf object, or field inside a GeoJSON property to use for colour

stroke_opacity

column of an sf object, or field inside a GeoJSON property to use for opacity

stroke_width

column of an sf object, or field inside a GeoJSON property to use for width (in meters)

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 sf object, or field inside a GeoJSON property to use for colour

fill_opacity

column of an sf object, or field inside a GeoJSON property to use for opacity

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 TRUE, stroke_colour for polygons is ignored

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 data containing text or HTML to render as a tooltip. Only works on sf objects.

highlight_colour

hex string colour to use for highlighting. Must contain the alpha component.

palette

string or matrix. String will be one of colourvalues::colour_palettes(). A matrix must have at least 5 rows, and 3 or 4 columns of values between [0, 255], where the 4th column represents the alpha. You can use a named list to specify a different palette for different colour options (where available), e.g. list(fill_colour = "viridis", stroke_colour = "inferno")

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.

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 )

Raw Geojson

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

stroke_colour

stroke_width

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)

data

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

legend

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

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

depending on which type of colouring the layer supports.

The list elements must be functions to apply to the values in the legend.

Examples

 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
62
63
64
65
66
67
68
69
## 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
 )

## 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"
 )

mapdeck(
 , location = c(145, -37.9)
 , zoom = 8
 , style = mapdeck_style("dark")
 , pitch = 35
) %>%
 add_geojson(
   data = geojson
   , 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
 )

## putting elevation and width values onto raw GeoJSON
library(geojsonsf)
sf <- geojsonsf::geojson_sf( geojson )
sf$width <- sample(1:100, size = nrow(sf), replace = TRUE)
sf$elevation <- sample(100:1000, size = nrow(sf), replace = TRUE)
geo <- geojsonsf::sf_geojson( sf )

mapdeck(
 , location = c(145, -37.9)
 , zoom = 8
 , style = mapdeck_style("dark")
 , pitch = 35
) %>%
 add_geojson(
   data = geo
 )

mapdeck documentation built on Sept. 4, 2020, 9:07 a.m.