{"action":"created","issue":{"url":"https://api.github.com/repos/Leaflet/Leaflet/issues/3109","labels_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/3109/labels{/name}","comments_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/3109/comments","events_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/3109/events","html_url":"https://github.com/Leaflet/Leaflet/pull/3109","id":53072230,"number":3109,"title":"Improve popups for FeatureGroup","user":{"login":"patrickarlt","id":378557,"avatar_url":"https://avatars.githubusercontent.com/u/378557?v=3","gravatar_id":"","url":"https://api.github.com/users/patrickarlt","html_url":"https://github.com/patrickarlt","followers_url":"https://api.github.com/users/patrickarlt/followers","following_url":"https://api.github.com/users/patrickarlt/following{/other_user}","gists_url":"https://api.github.com/users/patrickarlt/gists{/gist_id}","starred_url":"https://api.github.com/users/patrickarlt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patrickarlt/subscriptions","organizations_url":"https://api.github.com/users/patrickarlt/orgs","repos_url":"https://api.github.com/users/patrickarlt/repos","events_url":"https://api.github.com/users/patrickarlt/events{/privacy}","received_events_url":"https://api.github.com/users/patrickarlt/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Leaflet/Leaflet/labels/in+progress","name":"in progress","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2014-12-29T21:13:39Z","updated_at":"2015-01-05T04:25:42Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Leaflet/Leaflet/pulls/3109","html_url":"https://github.com/Leaflet/Leaflet/pull/3109","diff_url":"https://github.com/Leaflet/Leaflet/pull/3109.diff","patch_url":"https://github.com/Leaflet/Leaflet/pull/3109.patch"},"body":"This PR makes the 2 following improvements for `FeatureGroup`\r\n\r\n1. `FeatureGroup` no longer calls `bindPopup` on each of its layers. It now uses the built-in popup methods and the single instance of `Popup` from `Layer`.\r\n2.  `bindPopup` now can also accept a function in addition to HTML or string as the first argument. This function is passed the layer (or source of the popup). This mean that constructing a unique popup for each layer in a large `FeatureGroup` no longer requires iterating over each feature OR storing each features content in memory.\r\n\r\nBoth of these changes mean that doing this...\r\n\r\n```js\r\ntenThousandFeatures.eachLayer(function(layer){\r\n  layer.bindPopup('A unique template for this layer');\r\n});\r\n```\r\n\r\nCan now be done like this...\r\n\r\n```js\r\ntenThousandFeatures.bindPopup(function(layer){\r\n  return 'A unique template for this layer';\r\n});\r\n```\r\n\r\nAnd everything will be handled on the fly. This has the potential to lead to huge memory reductions depending on how big the popup content is and how many feature are in the collection.\r\n\r\nIn my own tests with 10k features and the following template I got about 200mb of memory reduction.\r\n\r\n```js\r\nlayer._leaflet_id + 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p><p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim pellentesque.'\r\n```\r\n\r\n![leaflet_debug_page](https://cloud.githubusercontent.com/assets/378557/5573101/3be2f808-8f5c-11e4-837c-d40a6c5e28b1.png)"},"comment":{"url":"https://api.github.com/repos/Leaflet/Leaflet/issues/comments/68667168","html_url":"https://github.com/Leaflet/Leaflet/pull/3109#issuecomment-68667168","issue_url":"https://api.github.com/repos/Leaflet/Leaflet/issues/3109","id":68667168,"user":{"login":"patrickarlt","id":378557,"avatar_url":"https://avatars.githubusercontent.com/u/378557?v=3","gravatar_id":"","url":"https://api.github.com/users/patrickarlt","html_url":"https://github.com/patrickarlt","followers_url":"https://api.github.com/users/patrickarlt/followers","following_url":"https://api.github.com/users/patrickarlt/following{/other_user}","gists_url":"https://api.github.com/users/patrickarlt/gists{/gist_id}","starred_url":"https://api.github.com/users/patrickarlt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patrickarlt/subscriptions","organizations_url":"https://api.github.com/users/patrickarlt/orgs","repos_url":"https://api.github.com/users/patrickarlt/repos","events_url":"https://api.github.com/users/patrickarlt/events{/privacy}","received_events_url":"https://api.github.com/users/patrickarlt/received_events","type":"User","site_admin":false},"created_at":"2015-01-05T04:25:42Z","updated_at":"2015-01-05T04:25:42Z","body":"@mourner don't merge this yet. I want to be able to make it so you can return DOM elements from the function as well a template string.\r\n\r\nI'll also squash all the commits in this down to a single one."}}