2014-01-27 39 views
2

我有一個傳單地圖,我想要打開它後彈出closeOnClick屬性。我試過這段代碼,但它不起作用。單張彈出更新closeOnClick

// at build 
var mapPopupOptions = {maxWidth:600,minWidth:300}; 
var popup = new L.popup(mapPopupOptions).setContent("hello world"); 

// elsewhere after popup is open 
popup.options.closeOnClick = false; 

參考:http://leafletjs.com/reference.html#popup

+0

你是什麼意思'它不工作'?你有什麼錯誤嗎? – RezaSh

+0

我能夠最初通過mapPopupOptions中的closeOnClick選項,並且一切正常。我希望能夠選擇性地「鎖定」彈出窗口,以便點擊地圖不會關閉它。如果我嘗試在地圖上創建並顯示彈出框後嘗試手動設置popup.options,那麼我無法更改此行爲 – Rayliu521

回答

0

而是從popup VAR引用您最初的彈出式菜單,您可以通過標記本身的實際彈出參考。

// elsewhere after the popup is open 
var marker = // This is the marker are attempting to modify popup behavior 
var popup = marker.getPopup(); 
// Modify the popup now 
popup.setContent("This popup has changed!", { closeOnClick: false }); 

這很可能是popup對象你引用是不是正在使用的要修改的標記實際彈出對象。

+0

我試過了您的答案,但不幸的是它無效,內容設置正確,但closeOnclick選項保留不變 – Rayliu521

+0

有沒有可以展示的JSFiddle? –