2014-01-27 38 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? –