【问题标题】:r leaflet: how to obtain lat/long where marker has been dragged to?r 传单:如何获得标记被拖到的纬度/经度?
【发布时间】:2018-11-19 08:17:11
【问题描述】:

在 R 版本的传单中,我怎样才能获得标记被拖到哪里的纬度?

library(shiny)
library(leaflet)
library(tidyverse)

ui = fluidPage(
    leafletOutput('map'),
    textOutput('dragEndLocation')
)

server = function(input, output, session){
    output$map = leaflet() %>%
        addTiles() %>%
        addMarkers(lat = 1,lng = 2, options = markerOptions(draggable = TRUE)

    output$dragEndLocation = renderText({
        ???
    })
}

我在 javascript 传单中看到,有一个名为 dragEnd 的事件可以监听,但它没有在 R 传单中实现。 (leaflet.js - Set marker on click, update position on drag)

这个人 (How to update coordinates after dragging a marker in leaflet shiny?) 通过监听 input$map_marker_mouseout 然后检查 lat long 是否发生了变化,做了一个 hack-y 解决方法,但这并不理想。当您非常快速地拖动标记时,mouseout 将注册几次。对于这个最小的工作示例来说这不是问题,但对于我想要在拖动结束后更慢的脚本的实际应用程序来说,它使这个解决方法非常错误和缓慢。

有什么想法吗?

【问题讨论】:

  • 你找到解决办法了吗?

标签: r leaflet


【解决方案1】:

老问题,但我来找同样的问题并想通了:

observe({
    print(input$map_marker_dragend)
})

换句话说 - 您要查找的事件是dragend

【讨论】:

    猜你喜欢
    • 2016-10-30
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多