1. <small id='589Oh'></small><noframes id='589Oh'>

      <bdo id='589Oh'></bdo><ul id='589Oh'></ul>
    <tfoot id='589Oh'></tfoot>

  2. <legend id='589Oh'><style id='589Oh'><dir id='589Oh'><q id='589Oh'></q></dir></style></legend>

    1. <i id='589Oh'><tr id='589Oh'><dt id='589Oh'><q id='589Oh'><span id='589Oh'><b id='589Oh'><form id='589Oh'><ins id='589Oh'></ins><ul id='589Oh'></ul><sub id='589Oh'></sub></form><legend id='589Oh'></legend><bdo id='589Oh'><pre id='589Oh'><center id='589Oh'></center></pre></bdo></b><th id='589Oh'></th></span></q></dt></tr></i><div id='589Oh'><tfoot id='589Oh'></tfoot><dl id='589Oh'><fieldset id='589Oh'></fieldset></dl></div>
    2. Leaflet Markercluster:从聚类中免除标记

      时间:2023-08-09

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

          <bdo id='Xly9J'></bdo><ul id='Xly9J'></ul>

            <tbody id='Xly9J'></tbody>
        • <tfoot id='Xly9J'></tfoot>

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

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

              1. 本文介绍了Leaflet Markercluster:从聚类中免除标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                如何在缩小时检查带有打开弹出窗口的标记以防止折叠成簇?

                How can one exampt a marker with open popup from collapsing into a cluster when zooming out?

                我正在使用 leaflet 和 markercluster 在 这个例子:

                I am using leaflet and markercluster as set up in this example:

                HTML:

                <div id="map"></div>
                

                CSS:

                html,
                body {
                  height: 100%;
                }
                
                #map {
                  height: 100%;
                }
                

                JS:

                const map = L.map('map', {
                    zoom: 5,
                    center: [0,0],
                    maxZoom: 18
                });
                const clustered = L.markerClusterGroup();
                map.addLayer(clustered);
                
                const m1 = L.marker(L.latLng(0,0));
                m1.addTo(clustered);
                m1.bindPopup('one');
                
                const m2 = L.marker(L.latLng(0,1));
                m2.addTo(clustered);
                m2.bindPopup('two');
                
                const m3 = L.marker(L.latLng(1,0));
                m3.addTo(clustered);
                m3.bindPopup('three');
                

                我想暂时避免标记折叠成一个集群只要它的弹出窗口是打开的.例如,这意味着:

                I would like to temporarily exempt a marker from collapsing into a cluster as long as its popup is open. For the example, this would mean:

                1. 放大直到看到各个标记.

                1. Zoom in until you see the individual markers.

                单击一个以打开一个弹出窗口.

                Click one to open a popup.

                再次缩小.

                弹出"标记应与打开的弹出窗口一起可见.剩余的标记应该折叠起来.

                The "popped up" marker should be visible, together with the open popup. The remaining markers should collapse.

                1. 当弹出窗口关闭时,标记应该消失在集群中.

                我尝试在 popupopen(和 popupclose)上将标记临时移动到地图(并返回),但这不起作用:

                I've tried to temporarily move the marker to the map (and back) on popupopen (and popupclose), but this does not work:

                map.on('popupopen', function(e) {
                    const m = e.popup._source;
                    clustered.removeLayer(m);
                    map.addLayer(m);
                });
                map.on('popupclose', function(e) {
                    let m = e.popup._source;
                    map.removeLayer(m);
                    clustered.addLayer(m);
                });
                

                有什么想法吗?

                推荐答案

                现在 这个 似乎正在工作.我必须添加一个单独的层unclustered,只在集群层处理popupopen,只在非集群层处理popupclose

                Now this seems to be working. I had to add a separate layer unclustered, and handle popupopen only in the clustering layer, and popupclose only in the unclustered layer

                const unclustered = L.markerClusterGroup(); // NOTE
                map.addLayer(unclustered);
                clustered.on('popupopen', function(e) {
                    console.log('open');
                    const m = e.popup._source;
                    clustered.removeLayer(m);
                    unclustered.addLayer(m);
                    m.openPopup();
                });
                unclustered.on('popupclose', function(e) {
                    console.log('close');
                    let m = e.popup._source;
                    unclustered.removeLayer(m);
                    clustered.addLayer(m);
                    m.closePopup();
                });
                

                注意:我不喜欢将 L.markerClusterGroup 用于非集群层.但我不知道还有什么.只要该层中只有一个标记,它就会起作用.但是为了避免多个标记折叠成一个簇,必须使用不同的层.哪一个?L.layerGroup 不起作用.

                NOTE: I'm not happy with using L.markerClusterGroup for the unclustered layer. But I would not know what else. As long as there's only one marker in that layer, it will work. But to exempt multiple markers from collapsing into a cluster, a different layer must be used. Which one? L.layerGroup does not work.

                这篇关于Leaflet Markercluster:从聚类中免除标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:传单:使用 CircleMarkers 包含元数据 下一篇:传单正方形给定中心和正方形宽度

                相关文章

                最新文章

                    <bdo id='miUmm'></bdo><ul id='miUmm'></ul>
                1. <small id='miUmm'></small><noframes id='miUmm'>

                    <tfoot id='miUmm'></tfoot>
                  1. <legend id='miUmm'><style id='miUmm'><dir id='miUmm'><q id='miUmm'></q></dir></style></legend>

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