SymbolixAU / mapdeck
1

2
#' Add sf
3
#'
4
#' Adds an sf object to the map.
5
#'
6
#' @inheritParams add_polygon
7
#' @param ... other argumetns passed to one of the plotting layers. See details
8
#'
9
#' @details
10
#' The plotting layer is determined by the type of sf geometries.
11
#'
12
#' \itemize{
13
#'   \item{POINT and MULTIPOINT objects will call \link{add_scatterplot}}
14
#'   \item{LINESTRING and MULTILINESTRING objects will call \link{add_path}}
15
#'   \item{POLYGON and MULTIPOLYGON objects will call \link{add_polygon}}
16
#'   \item{GEOMETRY objects will call \link{add_geojson}}
17
#' }
18
#'
19
#' @export
20
add_sf <- function( map, data = get_map_data(map), ... ) {
21

22 0
	if (!inherits(data, "sf")) stop("mapdeck - expecting sf object")
23

24 0
	geom <- data[[ attr( data, "sf_column" ) ]]
25 0
	cls <- substr( class(geom)[1], 5, nchar(class(geom)[1]))
26

27 0
	if( cls %in% c("POINT","MULTIPOINT")) {
28 0
		add_scatterplot( map = map, data = data, ... )
29 0
	} else if ( cls %in% c("LINESTRING", "MULTILINESTRING")) {
30 0
		add_path( map = map, data = data, ... )
31 0
	} else if ( cls %in% c("POLYGON", "MULTIPOLYGON")) {
32 0
		add_polygon( map = map, data = data, ... )
33
	} else {
34 0
		add_geojson( map = map, data = data, ... )
35
	}
36
}

Read our documentation on viewing source code .

Loading