SymbolixAU / mapdeck
1
mapdeckLoader3dTilesDependency <- function() {
2 0
	list(
3
		## https://unpkg.com/@loaders.gl/3d-tiles@2.2.3/dist/dist.min.js
4 0
		createHtmlDependency(
5 0
			name = "loader_3dtiles",
6 0
			version = "2.2.3",
7 0
			src = system.file("htmlwidgets/lib/", package = "mapdeck"),
8 0
			script = c("loader_3dtiles.min.js"),
9 0
			all_files =  FALSE
10
		)
11
	)
12
}
13

14
mapdeckLoaderIS3Dependency <- function() {
15 0
	list(
16
		## https://unpkg.com/@loaders.gl/i3s@2.2.3/dist/dist.min.js
17 0
		createHtmlDependency(
18 0
			name = "loader_i3s",
19 0
			version = "2.2.3",
20 0
			src = system.file("htmlwidgets/lib/", package = "mapdeck"),
21 0
			script = c("loader_i3s.min.js"),
22 0
			all_files =  FALSE
23
		)
24
	)
25
}
26

27
mapdeckTile3DDependency <- function() {
28 0
	list(
29 0
		createHtmlDependency(
30 0
			name = "tile3d",
31 0
			version = "1.0.0",
32 0
			src = system.file("htmlwidgets/lib/tile3d", package = "mapdeck"),
33 0
			script = c("tile3d.js"),
34 0
			all_files = FALSE
35
		)
36
	)
37
}
38

39

40
#' Add Cesium
41
#'
42
#' @examples
43
#' \donttest{
44
#'
45
#' ## Melbourne point cloud
46
#' ion_asset <- 43978
47
#' tile_data <- paste0("https://assets.cesium.com/",ion_asset,"/tileset.json")
48
#'
49
#' mapdeck() %>%
50
#'  add_cesium(
51
#'    data = tile_data
52
#'    , ion_token = secret::get_secret("ion")
53
#'  )
54
#'
55
#' }
56
#'
57
#' @export
58
add_cesium <- function(
59
	map,
60
	data,
61
	layer_id = NULL,
62
	ion_token = NULL
63
) {
64

65 0
	experimental_layer("cesium")
66

67 0
	layer_id <- layerId(layer_id, layer = "cesium" )
68

69 0
	map <- addDependency(map, mapdeckTile3DDependency() )
70 0
	map <- addDependency(map, mapdeckLoader3dTilesDependency() )
71

72 0
	jsfunc <- "add_cesium"
73

74 0
	invoke_method(
75 0
		map, jsfunc, map_type( map ), data, layer_id, ion_token
76
	)
77
}
78

79

80

81
#' Add I3S
82
#'
83
#' @examples
84
#' \donttest{
85
#'
86
#' ## San Francisco buildings
87
#' i3s <- 'https://tiles.arcgis.com/tiles/z2tnIkrLQ2BRzr6P/arcgis/rest/services/SanFrancisco_Bldgs/SceneServer/layers/0'
88
#' mapdeck() %>%
89
#'   add_i3s(
90
#'     data = i3s
91
#'   )
92
#' }
93
#'
94
#' @export
95
add_i3s <- function(
96
	map,
97
	data,
98
	layer_id = NULL
99
) {
100

101 0
	experimental_layer("i3s")
102

103 0
	layer_id <- layerId(layer_id, layer = "i3s" )
104

105 0
	map <- addDependency(map, mapdeckTile3DDependency() )
106 0
	map <- addDependency(map, mapdeckLoaderIS3Dependency() )
107

108 0
	jsfunc <- "add_i3s"
109

110 0
	invoke_method(
111 0
		map, jsfunc, map_type( map ), data, layer_id
112
	)
113
}
114

115
# ## canary_warf <- 'https://raw.githubusercontent.com/AnalyticalGraphicsInc/3d-tiles/master/examples/tileset.json'
116
# tl <- "https://raw.githubusercontent.com/AnalyticalGraphicsInc/3d-tiles-samples/master/tilesets/TilesetWithDiscreteLOD/tileset.json"
117
# mapdeck(
118
#   location = c(0, 0)
119
#   , zoom = 6
120
#   ) %>%
121
#   add_cesium(
122
#     data = tl
123
#   )
124

Read our documentation on viewing source code .

Loading