4

I have a flow Map - using leaflets in R

library(leaflet)
m <- leaflet(AM_Peak) %>% 
addTiles('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
attribution='Map tiles by <a href="http://stamen.com">Stamen Design</a>, 
<a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>') %>%
setView(103.831959, 1.360270, zoom = 11) %>% 
addCircles(~x_AM_Peak$Entry_Station_Long, ~x_AM_Peak$Entry_Station_Lat,
weight =x_AM_Peak$radius, radius=40, 
label = ~as.character(x_AM_Peak$Entry_Station),color="#ffa500", stroke = TRUE, fillOpacity = 0.8) %>%
    addPolylines(data = y_AM_Peak,
                 stroke = TRUE,color = "#6eff2a", weight = 0.2, opacity = 0.2,
                 fill = FALSE, fillOpacity = 0.1, dashArray = NULL,
                 smoothFactor = 1)

enter image description here

Something like this

What i am trying to do is - By default map should have all circles - When i hover on the Circle points - it should display all the polylines starting from that circle only ( as shown in the link). enter image description here

Prasanna Nandakumar
  • 4,295
  • 34
  • 63

1 Answers1

0

Haven't tried it but here is the approach that I would follow:

a) create different layer groups for each lines group.

b) set circle marker layers to interactive (Leaflet has this option).

c) use the 'mouseover' and 'mouseout' events that Leaflet supports.

d) use show/hide methods to only show the layer group (lines) that is connected to the "hovered" circle marker. I think you can show/hide with Leaflet methods (otherwise, jQuery could be useful).

treecon
  • 2,415
  • 2
  • 14
  • 28