在传单包中使用popupOptions() [英] Use of popupOptions() in leaflet package
问题描述
我正在关注Robin Lovelace博客上的传单教程 ( http://robinlovelace.net/r/2015/02/01/leaflet-r-package.html ). 我的以下代码运行正常:
I am following the leaflet tutorial on Robin Lovelace's blog (http://robinlovelace.net/r/2015/02/01/leaflet-r-package.html). My code below works fine:
# Install leaflet package
if(!require(leaflet)) install_github("rstudio/leaflet")
# Plot a default web map (brackets display the result)
m <- leaflet() %>% addTiles(m,urlTemplate = "http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png")
m %>% setView(lng = -1.5, lat = 53.4, zoom = 10) # set centre and extent of map
m2 <- m %>%
setView(-1.5, 53.4, 10) %>% # map location
addMarkers(-1.4, 53.5) %>% # add a marker
addPopups(-1.6, 53.3, popup = "Hello Sheffield!",options=list(closeButton=FALSE))
m2
但是addPopups的选项包含在addPopup位中.如何使用popupOptions()命令?
But the options for the addPopups is enclosed in the addPopup bit. How do I use the popupOptions() command?
我想是这样的:
# Plot a default web map (brackets display the result)
m <- leaflet() %>% addTiles(m,urlTemplate = "http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png")
m %>% setView(lng = -1.5, lat = 53.4, zoom = 10) # set centre and extent of map
m2 <- m %>%
setView(-1.5, 53.4, 10) %>% # map location
addMarkers(-1.4, 53.5) %>% # add a marker
addPopups(-1.6, 53.3, popup = "Hello Sheffield!") %>%
popupOptions(closeButton=FALSE) ##NEW BIT
m2
但是地图中未使用popupOptions(x框在其中).
But popupOptions isn't used in the map (the x box is there).
我在做什么错了?
欢呼
推荐答案
只需使用popupOptions
创建一个选项列表,然后进入options
arg.它将使用默认值填充所有其他值:
Just use popupOptions
to create a list of options that then goes into the options
arg. It fills in all the other ones with defaults:
leaflet() %>% addTiles() %>%
addPopups(-1.6, 53.5,popup="Hello Sheffield",options=popupOptions(closeButton=FALSE))
如果仅键入popupOptions(closeButton=FALSE)
,您将在示例中看到传递给options=
的大列表.
If you just type popupOptions(closeButton=FALSE)
you'll see the big list that is getting passed to options=
in the example.
这篇关于在传单包中使用popupOptions()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!