-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Custom iconCreateFunction in the constructor #701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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) }); } """
folium/features.py
Outdated
self._template = Template(u""" | ||
{% macro script(this, kwargs) %} | ||
var {{this.get_name()}} = L.markerClusterGroup(); | ||
var {{this.get_name()}} = L.markerClusterGroup({ | ||
{% if this._icon_create_function != "" %}iconCreateFunction: {{this._icon_create_function}}{% else %}{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E501 line too long (128 > 120 characters)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add:
- a test test for this functionality;
- docstring exampling this option;
- use example in the docstring;
- a notebook example, it can be the same as the docstring (optional);
- an entry in the changelog.
See https://github.com/Leaflet/Leaflet.markercluster/blob/f175a7cc31322a194ecafc28bbf4fcfe953c476e/README.md for creating docstring.
folium/features.py
Outdated
@@ -758,13 +758,18 @@ class MarkerCluster(Layer): | |||
Whether the Layer will be included in LayerControls | |||
|
|||
""" | |||
def __init__(self, name=None, overlay=True, control=True): | |||
def __init__(self, name=None, overlay=True, control=True, icon_create_function=""): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change icon_create_function=""
to icon_create_function=''
. Sounds silly, but with all the jinja templates represent JSONs it is nice to have single quotes for python code and double for JSON. (Makes it easier to read.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I try to do all you've said.
folium/features.py
Outdated
self._template = Template(u""" | ||
{% macro script(this, kwargs) %} | ||
var {{this.get_name()}} = L.markerClusterGroup(); | ||
var {{this.get_name()}} = L.markerClusterGroup({ | ||
{% if this._icon_create_function != "" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that {% if this._icon_create_function %}
would work.
Also, maybe a default to None
instead of ''
would be more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right. It works.
@odovad maybe we could take this opportunity and upgrade to 1.1.0 |
folium/features.py
Outdated
@@ -756,15 +756,21 @@ class MarkerCluster(Layer): | |||
Adds the layer as an optional overlay (True) or the base layer (False). | |||
control : bool, default True | |||
Whether the Layer will be included in LayerControls | |||
|
|||
icon_create_function : string, default None | |||
Override the default behaviour, making possible to customize markers colors and sizes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
folium/features.py
Outdated
|
||
icon_create_function : string, default None | ||
Override the default behaviour, making possible to customize markers colors and sizes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W293 blank line contains whitespace
folium/features.py
Outdated
... function (cluster) { | ||
... var childCount = cluster.getChildCount(); | ||
... var c = ' marker-cluster-small'; | ||
... return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
folium/features.py
Outdated
... var childCount = cluster.getChildCount(); | ||
... var c = ' marker-cluster-small'; | ||
... return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>', | ||
className: 'marker-cluster' + c, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W291 trailing whitespace
folium/features.py
Outdated
|
||
icon_create_function : string, default None | ||
Override the default behaviour, making possible to customize markers colors and sizes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W293 blank line contains whitespace
@odovad are you done? LGTM! Can you make and entry in the |
@Filipe I did not have time for the file with the test and the notebook.
I try to do it as fast as I can
Envoyé de mon iPhone
… Le 31 août 2017 à 20:25, Filipe ***@***.***> a écrit :
@odovad are you done? LGTM!
Can you make and entry in the CHANGES.txt file so we can merge this 😉
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
There is no rush 😉
The notebook is optional and can he added in another PR. I'll add the changelog entry if you don't mind and get this merged. The reason is b/c I am re-factoring a bunch of stuff and I don't want you to end up having to rebase this. Thanks a lot for the contribution! |
That will be nice to have too 😉 |
Custom iconCreateFunction in the constructor
Possible to add a custom iconCreateFunction to the constructor.
Please see the example below :