Skip to content

Fix geojson issue with marker cluster #1188

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,22 +413,23 @@ class GeoJson(Layer):
}
});
};
var {{ this.get_name() }} = L.geoJson(null, {
{%- if this.smooth_factor is not none %}
smoothFactor: {{ this.smooth_factor|tojson }},
{%- endif %}
onEachFeature: {{ this.get_name() }}_onEachFeature,
{% if this.style %}
style: {{ this.get_name() }}_styler,
{%- endif %}
}).addTo({{ this._parent.get_name() }});
var options = {
{%- if this.smooth_factor is not none %}
Copy link
Member

Choose a reason for hiding this comment

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

Why do you remove the indentation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

May be automatic linting, I didn't see it. Sorry

smoothFactor: {{ this.smooth_factor|tojson }},
{%- endif %}
onEachFeature: {{ this.get_name() }}_onEachFeature,
{% if this.style %}
style: {{ this.get_name() }}_styler,
{%- endif %} };
{%- if this.embed %}
{{ this.get_name() }}.addData({{ this.data|tojson }});
var {{ this.get_name() }} = L.geoJson(
{{ this.data|tojson }}, options).addTo({{ this._parent.get_name() }});
{%- else %}
$.ajax({url: {{ this.embed_link|tojson }}, dataType: 'json', async: true,
success: function(data) {
{{ this.get_name() }}.addData(data);
}});
var json_url = $.ajax({url: {{ this.embed_link|tojson }}, dataType: 'json', async: true })
$.when(json_url).done(function() {
Copy link
Member

Choose a reason for hiding this comment

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

You can link this to the ajax call directly: $.ajax().done(function() {});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have you tried? Because the problem I had was related with async ajax request and because of that I used a variable to check if the request was finished. I don't have experience with JS. I just searched about it and I found that solution in a blog post.

Copy link
Member

Choose a reason for hiding this comment

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

It seems to work here, and is also listed in the examples in the jQuery documentation, so assume it should be fine.

var geo_json_32b06f4a0e6d419c8f501b4e6c43bc57 = L.geoJson(json_url.responseJSON
Copy link
Member

Choose a reason for hiding this comment

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

The problem with this is that this breaks LayerControl for regular geojson use cases. This variable has to be declared and defined outside of the ajax call.

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, in fact it breaks. I wasn't aware of it. I just tried your PR and works as expected 👍

, options).addTo({{ this._parent.get_name() }});
});
{%- endif %}
{% endmacro %}
""") # noqa
Expand Down