Add option to control group/layer listing order #3

Closed
mjigmond opened this Issue Dec 26, 2013 · 5 comments

Projects

None yet

3 participants

Currently the groups and layers seem to be ordered arbitrarily in the control panel. It would be nice to preserve the order from the group definition or specify the order via a flag.

Owner
ismyrnow commented Feb 1, 2014

Can you provide an example? Does it behave similarly with the built-in control?

I render the layers almost exactly how the built-in layer control does it, for consistency. If their control has a bug in this area as well, it may be worth fixing in both places.

Contributor
blomm commented Feb 1, 2014

Hi there, i prob won't find the time to put together an example, but i did check the leaflet layer control works fine, it was only an issue in the grouped control, because of the grouping.

mjigmond commented Feb 3, 2014

Here's the issue I'm having: http://jsfiddle.net/wzLp4/. This is your example but I switched the order of Cities (1) and Motorways (2) layers in the groupedOverlays yet they show up as Motorways (1) and Cities (2). Do I have the wrong expectation as to how layers will be ordered? Based on some trials I've done this may be related to Leaflet.

Owner

@mjigmond take a look at this modified fiddle: http://jsfiddle.net/ismyrnow/wzLp4/1/

The only difference is the order the layers are added to the map (not the layer control). This behavior is also exhibited by Leaflet's layer control.

I would love to get this fixed, and even submit a pull request to Leaflet if it makes sense, since this seems like a bug to me as well. I doubt I'll have time to fix this, but I'll accept a pull request.

I believe the issue lies around line 115, where the layer is given a unique ID. Leaflet's control does it the same way, but I believe this is what's causing the strange behavior.

The problem (for me anyway) is that I don't want all layers to be enabled on page load. So if I want just one overlay out of ten to be enabled, that overlay will always be first in the list even if I want it at the bottom of the list (http://jsfiddle.net/wzLp4/2/). I'm more of a user than a developer and never really dissected one of these libraries but I'll take a look. I'll also look through the issues raised on Leaflet regarding layer ordering. Thanks for taking a look. For my purposes your plugin is great once I solve the ordering.

@ismyrnow ismyrnow added the enhancement label Aug 4, 2014
@ismyrnow ismyrnow closed this Jul 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment