Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addMapPane to add extra panes within leaflet #549

Merged
merged 4 commits into from May 22, 2018

Conversation

schloerke
Copy link
Contributor

@schloerke schloerke commented May 15, 2018

Fixes: #536

@tim-salabim

library(leaflet)                                                                    
rand_lng <- function(n = 10) rnorm(n, -93.65, .01)                                  
rand_lat <- function(n = 10) rnorm(n, 42.0285, .01)                                 
                                                                                    
random_data <- data.frame(                                                          
  lng = rand_lng(50),                                                                 
  lat = rand_lat(50),                                                                 
  radius = runif(50, 50, 150),                                                        
  circleId = paste0("circle #", 1:50),                                                
  lineId = paste0("circle #", 1:50)                                                   
)                                                                                   
                                                                                    
# display circles (zIndex: 420) above the lines (zIndex: 410), even when added first
leaflet() %>%                                                                       
  addTiles() %>%                                                                      
  # move the center to Snedecor Hall                                                  
  setView(-93.65, 42.0285, zoom = 14) %>%                                             
  addMapPane("ames_lines", zIndex = 410) %>% # shown below ames_circles               
  addMapPane("ames_circles", zIndex = 420) %>% # shown above ames_lines               
  # points above polygons                                                             
  addCircles(                                                                         
    data = random_data, ~lng, ~lat, radius = ~radius, popup = ~circleId,                
    options = pathOptions(pane = "ames_circles")                                        
  ) %>%                                                                               
  # lines in 'ames_lines' pane                                                        
  addPolylines(                                                                       
    data = random_data, ~lng, ~lat, color = "#F00", weight = 20,                        
    options = pathOptions(pane = "ames_lines")                                          
  )                                                                                   

# same example but circles (zIndex: 420) are below the lines (zIndex: 430)          
leaflet() %>%                                                                       
  addTiles() %>%                                                                      
  # move the center to Snedecor Hall                                                  
  setView(-93.65, 42.0285, zoom = 14) %>%                                             
  addMapPane("ames_lines", zIndex = 430) %>% # shown below ames_circles               
  addMapPane("ames_circles", zIndex = 420) %>% # shown above ames_lines               
  # points above polygons                                                             
  addCircles(                                                                         
    data = random_data, ~lng, ~lat, radius = ~radius, popup = ~circleId,                
    options = pathOptions(pane = "ames_circles")                                        
  ) %>%                                                                               
  # lines in 'ames_lines' pane                                                        
  addPolylines(                                                                       
    data = random_data, ~lng, ~lat, color = "#F00", weight = 20,                        
    options = pathOptions(pane = "ames_lines")                                          
  )                                                                                   


PR task list:

  • Update NEWS
  • Add tests (if appropriate)
  • Update documentation with devtools::document()

@tim-salabim
Copy link
Contributor

Awesome, thanks! I will delete in mapview and add leaflet:: where appropriate once this hits CRAN.

@schloerke schloerke requested a review from jcheng5 May 16, 2018 16:56
@schloerke schloerke merged commit 0eddf7e into rstudio:master May 22, 2018
@schloerke schloerke removed the request for review from jcheng5 May 22, 2018 16:25
@schloerke schloerke deleted the pane branch May 24, 2018 13:55
schloerke added a commit to schloerke/leaflet that referenced this pull request May 24, 2018
* master:
  addMapPane to add extra panes within leaflet (rstudio#549)
@schloerke schloerke requested a review from jcheng5 May 25, 2018 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants