Skip to content

Commit

Permalink
fix: marker ordering problems w/ merge()
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-davison committed Jul 19, 2024
1 parent 6ababc9 commit 8d3237d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
18 changes: 14 additions & 4 deletions R/magicIcons.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ magicIcons <- function(icon = "circle",
markerSize = markerSize
)

unique_combos <- unique(combinations)
combinations$rn <- seq_along(combinations$icon)

unique_combos <- combinations
unique_combos$rn <- NULL
unique_combos <- unique(unique_combos)

make_fa_icon <- function(icon, markerColor, iconColor, markerSize) {
time <- Sys.time() %>% as.numeric()
Expand Down Expand Up @@ -135,9 +139,15 @@ magicIcons <- function(icon = "circle",
unique_combos$themarker <- icons

combinations <-
merge(combinations,
unique_combos,
by = c("icon", "markerColor", "iconColor", "markerSize"))
merge(
combinations,
unique_combos,
sort = TRUE,
by = c("icon", "markerColor", "iconColor", "markerSize")
)

combinations <- combinations[order(combinations$rn),]
rownames(combinations) <- NULL

do.call(leaflet::iconList, combinations$themarker)
}
Expand Down
8 changes: 5 additions & 3 deletions vignettes/leaf-magic.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,16 @@ leaflet(port_talbot) %>%
```{r awesomepal}
cols <- names(awesomePalette)[names(awesomePalette) != "white"]
breweries91$color <- sample(cols, nrow(breweries91), replace = TRUE)
breweries91$facolor <- sample(cols, nrow(breweries91), replace = TRUE)
breweries91$hexcolor <- unlist(use.names = FALSE, awesomePalette[breweries91$facolor])
leaflet(breweries91) %>%
addTiles() %>%
addAwesomeMarkers(
icon = ~ awesomeIcons(
icon = "circle",
markerColor = color,
markerColor = facolor,
iconColor = "#FFFFFF",
library = "fa"
),
Expand All @@ -274,7 +276,7 @@ leaflet(breweries91) %>%
addMarkers(
icon = ~ magicIcons(
icon = "fas fa-circle",
markerColor = unlist(use.names = FALSE, awesomePalette[color]),
markerColor = hexcolor,
iconColor = "#FFFFFF"
),
group = "Magic"
Expand Down

0 comments on commit 8d3237d

Please sign in to comment.