Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom markers in leaflet

Tags:

r

leaflet

shiny

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

Any suggestions would be much appreciated. The overall aim is to implement this into a shiny web application.

Many Thanks

like image 930
Will Avatar asked Dec 24 '22 16:12

Will


1 Answers

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)
like image 155
symbolrush Avatar answered Dec 29 '22 05:12

symbolrush