diff --git a/R/global.R b/R/global.R index 6e5d651..68dd419 100644 --- a/R/global.R +++ b/R/global.R @@ -67,6 +67,7 @@ load_place <- function(path) { #' @return Circular polygon geometry. #' @noRd create_circle_polygon <- function(lat, long, radius_m) { + # Create a point in a geographical coordinate system (WGS 84) pt <- sf::st_point(c(long, lat)) pt <- sf::st_sfc(pt, crs = 4326) # Assign WGS 84 CRS diff --git a/R/server.R b/R/server.R index 60ad58b..d9bcd32 100644 --- a/R/server.R +++ b/R/server.R @@ -41,11 +41,11 @@ infinity_server <- function(...) { # Render coordinates text output$lat <- renderText({ - input$latitude + input$geolat }) output$long <- renderText({ - input$longitude + input$geolong }) output$accuracy <- renderText({ @@ -63,7 +63,7 @@ infinity_server <- function(...) { }) - circle_polygon <- eventReactive(input$executeButton, { + circle_polygon_choose <- eventReactive(input$executeButton, { lat <- tryCatch( as.numeric(input$latitude), error = function(e) @@ -90,6 +90,33 @@ infinity_server <- function(...) { }) + circle_polygon_geo <-eventReactive(input$executeButton, { + lat <- tryCatch( + as.numeric(input$geolat), + error = function(e) + NA + ) + long <- + tryCatch( + as.numeric(input$geolong), + error = function(e) + NA + ) + radius_m <- + tryCatch( + as.numeric(input$radiusChoice), + error = function(e) + NA + ) + + if (is.na(lat) || is.na(long) || is.na(radius_m)) { + return(NULL) + } + + return(create_circle_polygon(lat, long, radius_m)) + }) + + selected_polygon <- reactive({ switch( input$inputType, @@ -98,11 +125,11 @@ infinity_server <- function(...) { }, "choose" = { - return(circle_polygon()) + return(circle_polygon_choose()) }, "current" = { - return(circle_polygon()) + return(circle_polygon_geo()) }, "upload" = { diff --git a/R/ui.R b/R/ui.R index 8e0fed1..3fdd66c 100644 --- a/R/ui.R +++ b/R/ui.R @@ -87,8 +87,8 @@ ui <- function(){ var coords = position.coords; console.log(coords.latitude + ", " + coords.longitude, "," + coords.accuracy); Shiny.onInputChange("geolocation", true); - Shiny.onInputChange("latitude", coords.latitude); - Shiny.onInputChange("longitude", coords.longitude); + Shiny.onInputChange("geolat", coords.latitude); + Shiny.onInputChange("geolong", coords.longitude); Shiny.onInputChange("accuracy", coords.accuracy); }, 1100) } @@ -120,14 +120,14 @@ ui <- function(){ numericInput( "latitude", "Latitude", - value = -33.8688, + value = -34.1182, min = -90, max = 90, step = 0.00001), numericInput( "longitude", "Longitude", - value = 148.2093, + value = 151.0636, min = -180, max = 180, step = 0.00001