Area select event for R leaflet in shiny

ぐ巨炮叔叔 提交于 2020-01-15 19:12:12

问题


I've played with the mouse click event in leaflet using the following code:

mymap=leaflet()
selected_site=eventReactive(input$mymap_marker_click,{
      event <- input$mymap_map_marker_click
      return(mydt[Long==event$lng & Lat==event$lat,get("sites")])
    })

to display a plot from a data.table after a click on a point of the map. Now, I'd like to select an entire area then display data binding to it.

In other terms, I'd like to select not a couple of (Lat,Long) but a series of (Lat1, Long1)....(Latn,Longn)

Is there a mean to do it in leaflet ?

Thanks in advance,


回答1:


You just have to instantiate a L.Polygon per area, and attach an event handler to it: http://playground-leaflet.rhcloud.com/zab/edit?html,console,output

Keep in mind that you can make areas transparent (zero opacity but fill option still set to true) and still get mouse events from them.



来源:https://stackoverflow.com/questions/34986212/area-select-event-for-r-leaflet-in-shiny

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!