【问题标题】:Leaflet Coordinate Control in RR中的传单坐标控制
【发布时间】:2016-10-17 14:39:24
【问题描述】:

我正在使用 RStudio 中的 Leaflet。现在,我想捕捉鼠标点击并在地图上获取它的坐标。类似this

你知道如何为 R 中的传单调整该代码吗?

【问题讨论】:

  • 如果悬停就够了,试试mapview::addMouseCoordinates()
  • 感谢您的回答。我已经尝试过 addMouseCoordinates()。但我想复制并粘贴坐标。不幸的是,使用 addMouseCoordinates() 是不可能的。

标签: r leaflet coordinates rstudio


【解决方案1】:

如果要添加 Shiny 库,可以使用 input$map_click,其中 map 是地图的名称。:

library(shiny)
library(leaflet)

shinyApp(
  ui = fluidPage(
  leafletMap(
    "map", "100%", 400,
    initialTileLayer = "//{s}.tiles.mapbox.com/v3/jcheng.map-5ebohr46/{z}/{x}/{y}.png",
    initialTileLayerAttribution = HTML('Maps by <a href="http://www.mapbox.com/">Mapbox</a>'),
    options=list(
      center = c(37.45, -93.85),
      zoom = 4,
      maxBounds = list(list(17, -180), list(59, 180))))),

 server = function(input, output, session){
    map = createLeafletMap(session, 'map')

    observe({
      click<-input$map_click
      if(is.null(click))
    return()
      text<-paste("Lattitude ", click$lat, "Longtitude ", click$lng)
        map$showPopup( click$lat, click$lng, text)
     })
  }
)

【讨论】:

    猜你喜欢
    • 2015-08-03
    • 2017-10-21
    • 2013-01-05
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-29
    • 2015-10-28
    相关资源
    最近更新 更多