{"action":"created","issue":{"url":"https://api.github.com/repos/Leaflet/Leaflet/issues/2086","repository_url":"https://api.github.com/repos/Leaflet/Leaflet","labels_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/2086/labels{/name}","comments_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/2086/comments","events_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/2086/events","html_url":"https://github.com/Leaflet/Leaflet/issues/2086","id":20836823,"number":2086,"title":"Layer order in `L.Control.Layers` is not preserved with GeoJson/FeatureGroup","user":{"login":"jieter","id":1470389,"avatar_url":"https://avatars.githubusercontent.com/u/1470389?v=3","gravatar_id":"","url":"https://api.github.com/users/jieter","html_url":"https://github.com/jieter","followers_url":"https://api.github.com/users/jieter/followers","following_url":"https://api.github.com/users/jieter/following{/other_user}","gists_url":"https://api.github.com/users/jieter/gists{/gist_id}","starred_url":"https://api.github.com/users/jieter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jieter/subscriptions","organizations_url":"https://api.github.com/users/jieter/orgs","repos_url":"https://api.github.com/users/jieter/repos","events_url":"https://api.github.com/users/jieter/events{/privacy}","received_events_url":"https://api.github.com/users/jieter/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Leaflet/Leaflet/labels/bug","name":"bug","color":"EBC3C3"}],"state":"open","locked":false,"assignee":{"login":"mourner","id":25395,"avatar_url":"https://avatars.githubusercontent.com/u/25395?v=3","gravatar_id":"","url":"https://api.github.com/users/mourner","html_url":"https://github.com/mourner","followers_url":"https://api.github.com/users/mourner/followers","following_url":"https://api.github.com/users/mourner/following{/other_user}","gists_url":"https://api.github.com/users/mourner/gists{/gist_id}","starred_url":"https://api.github.com/users/mourner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mourner/subscriptions","organizations_url":"https://api.github.com/users/mourner/orgs","repos_url":"https://api.github.com/users/mourner/repos","events_url":"https://api.github.com/users/mourner/events{/privacy}","received_events_url":"https://api.github.com/users/mourner/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/Leaflet/Leaflet/milestones/27","html_url":"https://github.com/Leaflet/Leaflet/milestones/1.0-rc1","labels_url":"https://api.github.com/repos/Leaflet/Leaflet/milestones/27/labels","id":1342302,"number":27,"title":"1.0-rc1","description":"","creator":{"login":"mourner","id":25395,"avatar_url":"https://avatars.githubusercontent.com/u/25395?v=3","gravatar_id":"","url":"https://api.github.com/users/mourner","html_url":"https://github.com/mourner","followers_url":"https://api.github.com/users/mourner/followers","following_url":"https://api.github.com/users/mourner/following{/other_user}","gists_url":"https://api.github.com/users/mourner/gists{/gist_id}","starred_url":"https://api.github.com/users/mourner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mourner/subscriptions","organizations_url":"https://api.github.com/users/mourner/orgs","repos_url":"https://api.github.com/users/mourner/repos","events_url":"https://api.github.com/users/mourner/events{/privacy}","received_events_url":"https://api.github.com/users/mourner/received_events","type":"User","site_admin":false},"open_issues":18,"closed_issues":32,"state":"open","created_at":"2015-10-07T10:17:53Z","updated_at":"2016-02-12T14:39:01Z","due_on":null,"closed_at":null},"comments":23,"created_at":"2013-10-10T21:28:56Z","updated_at":"2016-02-12T14:40:05Z","closed_at":null,"body":"When I do\r\n\r\n```JavaScript\r\nL.control.layers({\r\n    'OSM': L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map)\r\n}, {\r\n    'Circle': L.circle([53, 4], 111111),\r\n    'Polygon': L.polygon([[48, -3], [50, -4], [52, 4]]),\r\n    'GeoJSON': L.geoJson(geojson)\r\n}, {\r\n    collapsed: false\r\n}).addTo(map);\r\n```\r\n\r\nI expect the order of the overlays to be as I supplied them, however, GeoJSON and FeatureGroup layers are moved up top. This is because the FeatureGroup gets its `_leaflet_id` while it's created, while the other layers get it while they're added to Control.Layers.\r\nFeatureGroup is stamped because it's passed as the context to `layer.on` in FeatureGroup.js:19.\r\n\r\nNot sure how to fix this:\r\n - stamping each layer while initializing? Seems dirty. \r\n - Different sorting mechanism in Control.Layers?\r\n\r\nhttp://jsfiddle.net/km5H9/1/\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Leaflet/Leaflet/issues/comments/183355475","html_url":"https://github.com/Leaflet/Leaflet/issues/2086#issuecomment-183355475","issue_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/2086","id":183355475,"user":{"login":"mourner","id":25395,"avatar_url":"https://avatars.githubusercontent.com/u/25395?v=3","gravatar_id":"","url":"https://api.github.com/users/mourner","html_url":"https://github.com/mourner","followers_url":"https://api.github.com/users/mourner/followers","following_url":"https://api.github.com/users/mourner/following{/other_user}","gists_url":"https://api.github.com/users/mourner/gists{/gist_id}","starred_url":"https://api.github.com/users/mourner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mourner/subscriptions","organizations_url":"https://api.github.com/users/mourner/orgs","repos_url":"https://api.github.com/users/mourner/repos","events_url":"https://api.github.com/users/mourner/events{/privacy}","received_events_url":"https://api.github.com/users/mourner/received_events","type":"User","site_admin":false},"created_at":"2016-02-12T14:40:05Z","updated_at":"2016-02-12T14:40:05Z","body":"@patrickarlt I think that's a great approach. I would be up for a PR on this."}}