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

How to add Layer on non Leaf node #71

Open ankitdhanai opened 8 months ago

ankitdhanai commented 8 months ago

As per the documentation of the plugin 'Non leaf nodes (that is, those with children) can also have a layer. In this case you will be able to select the layer, and only the icon will collapse or expand this branch'

When I tried to add layer to non leaf node...then instead of one checkbox ..2 checkbox are rendering for that node.... please help...thanks in advance

jjimenezshaw commented 8 months ago

Providing a simple self contained example that reproduces it will help.

ankitdhanai commented 8 months ago

sdsdf

Below is the object that I am trying to add as inner child: var innerchild = [{ label: 'France', selectAllCheckbox: true, layer: L.marker([52.9413240, 8.9581201]), children: [{ label: 'Tour Eiffel', layer: L.marker([48.8582441, 2.2944775]) }, { label: 'Notre Dame', layer: L.marker([48.8529540, 2.3498726]) }, { label: 'Louvre', layer: L.marker([48.8605847, 2.3376267]) }, ],

        }, {
            label: 'Germany',
            selectAllCheckbox: true,
            children: [{
                    label: 'Branderburger Tor',
                    layer: L.marker([52.5162542, 13.3776805])
                },
                {
                    label: 'Kölner Dom',
                    layer: L.marker([50.9413240, 6.9581201])
                },
            ]
        }, {
            label: 'Spain',
            layer: L.marker([52.9413240, 8.9581201]),
            selectAllCheckbox: 'De/seleccionar todo',
            children: [{
                    label: 'Palacio Real',
                    layer: L.marker([40.4184145, -3.7137051])
                },
                {
                    label: 'La Alhambra',
                    layer: L.marker([37.1767829, -3.5892795])
                },
            ]
        }]

Below is the code of how I add above inner child to overlays: overlaysTree = { label: "Overlay Layers", selectAllCheckbox: "Un/select all", children: [{ label: "States", selectAllCheckbox: "Un/select all", children: innerchild }, ], };

I have also attached screenshot with red color marker on right ...

What I am trying to achieve : Lets take example of airports of your docs... Suppose user selects Germany checkbox then polygon shape must appear on map for Germany ...and all the airports in Germany must be displayed as point ....and user can select and unselect any of these airports for displaying on map.

The problem of two checkbox is occurring when I set selectAllCheckbox option true for Germany and if I do not provide any selectAllCheckbox option then single checkbox is appearing for Germany but on selecting it...it is not selecting checkbox of all the airports in Germany.

However when I provide selectAllCheckbox true for germany the second checkbox is working as per my need but first checkbox is also appearing which is working independently that is when I select first checkbox all the airports in Germany are not getting selected .

Thanks

ankitdhanai commented 8 months ago

Have you looked into this issue? Thanks

jjimenezshaw commented 8 months ago

No, sorry, I had no time. I cannot ensure that I will have time in the near future. What I remember is that the checkboxes feature was added much later than the non-leaf with layer. Probably I never tested checkboxes in a non-leaf node with a layer. One explanation could be that there are two checkboxes, one for the non-leaf layer itself, and another to control the children. ... but do you really need a layer in that non-leaf node?

ankitdhanai commented 8 months ago

Sorry...but yes....I need layer in non leaf node...thanks