Я хотел бы сохранить функциональность «двойной щелчок для увеличения» в листочке (в R), но также хотел бы добавить событие click. В этом случае событие click должно уменьшить масштаб пользователя до установленного представления. Однако я не смог сохранить функциональность двойного щелчка. Я думаю, что это возможно, просто добавив код JS, но я не уверен.
Это то, что у меня есть:
library(shiny)
library(htmlwidgets)
location=c(46.52433,10.12633)
ui <- fluidPage(
leafletOutput("map")
)
server <- function(input, output, session) {
output$map = renderLeaflet({
leaflet() %>% addTiles() %>% setView(lat = location[1],lng = location[2],zoom = 10) %>%
addMarkers(lat = location[1],lng = location[2],popup = "Test") %>%
htmlwidgets::onRender("
map.on('click', function(event) {
if (_dblClickTimer !== null) {
return;}
_dblClickTimer = setTimeout(() => {
// real 'click' event handler here
// This is where I'm trying to insert code to have the click zoom out to the bounds.
map.flyToBounds([[36.578548,48.888541],
[69.310383,-25.115366]
]);
_dblClickTimer = null;
}, 200);})
.on('dblclick', function() {
clearTimeout(_dblClickTimer);
_dblClickTimer = null;
// real 'dblclick' handler here (if any). Do not add anything to just have the default zoom behavior
});
")
})
# Normally, I would create the click-even in Shiny, using the observeEvent function, as shown below.
# Unfortunately, however, this messes with the double-click-to-zoom functionality.
#
# observeEvent(input$map_click{
# leafletProxy("map") %>% flyToBounds(lng1 =-25.555731 ,lat1 = 69.200741,lng2 = 51.436455,lat2 =35.833665 )
#
# })
}
shinyApp(ui, server)
Я использую код, предложенный @keul здесь , чтобы попытаться сохранить функциональность двойного щелчка. Однако я не могу заставить его работать. Любая помощь будет оценена!