[英]R: Add title to Leaflet map
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) 我想为整个地图添加一个标题(与图例标题不同: addLegend(...,title =“”,...) :“title”,我的意思是一个保留在原位的重叠地图组件移动地图时(与重叠图像不同)
.
。
Is that an option in RStudio's leaflet for R? 这是RStudio的R 传单中的一个选项吗?
leafletR has a title="" argument but it updates the title of the webpage: it does not add a title to the map. leafletR有一个title =“”参数,但它更新了网页的标题:它没有为地图添加标题。
You should provide a reproducible example. 您应该提供可重现的示例。 But using
addControl
you could try: 但是使用
addControl
你可以尝试:
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. 打开testing.html保存在您的工作目录中,您将在地图上看到一个图像(只是在其中创建一个带有地图标题的图像)。 It is not center you can only put the control on the four corners.
它不是中心,你只能将控制放在四个角上。 Hope it helps!
希望能帮助到你!
@MLavoie's idea is correct, but I was looking for something more specific like this: @ MLavoie的想法是正确的,但我正在寻找更具体的东西:
tag.map.title <- tags$style(HTML("
.leaflet-control.map-title {
transform: translate(-50%,20%);
position: fixed !important;
left: 50%;
text-align: center;
padding-left: 10px;
padding-right: 10px;
background: rgba(255,255,255,0.75);
font-weight: bold;
font-size: 28px;
}
"))
title <- tags$div(
tag.map.title, HTML("Map title")
)
map_leaflet <- leaflet() %>%
addTiles() %>%
addControl(title, position = "topleft", className="map-title")
This will center the leaflet-control
title as shown in the screenshot and place it at the top. 这将使
leaflet-control
标题居中,如屏幕截图所示,并将其置于顶部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.