问题
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