leaflet-groupedlayercontrol icon indicating copy to clipboard operation
leaflet-groupedlayercontrol copied to clipboard

Add option to collapse groups

Open ccloquet opened this issue 10 years ago • 11 comments

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+"'>&nbsp-</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() == "&nbsp;+")
    {
        $("#leaflet-control-"+myid).children().show()
        $("#"+myid).html("&nbsp;-")
    }
    else
    {
        $("#leaflet-control-"+myid).children().hide()
        $("#"+myid).html("&nbsp;+")
    }
})

Best regards,

ccloquet avatar Feb 24 '15 22:02 ccloquet

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.

brentfraser avatar Aug 12 '15 16:08 brentfraser

Any news about this feature?

Asph91 avatar Oct 29 '15 12:10 Asph91

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.

ismyrnow avatar Oct 29 '15 15:10 ismyrnow

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...

brentfraser avatar Oct 29 '15 16:10 brentfraser

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.

dosstx avatar Dec 11 '15 11:12 dosstx

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!

jerryhall avatar Aug 29 '16 22:08 jerryhall

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...

brentfraser avatar Aug 30 '16 02:08 brentfraser

Apparently this fork does it. @tsrman, would you be interested in rebasing and doing a PR?

grischard avatar Nov 28 '16 08:11 grischard

Im litte bit busy for this time, i try create pull request on next week.

tsrman avatar Nov 28 '16 08:11 tsrman

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.

Randy6668 avatar Mar 02 '17 02:03 Randy6668

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?

hjrobinson avatar May 27 '18 15:05 hjrobinson