Search code examples
rr-leaflet

Custom markers in leaflet


Is there any way to get custom marker icons for leaflet in R? I have tried using the example code provided in the tutorial however the makeIcon function does not appear to exist. The code I tried is here but it didn't work.

http://rstudio.github.io/leaflet/markers.html

The overall aim is to implement this into a shiny web application.


Solution

  • The makeIcon function does exist, at least in my leaflet package.. The following code (from the tutorial) works fine for me..

    greenLeafIcon <- makeIcon(
      iconUrl = "http://leafletjs.com/examples/custom-icons/leaf-green.png",
      iconWidth = 38, iconHeight = 95,
      iconAnchorX = 22, iconAnchorY = 94,
      shadowUrl = "http://leafletjs.com/examples/custom-icons/leaf-shadow.png",
      shadowWidth = 50, shadowHeight = 64,
      shadowAnchorX = 4, shadowAnchorY = 62
    )
    
    leaflet(data = quakes[1:20,]) %>% addTiles() %>%
      addMarkers(~long, ~lat, ~as.character(mag), icon = greenLeafIcon)