Skip to content

Commit 72e9995

Browse files
authored
Custom iconCreateFunction the constructor
Possible to add a custom iconCreateFunction to the constructor. Please see the example below : icon_create_function = """ function (cluster) { var childCount = cluster.getChildCount(); var c = ' marker-cluster-small'; return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>', className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) }); } """
1 parent dc77e39 commit 72e9995

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

folium/features.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,13 +758,16 @@ class MarkerCluster(Layer):
758758
Whether the Layer will be included in LayerControls
759759
760760
"""
761-
def __init__(self, name=None, overlay=True, control=True):
761+
def __init__(self, name=None, overlay=True, control=True, icon_create_function=""):
762762
super(MarkerCluster, self).__init__(name=name, overlay=overlay,
763763
control=control)
764764
self._name = 'MarkerCluster'
765+
self._icon_create_function = icon_create_function.strip()
765766
self._template = Template(u"""
766767
{% macro script(this, kwargs) %}
767-
var {{this.get_name()}} = L.markerClusterGroup();
768+
var {{this.get_name()}} = L.markerClusterGroup({
769+
{% if this._icon_create_function != "" %}iconCreateFunction: {{this._icon_create_function}}{% else %}{% endif %}
770+
});
768771
{{this._parent.get_name()}}.addLayer({{this.get_name()}});
769772
{% endmacro %}
770773
""")

0 commit comments

Comments
 (0)