plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

Suggestion: icon markers

Open ThierryO opened this issue 2 years ago • 0 comments

Leaflet provides icon markers. This would be nice to have in plotly.

Code taken from https://rstudio.github.io/leaflet/markers.html. That webpage contains the rendered output.

library(leaflet)
# Make a list of icons. We'll index into it based on name.
oceanIcons <- iconList(
  ship = makeIcon("ferry-18.png", "[email protected]", 18, 18),
  pirate = makeIcon("danger-24.png", "[email protected]", 24, 24)
)

# Some fake data
df <- sp::SpatialPointsDataFrame(
  cbind(
    (runif(20) - .5) * 10 - 90.620130,  # lng
    (runif(20) - .5) * 3.8 + 25.638077  # lat
  ),
  data.frame(type = factor(
    ifelse(runif(20) > 0.75, "pirate", "ship"),
    c("ship", "pirate")
  ))
)

leaflet(df) %>% addTiles() %>%
  # Select from oceanIcons based on df$type
  addMarkers(icon = ~oceanIcons[type])

ThierryO avatar Aug 31 '23 12:08 ThierryO