2016-06-14 31 views
1

addPolygons()之內有一個popup參數,就像addPopups()函數中的參數一樣。不同的(我認爲)是當在addPolygons()內創建彈出窗口時,可以點擊多邊形內的任何地方以觸發彈出窗口,但是如果使用addPopups(),則必須定義單個點lnglat點。R小冊子:添加多邊形時傳遞popupOptions。

我想改變的使用addPopups()時,因爲它包含的參數options = popupOptions()這很容易做到在popupOptions()默認選項(maxWidth)之一,但我不知道如何使用addPolygons()時候做;在該功能中,選項參數是options = pathOptions()

下面是一個可重複的例子,其中彈出式菜單文檔中增加了一個我想增加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>" 
) 

enter image description here

+1

目前不可能,儘管已經實施爲拉取請求。見這裏https://github.com/rstudio/leaflet/issues/258 – TimSalabim

回答

0

您只需在addPloygons()塊彈出式窗口後,加入popupOptions()像這樣做:

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) 

下面是從PDF小插曲列表在小冊子R中您可以在popupOptions()列表中刪除所有東西:

popupOptions(maxWidth = 300, minWidth = 50, maxHeight = NULL, 
      autoPan = TRUE, keepInView = FALSE, closeButton = TRUE, 
      zoomAnimation = TRUE, closeOnClick = NULL, className = "", ...) 
相關問題