R Leaflet custom attribution string

不打扰是莪最后的温柔 提交于 2020-01-05 03:37:50

问题


When using the R leaflet package, how can I add something additional to the attribution string (i.e. the "Leaflet | ..." in the bottom right corner)?

For example, I how would I add something like "data source: ..." to the attribution text on this map:

leaflet(data = quakes[1:20,]) %>% 
  addTiles() %>%
  addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag))

回答1:


You can add an attribution argument to addTiles:

leaflet(data = quakes[1:20,]) %>% 
  addTiles(attribution = 'I did this, you hear?! Also Leaflet.') %>%
  addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag))

I'd love to know how to do this with addProviderTiles, though, because that doesn't appear to accept an attribution argument :/

EDIT: okay, my workaround for using provider tiles has been to just use both functions. I hope it's not actually calling both tiles, since that's a bit of a waste of user bandwidth—but hey, it looks fine!

leaflet(data = quakes[1:20,]) %>% 
  addTiles(attribution = 'I did this, you hear?! Also Leaflet.') %>%
  addProviderTiles(providers$OpenStreetMap.Mapnik) %>%
  addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag))



回答2:


As @rensa suspects, their second option does indeed embed and fetch both tile sets. However, the setting a blank urlTemplate seems to stop it:

leaflet(data = quakes[1:20,]) %>% 
  addProviderTiles(providers$OpenStreetMap.Mapnik) %>%
  addTiles(urlTemplate = "", attribution = 'I did this, you hear?! Also Leaflet.')


来源:https://stackoverflow.com/questions/44953146/r-leaflet-custom-attribution-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!