-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix geojson issue with marker cluster #1188
Conversation
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.
Indeed, linking geojson to marker cluster is broken at the moment. To be honest I didn't know we offered that functionality. Thanks for the well-written problem description.
I tried your fix, but it seems it breaks LayerControl
when using GeoJson
normally and with non-embedded data. While looking into this I came up with an alternative approach. I'll make a PR, maybe you can check it out, let me know what you think? #1190 Then we can discuss how to move on.
}}); | ||
var json_url = $.ajax({url: {{ this.embed_link|tojson }}, dataType: 'json', async: true }) | ||
$.when(json_url).done(function() { | ||
var geo_json_32b06f4a0e6d419c8f501b4e6c43bc57 = L.geoJson(json_url.responseJSON |
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.
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.
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, in fact it breaks. I wasn't aware of it. I just tried your PR and works as expected 👍
{%- endif %} | ||
}).addTo({{ this._parent.get_name() }}); | ||
var options = { | ||
{%- if this.smooth_factor is not none %} |
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.
Why do you remove the indentation here?
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.
May be automatic linting, I didn't see it. Sorry
{{ this.get_name() }}.addData(data); | ||
}}); | ||
var json_url = $.ajax({url: {{ this.embed_link|tojson }}, dataType: 'json', async: true }) | ||
$.when(json_url).done(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.
You can link this to the ajax call directly: $.ajax().done(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.
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.
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.
It seems to work here, and is also listed in the examples in the jQuery documentation, so assume it should be fine.
This problem has been fixed in #1190. |
This PR fixed #1129
My understating of the cause of this issue is because we are currently adding a geojson with a null value to cluster marker layer and only later adding the geojson data.
folium/folium/features.py
Line 416 in 2122625
And because of this, the following code produces a empty map:
The
cluster.html
html code:However, with the same python code, if we change the html code and add the geojson data at the same time we create the geojson layer, as bellow, the markers are displayed on map.
This PR fixed this issue and at the same time makes it possible have data not embed on html file when an url is passed as data source.