-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding feature to make individual groups collapsable #46
base: gh-pages
Are you sure you want to change the base?
Changes from 4 commits
af52090
515dc04
e29fa73
3e7f28a
c788ee6
76f8766
60db308
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,10 @@ L.Control.GroupedLayers = L.Control.extend({ | |
position: 'topright', | ||
autoZIndex: true, | ||
exclusiveGroups: [], | ||
groupCheckboxes: false | ||
groupCheckboxes: false, | ||
groupsCollapsable: false, | ||
groupsCollapseClass: "leaflet-control-layers-group-collapse-default", | ||
groupsExpandClass: "leaflet-control-layers-group-expand-default", | ||
}, | ||
|
||
initialize: function (baseLayers, groupedOverlays, options) { | ||
|
@@ -66,7 +69,7 @@ L.Control.GroupedLayers = L.Control.extend({ | |
var id = L.Util.stamp(layer); | ||
var _layer = this._getLayer(id); | ||
if (_layer) { | ||
delete this.layers[this.layers.indexOf(_layer)]; | ||
this._layers.splice(this._layers.indexOf(_layer), 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bug fix independent from my collapsable groups feature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! Someone else opened a PR for this which I just merged (#50). Can you take this commit out of your branch? |
||
} | ||
this._update(); | ||
return this; | ||
|
@@ -276,6 +279,21 @@ L.Control.GroupedLayers = L.Control.extend({ | |
} | ||
} | ||
|
||
if (this.options.groupsCollapsable){ | ||
groupContainer.classList.add("group-collapsable"); | ||
groupContainer.classList.add("collapsed"); | ||
|
||
var groupMin = document.createElement('span'); | ||
groupMin.className = 'leaflet-control-layers-group-collapse '+this.options.groupsCollapseClass; | ||
groupLabel.appendChild(groupMin); | ||
|
||
var groupMax = document.createElement('span'); | ||
groupMax.className = 'leaflet-control-layers-group-expand '+this.options.groupsExpandClass; | ||
groupLabel.appendChild(groupMax); | ||
|
||
L.DomEvent.on(groupLabel, 'click', this._onGroupCollapseToggle, groupContainer); | ||
} | ||
|
||
var groupName = document.createElement('span'); | ||
groupName.className = 'leaflet-control-layers-group-name'; | ||
groupName.innerHTML = obj.group.name; | ||
|
@@ -296,8 +314,19 @@ L.Control.GroupedLayers = L.Control.extend({ | |
|
||
return label; | ||
}, | ||
|
||
_onGroupCollapseToggle: function (event) { | ||
L.DomEvent.stopPropagation(event); | ||
L.DomEvent.preventDefault(event); | ||
if (this.classList.contains("group-collapsable") && this.classList.contains("collapsed")){ | ||
this.classList.remove("collapsed"); | ||
}else if (this.classList.contains("group-collapsable") && !this.classList.contains("collapsed")){ | ||
this.classList.add("collapsed"); | ||
} | ||
}, | ||
|
||
_onGroupInputClick: function () { | ||
_onGroupInputClick: function (event) { | ||
L.DomEvent.stopPropagation(event); | ||
var i, input, obj; | ||
|
||
var this_legend = this.legend; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you switch to two-space tabs please? I know the repo doesn't have anything fancy to check for that (and might even have some inconsistencies due to other PRs 🙈 ), so try to match the existing indentation whenever possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I designed the improvements to be disabled by default so that it doesn't cause problems with older configurations, so upgrading should have no problems.
I will try finding time in the next few days to revisit the code and make the requested changes.