我正在尝试从Leaflet.js文档中找出如何在显示页面时打开多个弹出窗口.例如,如果有三个标记(每个代表一个建筑物),每个标记将立即打开它们的弹出窗口.
http://leaflet.cloudmade.com/reference.html#popup
神秘地说:
“使用Map#openPopup打开弹出窗口,同时确保一次只打开一个弹出窗口(推荐用于可用性),或使用Map#addLayer打开所需的多个.”
但
http://leaflet.cloudmade.com/reference.html#map-addlayer
没有提示如何实现这一点.
任何人都可以澄清这是否可行,并给出任何提示如何做到这一点?
解决方法
您必须将弹出窗口添加为图层.
尝试使用此示例代码: @H_502_21@var popupLocation1 = new L.LatLng(51.5,-0.09); var popupLocation2 = new L.LatLng(51.51,-0.08); var popupContent1 = '<p>Hello world!<br />This is a nice popup.</p>',popup1 = new L.Popup(); popup1.setLatLng(popupLocation1); popup1.setContent(popupContent1); var popupContent2 = '<p>Hello world!<br />This is a nice popup.</p>',popup2 = new L.Popup(); popup2.setLatLng(popupLocation2); popup2.setContent(popupContent2); map.addLayer(popup1).addLayer(popup2);
尝试使用此示例代码: @H_502_21@var popupLocation1 = new L.LatLng(51.5,-0.09); var popupLocation2 = new L.LatLng(51.51,-0.08); var popupContent1 = '<p>Hello world!<br />This is a nice popup.</p>',popup1 = new L.Popup(); popup1.setLatLng(popupLocation1); popup1.setContent(popupContent1); var popupContent2 = '<p>Hello world!<br />This is a nice popup.</p>',popup2 = new L.Popup(); popup2.setLatLng(popupLocation2); popup2.setContent(popupContent2); map.addLayer(popup1).addLayer(popup2);