2012-07-10 18:54:39 -07:00
|
|
|
Leaflet.markercluster
|
|
|
|
=====================
|
|
|
|
|
2012-07-11 14:13:46 +12:00
|
|
|
Provides Marker Clustering functionality for Leaflet
|
|
|
|
|
2012-07-16 16:33:57 +12:00
|
|
|
## Using the plugin
|
|
|
|
See the included example for usage. Or [check it out online here](http://danzel.github.com/Leaflet.markercluster/example/marker-clustering.html)
|
2012-07-11 14:13:46 +12:00
|
|
|
|
|
|
|
Create a new MarkerClusterGroup, add your markers to it, then add it to the map
|
2012-07-12 00:15:35 +03:00
|
|
|
|
|
|
|
```javascript
|
2012-07-11 14:13:46 +12:00
|
|
|
var markers = new L.MarkerClusterGroup();
|
|
|
|
markers.addLayer(new L.Marker(getRandomLatLng(map)));
|
2012-07-16 16:33:57 +12:00
|
|
|
... Add more layers ...
|
2012-07-11 14:13:46 +12:00
|
|
|
map.addLayer(markers);
|
2012-07-12 00:15:35 +03:00
|
|
|
```
|
2012-07-11 14:13:46 +12:00
|
|
|
|
2012-07-16 16:33:57 +12:00
|
|
|
For the complete example see example/marker-clustering.html
|
2012-07-11 14:13:46 +12:00
|
|
|
|
2012-07-16 16:33:57 +12:00
|
|
|
### Customising the Clustered Marker
|
2012-07-11 14:13:46 +12:00
|
|
|
As an option to MarkerClusterGroup you can provide your own function for creating the Icon for the clustered markers.
|
|
|
|
The default implementation changes color at bounds of 10 and 100, but more advanced uses may require customising this.
|
|
|
|
|
2012-07-12 00:15:35 +03:00
|
|
|
```javascript
|
2012-07-11 14:13:46 +12:00
|
|
|
var markers = new L.MarkerClusterGroup({ options: {
|
|
|
|
iconCreateFunction: function(childCount) {
|
|
|
|
return new L.DivIcon({ html: '<b>' + childCount + '</b>' });
|
|
|
|
}
|
|
|
|
}});
|
2012-07-16 16:33:57 +12:00
|
|
|
```
|
|
|
|
|
|
|
|
### Events
|
|
|
|
|
|
|
|
If you register for click, mouseover, etc events on the MarkerClusterGroup you will get callbacks for both individual markers and clusters.
|
|
|
|
Set your callback up as follows to handle both cases:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
markers.on('click', function (a) {
|
|
|
|
if (a.layer instanceof L.MarkerCluster) {
|
|
|
|
console.log('cluster ' + a.layer.getAllChildMarkers().length);
|
|
|
|
} else {
|
|
|
|
console.log('marker ' + a.layer);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### License
|
|
|
|
|
|
|
|
|
|
|
|
Leaflet.markercluster is free software, and may be redistributed under the MIT-LICENSE.
|