-
Notifications
You must be signed in to change notification settings - Fork 1
/
widget_mapManager_ui.R
257 lines (244 loc) · 6.38 KB
/
widget_mapManager_ui.R
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#' @include internal.R
NULL
#' Map manager
#'
#' Constructs a widget for managing items on a Leaflet map.
#' This widget is designed to be used in conjunction with an existing
#' Leaflet Map within a Shiny web application.
#'
#' @param x [MapManager] object.
#'
#' @inheritParams solutionSettings
#'
#' @section Server value:
#' The widget sends a `list` with the following values to the server:
#'
#' \describe{
#'
#' \item{id}{`character` identifier for layer to update.}
#'
#' \item{setting}{`character` name of the updated setting}.
#'
#' \item{value}{`numeric` or `logical` values.}
#'
#'
#' }
#'
#' @rdname mapManager-widget
#'
#' @examples
#' \dontrun{
#' # run Shiny app to demo the sidebar pane
#' if (interactive()) {
#' runExample("mapManager")
#' }
#' }
#'
#' @export
mapManager <- function(x, width = NULL, height = NULL, elementId = NULL) {
# assert that arguments are valid
assertthat::assert_that(inherits(x, "MapManager"))
# create widget
htmlwidgets::createWidget(
name = "mapManager",
x$get_widget_data(),
width = width,
height = height,
package = "wheretowork",
elementId = elementId,
dependencies = c(
htmltools::htmlDependencies(shiny::icon("map-marked-alt"))
)
)
}
#' Shiny bindings for `mapManager`
#'
#' Use `mapManagerOutput()` to create a user interface element,
#' and `renderMapManager()` to render the widget.
#'
#' @param outputId output variable to read from
#'
#' @param width,height Must be a valid CSS unit (like \code{"100\%"},
#' \code{"400px"}, \code{"auto"}) or a number, which will be coerced to a
#' string and have \code{"px"} appended.
#'
#' @param expr An expression that generates a [mapManager()]
#'
#' @param env The environment in which to evaluate \code{expr}.
#'
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#'
#' @name mapManager-shiny
#'
#' @export
mapManagerOutput <- function(outputId, width = "100%", height = "auto") {
htmlwidgets::shinyWidgetOutput(
outputId, "mapManager", width, height,
package = "wheretowork"
)
}
#' @rdname mapManager-shiny
#' @export
renderMapManager <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) {
expr <- substitute(expr)
} # force quoted
htmlwidgets::shinyRenderWidget(expr, mapManagerOutput, env, quoted = TRUE)
}
# Add custom HTML for the widget (automatically used by htmlwidgets)
mapManager_html <- function(id, style, class, ...) {
# HTML scaffold
x <-
htmltools::tags$div(
id = id, class = class, style = style,
htmltools::div(
class = "map-manager-container",
htmltools::div(
class = "map-manager",
htmltools::tags$div(
class = "layers"
)
)
)
)
# add HTML template scaffolds for dynamic content
## solution
x <-
htmltools::tagAppendChild(
x,
htmltools::tags$template(
class = "solution-layer-template",
htmltools::tags$div(
class = "map-manager-layer",
htmltools::tags$div(
class = "solution-layer",
mm_header_component_scaffold(
type = "solution",
remove_button = TRUE
),
htmltools::tags$div(
class = "layer-legend-container",
mm_legend_component_scaffold()
)
)
)
)
)
## include
x <-
htmltools::tagAppendChild(
x,
htmltools::tags$template(
class = "include-layer-template",
htmltools::tags$div(
class = "map-manager-layer",
htmltools::tags$div(
class = "include-layer",
mm_header_component_scaffold(type = "include"),
htmltools::tags$div(
class = "layer-legend-container",
mm_legend_component_scaffold()
)
)
)
)
)
## exclude
x <-
htmltools::tagAppendChild(
x,
htmltools::tags$template(
class = "exclude-layer-template",
htmltools::tags$div(
class = "map-manager-layer",
htmltools::tags$div(
class = "exclude-layer",
mm_header_component_scaffold(type = "exclude"),
htmltools::tags$div(
class = "layer-legend-container",
mm_legend_component_scaffold()
)
)
)
)
)
## weight
x <-
htmltools::tagAppendChild(
x,
htmltools::tags$template(
class = "weight-layer-template",
htmltools::tags$div(
class = "map-manager-layer",
htmltools::tags$div(
class = "weight-layer",
mm_header_component_scaffold(type = "weight"),
htmltools::tags$div(
class = "layer-legend-container",
mm_legend_component_scaffold()
)
)
)
)
)
## singleTheme
x <-
htmltools::tagAppendChild(
x,
htmltools::tags$template(
class = "single-theme-layer-template",
htmltools::tags$div(
class = "map-manager-layer",
htmltools::tags$div(
class = "theme-layer",
mm_header_component_scaffold(type = "theme"),
htmltools::tags$div(
class = "layer-legend-container",
mm_legend_component_scaffold()
)
)
)
)
)
## multiTheme
### main container
x <-
htmltools::tagAppendChild(
x,
htmltools::tags$template(
class = "multi-theme-layer-template",
htmltools::tags$div(
class = "map-manager-layer",
htmltools::tags$div(
class = "theme-layer",
mm_header_component_scaffold(type = "theme"),
htmltools::tags$div(class = "main")
)
)
)
)
### sub container
x <-
htmltools::tagAppendChild(
x,
htmltools::tags$template(
class = "multi-theme-single-layer-template",
htmltools::tags$div(
class = "single-container",
htmltools::tags$div(
htmltools::tags$div(
class = "sub-layer",
mm_subheader_component_scaffold(),
htmltools::tags$div(
class = "layer-legend-container",
mm_legend_component_scaffold()
)
)
)
)
)
)
# return result
x
}