Skip to content

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

Merged
merged 6 commits into from
Sep 1, 2017

Conversation

odovad
Copy link
Contributor

@odovad odovad commented Aug 31, 2017

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) });
}
"""

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) });
}
"""
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 %}

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)

Copy link
Member

@ocefpaf ocefpaf left a 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.

@@ -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=""):
Copy link
Member

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.)

Copy link
Contributor Author

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.

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 != "" %}
Copy link
Member

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.

Copy link
Contributor Author

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 odovad changed the title Custom iconCreateFunction the constructor Custom iconCreateFunction in the constructor Aug 31, 2017
@ocefpaf
Copy link
Member

ocefpaf commented Aug 31, 2017

@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W291 trailing whitespace


icon_create_function : string, default None
Override the default behaviour, making possible to customize markers colors and sizes

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

... function (cluster) {
... var childCount = cluster.getChildCount();
... var c = ' marker-cluster-small';
... return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W291 trailing whitespace

... var childCount = cluster.getChildCount();
... var c = ' marker-cluster-small';
... return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>',
className: 'marker-cluster' + c,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W291 trailing whitespace


icon_create_function : string, default None
Override the default behaviour, making possible to customize markers colors and sizes

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

@ocefpaf
Copy link
Member

ocefpaf commented Aug 31, 2017

@odovad are you done? LGTM!

Can you make and entry in the CHANGES.txt file so we can merge this 😉

@odovad
Copy link
Contributor Author

odovad commented Aug 31, 2017 via email

@ocefpaf
Copy link
Member

ocefpaf commented Sep 1, 2017

I try to do it as fast as I can

There is no rush 😉

@Filipe I did not have time for the file with the test and the notebook.

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!

@ocefpaf ocefpaf merged commit 9d851f5 into python-visualization:master Sep 1, 2017
@odovad
Copy link
Contributor Author

odovad commented Sep 1, 2017 via email

@ocefpaf
Copy link
Member

ocefpaf commented Sep 1, 2017

at least the file for the test.

That will be nice to have too 😉

sanga pushed a commit to sanga/folium that referenced this pull request Oct 24, 2017
Custom iconCreateFunction in the constructor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants