R:为传单地图添加标题 [英] R: Add title to Leaflet map

查看:32
本文介绍了R:为传单地图添加标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给整个地图添加一个标题(不同于图例标题:addLegend(..., title = "", ...): by "title",我的意思是在移动地图时保持原位的叠加地图组件(与叠加图像不同).

这是 RStudio 的 leaflet 中的一个选项吗?p>

leafletR有一个 title="" 参数,但它会更新网页的标题:它不会向地图添加标题.

解决方案

您应该提供一个可重现的示例.但是使用 addControl 你可以试试:

 库(传单)图书馆(htmlwidgets)库(htmltools)rr <- 标签$div(HTML('<a href="https://cran.r-project.org/"><img border="0" alt="ImageTitle" src="/PathToImage/ImageR.jpeg" width="300" 高度="100"> </a>'))map_leaflet <- 传单() %>%addTiles() %>%addMarkers(50, 50) %>%addControl(rr, position = "bottomleft")saveWidget(map_leaflet, file="testing.html")

打开保存在您的工作目录中的 testing.html,您将在地图上看到一张图片(只需创建一张带有 Map Title 的图片).它不是中心,您只能将控件放在四个角上.希望对您有所帮助!

I'd like to add a title to the whole map (different from the legend title: addLegend(..., title = "", ...): by "title", I mean an overlaid map component that stays in place while the map is moved (unlike an overlaid image).

Is that an option in RStudio's leaflet for R?

leafletR has a title="" argument but it updates the title of the webpage: it does not add a title to the map.

解决方案

You should provide a reproducible example. But using addControl you could try:

 library(leaflet)
 library(htmlwidgets)
 library(htmltools)

 rr <- tags$div(
   HTML('<a href="https://cran.r-project.org/"> <img border="0" alt="ImageTitle" src="/PathToImage/ImageR.jpeg" width="300" height="100"> </a>')
 )  

 map_leaflet <- leaflet() %>%
   addTiles() %>%
   addMarkers(50, 50) %>%
   addControl(rr, position = "bottomleft")

 saveWidget(map_leaflet, file="testing.html")

Open testing.html saved in your working directory and you will see an image (just create an image with Map Title in it) over your map. It is not center you can only put the control on the four corners. Hope it helps!

这篇关于R:为传单地图添加标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆