Leaflet.StyledLayerControl icon indicating copy to clipboard operation
Leaflet.StyledLayerControl copied to clipboard

expanded: true opens all groups

Open letmaik opened this issue 9 years ago • 4 comments

When I add a layer to a group (or implicitly create a new group), I want that group to be expanded, but not the other groups. When I set expanded: true in the options for addOverlay it opens all groups which I think is a bug.

letmaik avatar Oct 30 '15 18:10 letmaik

Do it this way instead:

var baseLayers = [ { groupName : "Base Maps", expanded : true, layers : { "LINZ Aerials": aerials, "Topo50": topo50, "OpenStreetMap": osm, "Google Terrain": gTerrain, "Google Hybrid": gHybrid } }
];

        var overlays = [
                        {
                            groupName : "Species Distribution",
                            layers    : { 
                                        "Feral Pig 2007": pigs,
                                                        "Feral Goat 2007": goats,
                                                        "Fallow Deer 2007": fallow,
                                                        "Red Deer 2007": red,
                                                        }   
                                                     }, {
                            groupName : "Points of Interest",
                            expanded : true,
                            layers    : { 
                                        "DOC Campsites": campsites,
                                                        "DOC Huts": huts        
                                            }   
                                                     }                       
        ];

This makes the Basemaps layer group expanded by default. Species Distribution overlay group is collapsed by default, and Points of Interest overlay group is expanded by default.

Check out my example: https://dl.dropboxusercontent.com/u/7075784/Leaflet/Leaflet2.html

stretchkerr avatar Oct 30 '15 21:10 stretchkerr

I'm not sure how this solves my problem. Maybe I wasn't precise enough, but this happens when I'm dynamically adding groups and layers, not when I initialize the control. When I dynamically add a new group with expanded: true then it also expands all other groups. But I want the existing groups to stay in whichever state they are.

letmaik avatar Oct 30 '15 21:10 letmaik

@neothemachine I understand the problem. Really I did not write the ability to expand a group dynamically. I am currently struggling to find time to update the plugin, but if you are willing to look at the code and create a pull request ...

davicustodio avatar Feb 25 '16 12:02 davicustodio

@stretchkerr I enjoyed its application in https://dl.dropboxusercontent.com/u/7075784/Leaflet/Leaflet2.html I realized that their implementation is still a problem (I just load the last commit) related to the automatic resizing of the control relative to the main application window.

Taking advantage of you is already with that application in a production environment? If so, you could share the link?

Thank you.

davicustodio avatar Feb 25 '16 12:02 davicustodio