这是其中最常见的传单示例之一。但是,当我运行此代码时,在海洋或图例中看不到红色和绿色的叶子图标,而是看到带有问号的蓝色方块。虽然背景图是正确的。
library(leaflet)
# Sample Data
data(quakes)
quakes <- quakes[1:10,]
# Choose Icon:
leafIcons <- icons(
iconUrl = ifelse(quakes$mag < 4.6,"http://leafletjs.com/docs/images/leaf-green.png","http://leafletjs.com/docs/images/leaf-red.png"
),iconWidth = 38,iconHeight = 95,iconAnchorX = 22,iconAnchorY = 94)
html_legend <- "<img src='http://leafletjs.com/docs/images/leaf-green.png'>green<br/>
<img src='http://leafletjs.com/docs/images/leaf-red.png'>red"
# Produce Map:
leaflet(data = quakes) %>% addTiles() %>%
addMarkers(~long,~lat,icon = leafIcons) %>%
addControl(html = html_legend,position = "bottomleft")