Skip to content

Commit 773d7e7

Browse files
GordoneiConengmo
authored andcommitted
Adding icon_create_function argument to FastMarkerCluster plugin (#1109)
Add `icon_create_function` argument to `FastMarkerCluster`. It's use is the same as in the `MarkerCluster` plugin. It allows customization of the cluster icons.
1 parent 4cd4461 commit 773d7e7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

folium/plugins/fast_marker_cluster.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import (absolute_import, division, print_function)
44

55
from folium.plugins.marker_cluster import MarkerCluster
6-
from folium.utilities import validate_location, if_pandas_df_convert_to_numpy
6+
from folium.utilities import if_pandas_df_convert_to_numpy, validate_location
77

88
from jinja2 import Template
99

@@ -38,6 +38,9 @@ class FastMarkerCluster(MarkerCluster):
3838
Whether the Layer will be included in LayerControls.
3939
show: bool, default True
4040
Whether the layer will be shown on opening (only for overlays).
41+
icon_create_function : string, default None
42+
Override the default behaviour, making possible to customize
43+
markers colors and sizes.
4144
**kwargs
4245
Additional arguments are passed to Leaflet.markercluster options. See
4346
https://github.com/Leaflet/Leaflet.markercluster
@@ -50,6 +53,10 @@ class FastMarkerCluster(MarkerCluster):
5053
5154
var data = {{ this.data|tojson }};
5255
var cluster = L.markerClusterGroup({{ this.options|tojson }});
56+
{%- if this.icon_create_function is not none %}
57+
cluster.options.iconCreateFunction =
58+
{{ this.icon_create_function.strip() }};
59+
{%- endif %}
5360
5461
for (var i = 0; i < data.length; i++) {
5562
var row = data[i];
@@ -63,11 +70,12 @@ class FastMarkerCluster(MarkerCluster):
6370
{% endmacro %}""")
6471

6572
def __init__(self, data, callback=None, options=None,
66-
name=None, overlay=True, control=True, show=True, **kwargs):
73+
name=None, overlay=True, control=True, show=True, icon_create_function=None, **kwargs):
6774
if options is not None:
6875
kwargs.update(options) # options argument is legacy
6976
super(FastMarkerCluster, self).__init__(name=name, overlay=overlay,
7077
control=control, show=show,
78+
icon_create_function=icon_create_function,
7179
**kwargs)
7280
self._name = 'FastMarkerCluster'
7381
data = if_pandas_df_convert_to_numpy(data)

tests/plugins/test_fast_marker_cluster.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def test_fast_marker_cluster():
4444
4545
var data = {{ this.data|tojson }};
4646
var cluster = L.markerClusterGroup({{ this.options|tojson }});
47+
{%- if this.icon_create_function is not none %}
48+
cluster.options.iconCreateFunction =
49+
{{ this.icon_create_function.strip() }};
50+
{%- endif %}
4751
4852
for (var i = 0; i < data.length; i++) {
4953
var row = data[i];

0 commit comments

Comments
 (0)