jjimenezshaw / Leaflet.Control.Layers.Tree

a Tree Layers Control for Leaflet
https://jjimenezshaw.github.io/Leaflet.Control.Layers.Tree/examples/basic.html
BSD 3-Clause "New" or "Revised" License
146 stars 36 forks source link

leaflet.control.layers.tree same layer in different group #28

Closed Dinuxax100 closed 4 years ago

Dinuxax100 commented 4 years ago

Hi,

In leaflet.control.layers.tree, i have same layer in different children group. On selecting the layer in one group, need to select the same layer in all other group. same goes to unchecked.

Can you help on this.

Thanks.

jjimenezshaw commented 4 years ago

I think the problem is in the Control.Layers class, not in Layers.Tree

With this function you can more or less workaround it

        function multiCheckbox(layer, control) {
            list_input=[];
            control.getContainer().querySelectorAll('input').forEach(input => {
                if (input.layerId && input.layerId === L.Util.stamp(layer)) {
                    list_input.push(input);
                    L.DomEvent.on(input, 'click', function(ev){
                        list_input.forEach(i => {
                            if(i.checked !== input.checked) i.click();
                        });
                    });
                }
            });
        }

And call it with the layers you know are duplicated. In the example options.html, I created another entry "sevilla" and added with multiCheckbox(sevilla, lay); However it does not work in some scenarios if you use selectAllCheckbox.

Dinuxax100 commented 4 years ago

Thanks for your code. It's working.