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

Columns in Legend #59

Closed ajpelu closed 1 year ago

ajpelu commented 1 year ago

hi @tomroh thanks for your package. Is there any way to use a column view (e.g. two columns) in the legend?

I have a layer with a high number of levels (64). I used the addLegendFactor but I would like to show the legend using a four columns view. Thanks

tomroh commented 1 year ago

This isn't currently supported. You could do hack this together by creating four separate legends and then overriding the styling of the legend backgrounds or removing the background all together.

tomroh commented 1 year ago

Here is a minimal example:

symbols <- Map(f = makeSymbol,
  shape = c('rect', 'circle', 'triangle', 'plus', 'cross', 'star')
  ,fillColor = c('blue', 'red', 'green', 'yellow', 'orange', 'purple')
  ,color = 'black'
    ,opacity = 1
  ,fillOpacity = .5
  ,height = 24
  ,width = 24
  ,'stroke-width' = 2)
m <- leaflet(x) |> 
  addLegendImage(title = 'Legend', images = symbols[1:3], labels = 1:3, position = 'topright') |> 
  addLegendImage(title = htmltools::HTML('<br>'), images = symbols[4:6], labels = 4:6, position = 'topright')
htmltools::browsable(
  htmltools::tagList(
    htmltools::tags$style('
      div.leaflet-top.leaflet-right{
      display: flex;
      }
      .info.legend.leaflet-control:first-child {
      margin-right: 0px;
      border-radius: 0px;
      background-color: white;
      box-shadow: none;
      }
      .info.legend.leaflet-control {
      border-radius: 0px;
      background-color: white;
      box-shadow: none;
      }'),        
    m
  )
)
image