【问题标题】:Animated marker moving and/or path trajectory with Leaflet and R带有 Leaflet 和 R 的动画标记移动和/或路径轨迹
【发布时间】:2017-06-20 21:20:01
【问题描述】:

Leaflet 与 R 相结合的空间能力让我感到非常兴奋,但我非常需要在标记周围移动和/或在地图上绘制路径的可能性。据我所知,Leaflet R 包缺少此选项,尽管原始 Java 版本可能会以这种方式强制执行。你有什么想法吗?

【问题讨论】:

  • 可以使用 leaflet.extras 包(目前仅在 github 上)github.com/bhaskarvk/leaflet.extras。一个例子可以在这里找到rpubs.com/bhaskarvk/leaflet-draw
  • 抱歉,我只看到这里添加了“在地图上绘制特征”功能。上面网站上的任何动画到底在哪里?
  • 动画到底是什么意思?时间动画?
  • 我的意思是我记录了一次旅行(经度、纬度、时间戳序列),我想在地图上重播它。
  • 这是在制作中github.com/bhaskarvk/leaflet.extras/issues/34。也许借此机会将您的想法添加到问题中。

标签: r leaflet geospatial


【解决方案1】:

这个问题相当高级,但话虽如此,有一个答案here 提供了在闪亮应用程序中在地图上绘制点的解决方案。

如果您想在点之间添加线并显示经过的路线,请使用addPolylines()。示例:

library(shiny)
library(dplyr)
library(leaflet)

travel <- data.frame("time" = c("6/20/17 13:32", "6/20/17 13:33", "6/20/17 13:34", "6/20/17 13:35", "6/20/17 13:36", "6/20/17 13:37"),
             "lat" = c(59.313833, 59.312333, 59.309897, 59.307728, 59.300728, 59.298184),
             "lon" = c(18.070431, 18.07431, 18.085347, 18.076543, 18.080761, 18.076176),
             stringsAsFactors = F) %>%
          mutate(
            time = as.POSIXct(time, format = "%m/%d/%y %H:%M")
          )

# define ui with slider and animation control for time
ui <- fluidPage(
          sliderInput(inputId = "time", label = "Time", min = min(travel$time), 
          max = max(travel$time),
          value = min(travel$time),
          step=60, # set to increment by 60 seconds, adjust appropriately
          animate=T),
          leafletOutput("mymap")
)

server <- function(input, output, session) {
    points <- reactive({
        travel %>% 
            filter(time == input$time)
    })

    history <- reactive({
        travel %>%
            filter(time <= input$time)
    })

    output$mymap <- renderLeaflet({
        leaflet() %>%
            addTiles() %>%
            addMarkers(lng = ~lon,
                       lat = ~lat,
                       data = points()) %>%
            addMarkers(lng = ~lon,
                       lat = ~lat,
                       data = history()) %>%
            addPolylines(lng = ~lon,
                         lat = ~lat,
                         data = history())
   })
}

shinyApp(ui, server)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多