Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addImageQuery does not work with leafletProxy() #15

Closed
micahwilhelm opened this issue Apr 6, 2020 · 0 comments
Closed

addImageQuery does not work with leafletProxy() #15

micahwilhelm opened this issue Apr 6, 2020 · 0 comments

Comments

@micahwilhelm
Copy link

addImageQuery only works when I initially generate the map (see code block 1). However, the map is first generated and then modified with leafletProxy to add the raster and image query, the raster is added to the map but the query does not work (see code block 2).

Code block 1 (addImageQuery works):

library(leaflet)
library(plainview)
library(leafem)
library(shiny)

ui <- fluidPage(
  fluidRow(
    leafletOutput("map")
  )
)

server <- function(input, output) {
  output$map <- renderLeaflet({
    leaflet() %>%
      addProviderTiles("OpenStreetMap") %>%
      addRasterImage(poppendorf[[1]], project = TRUE, group = "poppendorf",
                     layerId = "poppendorf") %>%
      addImageQuery(poppendorf[[1]], project = TRUE,
                            layerId = "poppendorf",position="bottomleft",prefix = "") %>%
      addLayersControl(overlayGroups = "poppendorf")
  })
}

shinyApp(ui, server)

Code block 2 (raster added on click, addImageQuery does not work):

library(leaflet)
library(plainview)
library(leafem)
library(shiny)

ui <- fluidPage(
  fluidRow(
    leafletOutput("map")
  )
)

server <- function(input, output) {
  output$map <- renderLeaflet({
    leaflet() %>%
      addProviderTiles("OpenStreetMap") %>%
      setView(11.2,49.73,12)
  })

  counter <- reactiveValues(
    counter = 0
  )

  observeEvent(input$map_click,{
    counter$counter <- counter$counter + 1
    if (counter$counter == 1) {
      leafletProxy("map") %>%
        addRasterImage(poppendorf[[1]], project = TRUE, group = "poppendorf",
                       layerId = "poppendorf") %>%
        addImageQuery(poppendorf[[1]], project = TRUE,
                      layerId = "poppendorf",position="bottomleft",prefix = "") %>%
        addLayersControl(overlayGroups = "poppendorf")

    }
  })
}

shinyApp(ui, server)

Does anyone know a way to get the addImageQuery function to work with a leafletProxy call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant