Skip to content

Commit

Permalink
Add new arg set_view in selectionMap()
Browse files Browse the repository at this point in the history
This allows to focus on selected location and may be useful for #14.
  • Loading branch information
KevCaz committed Jan 31, 2022
1 parent 30e7d6b commit 74c41ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions app/R/selectionMap.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Interactive map created with `leaflet` and called in `mapedit::callModule`.

selectionMap <- function(geoms = NULL) {
selectionMap <- function(geoms = NULL, set_view = TRUE) {

out <- leaflet::leaflet(height = 2000) %>%
leaflet::addTiles() %>%
leafem::addMouseCoordinates() %>%
leaflet::setView(lat = 45.6, lng = -63.6, zoom = 7) %>%
leaflet::addProviderTiles('Esri.OceanBasemap', group = 'OceaBasemap') %>%
leaflet::addProviderTiles("OpenTopoMap", group = "OpenTopoMap") %>%
leaflet::addProviderTiles("OpenStreetMap", group = "OpenStreetMap") %>%
Expand All @@ -15,6 +14,9 @@ selectionMap <- function(geoms = NULL) {

if (!is.null(geoms)) out <- leafem::addFeatures(out, geoms)

out
if (set_view) {
out %>% leaflet::setView(lat = 45.6, lng = -63.6, zoom = 7)
} else out

}

6 changes: 3 additions & 3 deletions app/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ server <- function(input, output, session) {


# CREATE GEOMS
geoms <- reactiveValues(select = NULL, final = NULL)
geoms <- reactiveValues(select = NULL, final = NULL, locations = NULL)

# GEOMS CREATED
nb_geom <- reactive({
Expand Down Expand Up @@ -128,7 +128,7 @@ server <- function(input, output, session) {
selected = seq_along(x)
)
}, ignoreNULL = FALSE)

# Search location
observeEvent(input$search_loc, {
bb <- osmdata::getbb(input$location)
if (!is.na(bb[1, 1])) {
Expand All @@ -147,7 +147,7 @@ server <- function(input, output, session) {
)
)
# review selection area so that default setup depends on selection
map <- selectionMap(sf_loc)
map <- selectionMap(sf_loc, FALSE)
callModule(editMod, leafmap = map, id = "map")
}

Expand Down

0 comments on commit 74c41ee

Please sign in to comment.