Skip to content

NA values are repeatedly added in linked legend when switching layer off/on #456

Closed
@tim-salabim

Description

@tim-salabim

First of all many thanks for the grouped layer/legend feature. This really is a game changer as it makes interacting with the map much cleaner. I found a little bug related to NA value rendering in the legend.

If we use the new group argument in addLegend and the data has NAs I see that the na.color part of the legend gets repeatedly added to the legend as the layer is switched on/off.

library(leaflet)
library(mapview)
library(sf)

breweries = st_join(breweries, franconia[, "district"])

pal = colorFactor(c("red", "purple", "blue"), 
                  domain = mapview::breweries$district, 
                  na.color = "#BEBEBE")

leaflet() %>%
  addTiles() %>%
  addCircleMarkers(data = breweries, color = ~pal(district), group = "breweries")  %>%
  addLayersControl(overlayGroups = "breweries") %>%
  addLegend(pal = pal, values = breweries$district, group = "breweries")

In the primary rendering of the legend everything looks as expected. If we switch the breweries layer off and on we get a second NA entry in the legend. This is repeatedly added every time we switch the layer off/on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions