Skip to content

Commit 9d851f5

Browse files
authored
Merge pull request #701 from odovad/patch-1
Custom iconCreateFunction in the constructor
2 parents dc77e39 + e96319e commit 9d851f5

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

folium/features.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,15 +756,33 @@ class MarkerCluster(Layer):
756756
Adds the layer as an optional overlay (True) or the base layer (False).
757757
control : bool, default True
758758
Whether the Layer will be included in LayerControls
759+
icon_create_function : string, default None
760+
Override the default behaviour, making possible to customize markers colors and sizes
759761
762+
Example
763+
-------
764+
>>> icon_create_function = '''
765+
... function (cluster) {
766+
... var childCount = cluster.getChildCount();
767+
... var c = ' marker-cluster-small';
768+
... return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>',
769+
className: 'marker-cluster' + c,
770+
iconSize: new L.Point(40, 40) });
771+
... }
772+
... '''
760773
"""
761-
def __init__(self, name=None, overlay=True, control=True):
774+
def __init__(self, name=None, overlay=True, control=True, icon_create_function=None):
762775
super(MarkerCluster, self).__init__(name=name, overlay=overlay,
763776
control=control)
764777
self._name = 'MarkerCluster'
778+
self._icon_create_function = icon_create_function.strip()
765779
self._template = Template(u"""
766780
{% macro script(this, kwargs) %}
767-
var {{this.get_name()}} = L.markerClusterGroup();
781+
var {{this.get_name()}} = L.markerClusterGroup({
782+
{% if this._icon_create_function %}
783+
iconCreateFunction: {{this._icon_create_function}}
784+
{% endif %}
785+
});
768786
{{this._parent.get_name()}}.addLayer({{this.get_name()}});
769787
{% endmacro %}
770788
""")

0 commit comments

Comments
 (0)