1
-
2
-
3
-
4
1
# ' @title mapedit create features Addin
5
2
# ' @description Create and save spatial objects within the Rstudio IDE. Objects
6
3
# ' can then be saved to file types such as \code{.geojson} or \code{.shp}.
17
14
# ' @param SF_OBJECT sf Simple feature collection
18
15
# '
19
16
# ' @return sf object and/or saved to file
20
- # ' @importFrom miniUI miniPage miniContentPanel gadgetTitleBar miniButtonBlock
21
- # ' @import shiny
22
- # ' @importFrom shinyWidgets switchInput updateSwitchInput
23
- # ' @importFrom mapview mapview
24
- # ' @importFrom sf write_sf
25
- # ' @importFrom dplyr bind_rows
26
- # ' @importFrom leaflet setView
27
- # ' @importFrom rstudioapi getActiveDocumentContext
28
17
# ' @export
29
18
# '
30
19
createFeatures <- function (SF_OBJECT = NULL ) {
31
20
32
- ui <- miniPage(
33
- gadgetTitleBar(" Edit Map" ),
34
- miniContentPanel(
35
- editModUI(" editor" ),
36
- miniButtonBlock(
37
- div(style = " display: inline-block;padding-top:22px;padding-left:30px;width:200px;" ,
38
- switchInput(' savefile' , ' Save' , value = FALSE , onStatus = " success" , offStatus = " danger" )),
39
- div(style = " display: inline-block; width: 400px;" ,
40
- textInput(' filename' , ' ' , value = ' saved_geometry.geojson' )),
41
- div(style = " display: inline-block;padding-top:18px;width: 400px;font-size: 10pt;color: #313844;" ,
42
- ' The filename can include a path relative to working directory. ' ,
43
- ' A different file type can be selected by changing the file extension.' )
21
+ ui <- miniUI :: miniPage(
22
+ miniUI :: gadgetTitleBar(" Edit Map" ),
23
+ miniUI :: miniContentPanel(
24
+ mapedit :: editModUI(" editor" ),
25
+ miniUI :: miniButtonBlock(
26
+ htmltools :: div(style = " display: inline-block;padding-top:22px;padding-left:30px;width:200px;" ,
27
+ shinyWidgets :: switchInput(' savefile' , ' Save' , value = FALSE , onStatus = " success" , offStatus = " danger" )),
28
+ htmltools :: div(style = " display: inline-block; width: 400px;" ,
29
+ shiny :: textInput(' filename' , ' ' , value = ' saved_geometry.geojson' )),
30
+ htmltools :: div(style = " display: inline-block;padding-top:18px;width: 400px;font-size: 10pt;color: #313844;" ,
31
+ ' The filename can include a path relative to working directory. ' ,
32
+ ' A different file type can be selected by changing the file extension.' )
44
33
)
45
34
)
46
35
)
@@ -63,36 +52,38 @@ createFeatures <- function(SF_OBJECT = NULL) {
63
52
}, silent = TRUE )
64
53
65
54
# update UI based on inputs
66
- updateTextInput(session , ' filename' , value = FILENAME )
55
+ shiny :: updateTextInput(session , ' filename' , value = FILENAME )
67
56
if (FILENAME != ' saved_geometry.geojson' ) {
68
- updateSwitchInput(session , ' savefile' , value = TRUE )
57
+ shinyWidgets :: updateSwitchInput(session , ' savefile' , value = TRUE )
69
58
}
70
59
71
60
# load mapedit
72
61
if (' sf' %in% class(SF_OBJECT )) {
73
- geo <- callModule(editMod , " editor" , mapview(SF_OBJECT )@ map )
62
+ geo <- shiny :: callModule(mapedit :: editMod , " editor" , mapview :: mapview(SF_OBJECT )@ map )
74
63
} else {
75
- geo <- callModule(editMod , " editor" , setView(mapview()@ map , 80 , 0 , 3 ))
64
+ geo <- shiny :: callModule(mapedit :: editMod , " editor" , leaflet :: setView(mapview :: mapview()@ map , 80 , 0 , 3 ))
76
65
}
77
66
78
- observe({
67
+ shiny :: observe({
79
68
input $ filename
80
69
OBJECTNAME <- tools :: file_path_sans_ext(basename(input $ filename ))
81
70
})
82
71
83
72
# return geometry to file and object in console
84
- observeEvent(input $ done , {
73
+ shiny :: observeEvent(input $ done , {
85
74
geom <- geo()$ finished
86
75
87
- if (! is.null(geom ) & ! is.null(SF_OBJECT )) geom <- dplyr :: bind_rows(SF_OBJECT , geom )
76
+ if (! is.null(geom ) & ! is.null(SF_OBJECT )) {
77
+ geom <- dplyr :: bind_rows(SF_OBJECT , geom )
78
+ }
88
79
89
80
if (! is.null(geom )) {
90
81
if (input $ savefile ) {
91
82
sf :: write_sf(geom , input $ filename , delete_layer = TRUE , delete_dsn = TRUE )
92
83
}
93
84
}
94
85
95
- stopApp({
86
+ shiny :: stopApp({
96
87
if (! is.null(geom )) {
97
88
geom
98
89
}
@@ -101,7 +92,7 @@ createFeatures <- function(SF_OBJECT = NULL) {
101
92
102
93
}
103
94
104
- viewer <- paneViewer(600 )
105
- runGadget(ui , server , viewer = viewer )
95
+ viewer <- shiny :: paneViewer(600 )
96
+ shiny :: runGadget(ui , server , viewer = viewer )
106
97
107
98
}
0 commit comments