当用户按下按钮放大到该点时,如何在传单地图(使用 Shiny)上选择一个点时控制缩放速度?
How can I control the zoom speed when selecting a point on a leaflet map (with Shiny) when the user presses the button to zoom in to the point?
我正在 Rmarkdown
、Flexdashboard
和 Shiny
中开发仪表板。目前我正在使用 Leaflet
来映射几个点并且我有一个闪亮的输入,当按下按钮时它会选择一个特定的点并对其进行缩放。
想知道有没有办法控制缩放速度
图片示例:
地图的初始状态,点为蓝色。
用户选择点和按钮执行过滤和缩放的面板。
在这张图片中,我显示了对所选点的缩放,速度非常快。
我留下了一些示例代码,我会继续关注您的评论。谢谢。
{r chunk, echo = false}
leafletOutput(outputId = "mapa1")
# DATA FILTERED BY USER INPUT (1 point)
rbdFiltered <- reactive({
misDatos()[misDatos()$rdb == input$rbd, ]
})
# LEAFLET OBJECT WITH ALL POINTS
myMap <- reactive({
input$params
leaflet() %>%
addTiles() %>%
addCircleMarkers(data = misDatos(), lng = ~ longitud, lat = ~ latitud, radius = 3, group = "myMarkers") %>%
setView(lng = -70.560946, lat = -33.592340, zoom = 13) # ZOOM SET HERE
})
# OBSERVE EVENT (Select a point)
observeEvent(input$BT_select_rbd, {
leafletProxy(mapId = "mapa1") %>% clearGroup(group = "myMarkers") %>%
addCircleMarkers(data = rbdFiltered(), lng = ~ longitud, lat = ~ latitud, radius = 3, group = "myMarkers") %>%
# HERE A ZOOM TO THE SELECTED POINT IS PROCESSED, IS IT POSSIBLE TO CONTROL THE SPEED?
setView(lng = rbdFiltered()$longitud, lat = rbdFiltered()$latitud, zoom = 17)
})
# OBSERVE EVENT (Show all points)
observeEvent(input$BT_todo_rbd, {
leafletProxy(mapId = "mapa1") %>% clearGroup(group = "myMarkers") %>%
addCircleMarkers(data = misDatos(), lng = ~ longitud, lat = ~ latitud, radius = 3, group = "myMarkers") %>%
setView(lng = -70.560946, lat = -33.592340, zoom = 13) # WE RETURN TO ORIGINAL ZOOM
})
output$mapa1 <- renderLeaflet({myMap()})
问候
编辑:图片
不要在你的 Shiny 事件中使用 setView()
,而是尝试使用 leaflet::flyTo()
。
我正在 Rmarkdown
、Flexdashboard
和 Shiny
中开发仪表板。目前我正在使用 Leaflet
来映射几个点并且我有一个闪亮的输入,当按下按钮时它会选择一个特定的点并对其进行缩放。
想知道有没有办法控制缩放速度
图片示例:
地图的初始状态,点为蓝色。
用户选择点和按钮执行过滤和缩放的面板。
在这张图片中,我显示了对所选点的缩放,速度非常快。
我留下了一些示例代码,我会继续关注您的评论。谢谢。
{r chunk, echo = false}
leafletOutput(outputId = "mapa1")
# DATA FILTERED BY USER INPUT (1 point)
rbdFiltered <- reactive({
misDatos()[misDatos()$rdb == input$rbd, ]
})
# LEAFLET OBJECT WITH ALL POINTS
myMap <- reactive({
input$params
leaflet() %>%
addTiles() %>%
addCircleMarkers(data = misDatos(), lng = ~ longitud, lat = ~ latitud, radius = 3, group = "myMarkers") %>%
setView(lng = -70.560946, lat = -33.592340, zoom = 13) # ZOOM SET HERE
})
# OBSERVE EVENT (Select a point)
observeEvent(input$BT_select_rbd, {
leafletProxy(mapId = "mapa1") %>% clearGroup(group = "myMarkers") %>%
addCircleMarkers(data = rbdFiltered(), lng = ~ longitud, lat = ~ latitud, radius = 3, group = "myMarkers") %>%
# HERE A ZOOM TO THE SELECTED POINT IS PROCESSED, IS IT POSSIBLE TO CONTROL THE SPEED?
setView(lng = rbdFiltered()$longitud, lat = rbdFiltered()$latitud, zoom = 17)
})
# OBSERVE EVENT (Show all points)
observeEvent(input$BT_todo_rbd, {
leafletProxy(mapId = "mapa1") %>% clearGroup(group = "myMarkers") %>%
addCircleMarkers(data = misDatos(), lng = ~ longitud, lat = ~ latitud, radius = 3, group = "myMarkers") %>%
setView(lng = -70.560946, lat = -33.592340, zoom = 13) # WE RETURN TO ORIGINAL ZOOM
})
output$mapa1 <- renderLeaflet({myMap()})
问候 编辑:图片
不要在你的 Shiny 事件中使用 setView()
,而是尝试使用 leaflet::flyTo()
。