简体   繁体   中英

Area select event for R leaflet in shiny

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,

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM