Leaflet/Leaflet — pull request #3109 by patrickarlt (2014-12-29 21:13:39+00:00)
Title: Improve popups for FeatureGroup

This PR makes the 2 following improvements for `FeatureGroup`

1. `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`.
2. `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.

Both of these changes mean that doing this...

```js
tenThousandFeatures.eachLayer(function(layer){
layer.bindPopup('A unique template for this layer');
});
```

Can now be done like this...

```js
tenThousandFeatures.bindPopup(function(layer){
return 'A unique template for this layer';
});
```

And 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.

In my own tests with 10k features and the following template I got about 200mb of memory reduction.

```js
layer._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.

Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim pellentesque.'
```

![leaflet_debug_page](https://cloud.githubusercontent.com/assets/378557/5573101/3be2f808-8f5c-11e4-837c-d40a6c5e28b1.png)