tomroh / leaflegend

Provides extensions to the leaflet R package to customize legends with images, text styling, orientation, sizing, and symbology.
https://leaflegend.delveds.com
Other
34 stars 3 forks source link

Add Line Weight Size Legend #47

Closed bpb824 closed 2 years ago

bpb824 commented 2 years ago

Do you plan to add an implementation of this for the width/weight of polylines? I haven't seen any other package do it yet, and it seems like it would not be that hard from what you have already set up.

tomroh commented 2 years ago

@bpb824 I can add this in the next version. You are looking for something similar to addLegendSize but only changes the weight of the line height but not the line width?

bpb824 commented 2 years ago

Precisely -- something that can be used to represent flow data on a polyline. I use your package to map transit data for example, and I want to be able to show passenger load observed on segments of a bus route using the weight attribute of Leaflet's polyline shape. Thank you!

tomroh commented 2 years ago
devtools::install_github('tomroh/leaflegend@devel')

library(leaflet)
library(leaflegend)
data("atlStorms2005")
baseSize <- 10
lineColor <- '#00000080'
pal <- colorNumeric('Reds', atlStorms2005$MinPress)
leaflet() |> 
  addTiles() |> 
  addPolylines(data = atlStorms2005,
               weight = ~sizeNumeric(values = MaxWind, baseSize = baseSize),
               color = ~pal(MinPress),
               popup = ~as.character(MaxWind)) |> 
  addLegendLine(values = atlStorms2005$MaxWind, 
                title = 'MaxWind',
                baseSize = baseSize,
                width = 50,
                color = lineColor) |> 
  addLegendNumeric(pal = pal, 
                   title = 'MinPress',
                   values = atlStorms2005$MinPress)

I added in a new function and this should solve the issue.

bpb824 commented 2 years ago

Thank you!!!

tomroh commented 2 years ago

fda701250eb7cc568f895c43778f6d9790ae2254