R传单:添加多边形时传递popupOptions. [英] R Leaflet: Passing popupOptions when adding Polygons.
问题描述
在addPolygons()
中,有一个popup
参数,就像addPopups()
函数中的参数一样.区别(我认为)是,在addPolygons()
中创建弹出窗口时,可以单击多边形内的任意位置以触发弹出窗口,但是如果使用addPopups()
,则必须在单个c3和c6点上定义.
Within addPolygons()
there is a popup
parameter just like the one in the addPopups()
function. The difference (I think) is that when the popup is created within addPolygons()
, one can click anywhere within the polygon to trigger the popup, but if addPopups()
is used, a single lng
and lat
point must be defined.
我想更改popupOptions()
中的默认选项(maxWidth
)之一,使用addPopups()
时可以轻松完成,因为它包含参数options = popupOptions()
,但是我不知道该怎么做使用addPolygons()
;在该函数中,options参数为options = pathOptions()
.
I want to change one of the default options (maxWidth
) in popupOptions()
which can easily be done when using addPopups()
because it contains the parameter options = popupOptions()
but I don't know how to do it when using addPolygons()
; within that function the options parameter is options = pathOptions()
.
下面是传单文档中的可复制示例,其中添加了一个弹出窗口,我想增加maxWidth
.
Below is a reproducible example from the leaflet documentation with a popup added that I'd like increase the maxWidth
.
library(rgdal)
# From https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html
states <- readOGR("shp/cb_2013_us_state_20m.shp",
layer = "cb_2013_us_state_20m", verbose = FALSE)
neStates <- subset(states, states$STUSPS %in% c(
"CT","ME","MA","NH","RI","VT","NY","NJ","PA"
))
leaflet(neStates) %>%
addPolygons(
stroke = FALSE, fillOpacity = 0.5, smoothFactor = 0.5,
color = ~colorQuantile("YlOrRd", states$AWATER)(AWATER),
popup="<b>Hello World</b>"
)
推荐答案
您可以通过在addPloygons()
块中的弹出窗口之后添加popupOptions()
来简单地做到这一点,如下所示:
You can do this simply by adding popupOptions()
after your popup in the addPloygons()
block like so:
leaflet(neStates) %>%
addPolygons(
stroke = FALSE, fillOpacity = 0.5, smoothFactor = 0.5,
color = ~colorQuantile("YlOrRd", states$AWATER)(AWATER),
popup="<b>Hello World</b>"
popupOptions = popupOptions(maxWidth ="100%", closeOnClick = TRUE)
)
以下是活页R上的PDF小插图中您可以放入popupOptions()
列表中的所有内容的列表:
Here is the list from the PDF vignette on leaflet R of all the things you can drop in the popupOptions()
list:
popupOptions(maxWidth = 300, minWidth = 50, maxHeight = NULL,
autoPan = TRUE, keepInView = FALSE, closeButton = TRUE,
zoomAnimation = TRUE, closeOnClick = NULL, className = "", ...)
这篇关于R传单:添加多边形时传递popupOptions.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!