Leaflet.StyledLayerControl icon indicating copy to clipboard operation
Leaflet.StyledLayerControl copied to clipboard

maintain order of layers in menu?

Open pacioos opened this issue 10 years ago • 8 comments

Thanks for this Leaflet plugin--it's great. One thing I've had difficulty with, however, is trying to put the layers and groups into a specific order. Regardless of the order in which I define them inside my overlayMaps object, they show up in the layer control in seemingly arbitrary fashion. Thoughts?

pacioos avatar Mar 27 '15 19:03 pacioos

I've got the same problem, but at least I found a way to work around it:

I think, the groups with layers, that were added to the map in the Javascript-Code (map.addLayer(var);) are placed over the groups only with layers that were not added to the map:

I have 1 or 2 layers in each group, in groups with 2 layers, the first one is added to the map, in groups with 1 layer, nothing is added to the map. Result: The groups with only one layer are shown below the groups with 2 layers. If I also add the layer in the 1-layer-groups to the map, the order is OK.

For now, I have to add at least one layer from each group or only one layer from the first group, then it works. Thats no problem in my project, but of course it would be easier if the order of the groups would only be defined by their order in the overlay-layers-list.

DavidZebris avatar Jun 09 '15 15:06 DavidZebris

I found the same problem in regards to the display order of the layers. In my case, the easiest solution was to create my feature groups in the order that I would want to see them. There was then no issue with the display ordering.

Thanks to Davi for providing a nice layer control, it provides a much more professional finish in one's application.

peterb-2795 avatar Jun 18 '15 12:06 peterb-2795

peterb-2795, thanks for the encouragement. Lately I have not had time to improve StyledLayerControl. If you see volunteers interested in advancing the tool, I'd appreciate it. Could you please provide us with a webgis the url that you are developing to have idea of how you can get a real application using the control? If you prefer not to publish here, could send to my email in off?

Thank you.

davicustodio avatar Jun 18 '15 17:06 davicustodio

Hi Davi, replied via your gmail account.

peterb-2795 avatar Jun 21 '15 01:06 peterb-2795

I dont have any URL yet, until now its all local. But if I have something official including the nice layer-controll, I'll post the link here. :)

DavidZebris avatar Jun 24 '15 06:06 DavidZebris

Same problem here. Looked at the DOM structure and I used

$("#leaflet-control-accordion-layers-1").insertBefore("#leaflet-control-accordion-layers-2")

in a case like below:

<div class="leaflet-control-layers-overlays">
<div id=​ "leaflet-control-accordion-layers-2">​…​</div>​,
<div id=​ "leaflet-control-accordion-layers-3">​…​</div>​,
<div id=​ "leaflet-control-accordion-layers-1">​…​</div>​,
<div id=​ "leaflet-control-accordion-layers-4">​…​</div>​,
</div>

Works for me..

Ca-aC avatar Aug 18 '15 10:08 Ca-aC

Ca-Ac, You could create a pull request for this fix?

davicustodio avatar Aug 18 '15 12:08 davicustodio

In my case, I used the L.stamp().

dosstx avatar Dec 07 '15 13:12 dosstx