davicustodio / Leaflet.StyledLayerControl

A styled Leaflet plugin that implements the management and control of layers by organization into categories or groups
Other
119 stars 46 forks source link

addOverlay options #48

Open a-lurker opened 5 years ago

a-lurker commented 5 years ago

Hello there. Like the control but a few issues that can generally be worked around by making sure every call to control.addOverlay always specifies every option consistently.

1st issue: Layers that get their data using AJAX need to use addOverlay once the data is ready. If there is more than one layer using AJAX, then you have two calls to addOverlay, say like this:

control.addOverlay( corn_bh, "Corn Plant", {groupName : "Belo Horizonte"} ); control.addOverlay(bean_bh, "Bean Plant", {groupName : "Belo Horizonte"} );

this will load null into 'expanded' and 'removable'. See lines starting at 257.

2nd issue: You can also do this:

control.addOverlay( corn_bh, "Corn Plant", {groupName : "Belo Horizonte", expanded: true} ); control.addOverlay(bean_bh, "Bean Plant", {groupName : "Belo Horizonte", expanded: false} );

Each layer keeps a record of its group settings but now the group settings are inconsistent for 'expanded'. See also lines starting at 257. This a design issue. There needs to be one only set of options for each group. Not a copy for every layer.

3rd issue: If you leave out the group name, the code produces an error. Eg:

control.addOverlay( corn_bh, "Corn Plant" );

A default group name would help the programmer identify this error.

So before the lines starting at 257. Need something similar to this at a minimum:

if ((typeof group.groupName !== 'string') || (group.groupName === '')) group.groupName = 'Group name not specified'; if (typeof group.expanded !== 'boolean') group.expanded = true; if (typeof group.removable !== 'boolean') group.removable = false;

Not even too sure 'group.removable' is correct, as it appears to be inconsistent with line 391. Are they meant to be the same option?

obj.layer.StyledLayerControl.removable