leaflet-groupedlayercontrol
leaflet-groupedlayercontrol copied to clipboard
Add option to collapse groups
Dear contributors,
I would find nice to implement some sort of collapsing of the groups. Here is how I did it quick and dirty with jqm :
if (!groupContainer) {
[...]
groupLabel.innerHTML = obj.group.name + "<span class='group-button' id='layers-group-"+obj.group.id+"'> -</span>";
container.appendChild(groupLabel);
container.appendChild(groupContainer);
[...]
}
At the end, added :
$('body').delegate('.group-button', 'click', function()
{
var myid = $(this)[0].id
console.log(myid)
if ($("#"+myid).html() == " +")
{
$("#leaflet-control-"+myid).children().show()
$("#"+myid).html(" -")
}
else
{
$("#leaflet-control-"+myid).children().hide()
$("#"+myid).html(" +")
}
})
Best regards,
Interesting enhancement. I implemented the above code in v0.3.1 but the parent disappears as well as the children making it impossible to expand after a collapse.
Any news about this feature?
I'm not planning to add this feature myself. If someone wanted to fork and add this functionality, I'd consider merging it.
It would need to be opt-in functionality (via advanced options), and not introduce any new dependencies, like jQuery. It would also need to play nicely with the layer group toggle functionality added by @brentfraser in v0.4.0.
I really like the idea of this feature, so some requirements:
- no new dependencies
- use a graphic for the collapse/expand functionality (some kind of folder icon?)
- as I recall, my group checkbox works on clicking anywhere on the group name so that would have to be changed...
Please add this feature. I often have to deal with lots of feature categories and subcategories (100+) in my projects and need a way to consolidate all that in the control. For now, I'm reverting to css overflow:auto to allow scrolling, but it's messy.
Don't know if you've seen this but, here's a model that collapses: https://jsfiddle.net/gaby/La77L8L9/2/ which I'm not sure meets your dependency criteria. Thanks for your work on this as well!
I like it (basemaps on the bottom of the list where they should be. WooHoo!). but it looks like only one category at a time can be expanded. I'll need to dig into it...
Apparently this fork does it. @tsrman, would you be interested in rebasing and doing a PR?
Im litte bit busy for this time, i try create pull request on next week.
By any chance a working version of collapsible group be implemented? I've tried the for @grischard suggested, but there are no expanded layers beneath.
Okay, so I used the fork, but the only way I can add polygons to the layer control (and avoiding a failed page load) is by extracting coordinates from a geoJSON file and adding them to into a polygon. I guess I could try to write a loop to convert the text, but is there a way to get L.geoJSON directly into the layer instead of using L.polygon?