1. <i id='l8fJG'><tr id='l8fJG'><dt id='l8fJG'><q id='l8fJG'><span id='l8fJG'><b id='l8fJG'><form id='l8fJG'><ins id='l8fJG'></ins><ul id='l8fJG'></ul><sub id='l8fJG'></sub></form><legend id='l8fJG'></legend><bdo id='l8fJG'><pre id='l8fJG'><center id='l8fJG'></center></pre></bdo></b><th id='l8fJG'></th></span></q></dt></tr></i><div id='l8fJG'><tfoot id='l8fJG'></tfoot><dl id='l8fJG'><fieldset id='l8fJG'></fieldset></dl></div>

      <tfoot id='l8fJG'></tfoot><legend id='l8fJG'><style id='l8fJG'><dir id='l8fJG'><q id='l8fJG'></q></dir></style></legend>

      <small id='l8fJG'></small><noframes id='l8fJG'>

        • <bdo id='l8fJG'></bdo><ul id='l8fJG'></ul>

        Leafletjs - marker.bindPopup - 保持所有弹出窗口打开

        时间:2023-08-09

        <legend id='fNDZs'><style id='fNDZs'><dir id='fNDZs'><q id='fNDZs'></q></dir></style></legend>
        • <bdo id='fNDZs'></bdo><ul id='fNDZs'></ul>

          <small id='fNDZs'></small><noframes id='fNDZs'>

          <tfoot id='fNDZs'></tfoot>
            <i id='fNDZs'><tr id='fNDZs'><dt id='fNDZs'><q id='fNDZs'><span id='fNDZs'><b id='fNDZs'><form id='fNDZs'><ins id='fNDZs'></ins><ul id='fNDZs'></ul><sub id='fNDZs'></sub></form><legend id='fNDZs'></legend><bdo id='fNDZs'><pre id='fNDZs'><center id='fNDZs'></center></pre></bdo></b><th id='fNDZs'></th></span></q></dt></tr></i><div id='fNDZs'><tfoot id='fNDZs'></tfoot><dl id='fNDZs'><fieldset id='fNDZs'></fieldset></dl></div>
                <tbody id='fNDZs'></tbody>

                  本文介绍了Leafletjs - marker.bindPopup - 保持所有弹出窗口打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在使用传单打开所有弹出窗口时遇到了一些困难.

                  I am having some difficulty keeping all the popups open with leaflet.

                  我在 a 循环中有以下代码,用于向 LayerGroup 添加标记(ajax 自动更新).

                  I have the following code in the a loop to add markers to a LayerGroup (ajax auto-updating).

                  var marker = L.marker([value.position.lat, value.position.lon],options).addTo(markers);
                  allpoints.push([value.position.lat, value.position.lon]);
                  marker.bindPopup("InfoWindow",{closeOnClick:false,closeButton:false}).openPopup();
                  

                  它工作得很好,除了它只保持最后一个弹出窗口打开.我想保持所有这些开放.我确实在这里(stackoverflow)上找到了一篇关于使用不同标记名称这样做的文章,但是我有这个循环.我确实尝试将 L.marker 放入数组中,但传单不喜欢那样.

                  It works great, except it only keeps the last popup open. I would like to keep all of them open. I did find an article on here (stackoverflow) regarding doing so with different marker names, however I have this in a loop. I did try putting L.marker into an array, but leaflet did not like that.

                  有什么想法吗?

                  推荐答案

                  你需要重写 Leaflet Map 上的 openpopup 方法,用这个方法的副本替换它,只注释掉调用 this.closePopup();

                  You will need to override the openpopup method on the Leaflet Map, replacing it with a copy of this method, only comment out the line that calls this.closePopup();

                  在您的页面上添加

                  L.Map = L.Map.extend({
                      openPopup: function (popup, latlng, options) { 
                          if (!(popup instanceof L.Popup)) {
                          var content = popup;
                  
                          popup = new L.Popup(options).setContent(content);
                          }
                  
                          if (latlng) {
                          popup.setLatLng(latlng);
                          }
                  
                          if (this.hasLayer(popup)) {
                          return this;
                          }
                  
                          // NOTE THIS LINE : COMMENTING OUT THE CLOSEPOPUP CALL
                          //this.closePopup(); 
                          this._popup = popup;
                          return this.addLayer(popup);        
                      }
                  });
                  

                  http://jsfiddle.net/yVLJf/37/

                  您可以在此处找到原始 Leaflet openPopup 方法:https://github.com/Leaflet/Leaflet/blob/1acffc5a3d31010b7d613382ab2a5830ecee5dd5/src/layer/Popup.js#L290

                  You can find the original Leaflet openPopup method here: https://github.com/Leaflet/Leaflet/blob/1acffc5a3d31010b7d613382ab2a5830ecee5dd5/src/layer/Popup.js#L290

                  这篇关于Leafletjs - marker.bindPopup - 保持所有弹出窗口打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Leaflet _ ReactJS - 在哪里可以找到 invalidateSize 属性 下一篇:使用markercluster对多个图层进行聚类

                  相关文章

                  最新文章

                  <legend id='OJ0kW'><style id='OJ0kW'><dir id='OJ0kW'><q id='OJ0kW'></q></dir></style></legend>

                    <small id='OJ0kW'></small><noframes id='OJ0kW'>

                    <tfoot id='OJ0kW'></tfoot>

                    • <bdo id='OJ0kW'></bdo><ul id='OJ0kW'></ul>
                    <i id='OJ0kW'><tr id='OJ0kW'><dt id='OJ0kW'><q id='OJ0kW'><span id='OJ0kW'><b id='OJ0kW'><form id='OJ0kW'><ins id='OJ0kW'></ins><ul id='OJ0kW'></ul><sub id='OJ0kW'></sub></form><legend id='OJ0kW'></legend><bdo id='OJ0kW'><pre id='OJ0kW'><center id='OJ0kW'></center></pre></bdo></b><th id='OJ0kW'></th></span></q></dt></tr></i><div id='OJ0kW'><tfoot id='OJ0kW'></tfoot><dl id='OJ0kW'><fieldset id='OJ0kW'></fieldset></dl></div>