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
Adding popup_attribute to the GeoJson feature #376
Conversation
The popup_attribute takes an attribute name and uses the attribute as the popup value for each feature in the layer. Signed-off-by: Henry Walshaw <henry.walshaw@gmail.com>
Update to the GeoJson and GeoPandas examples to include the popup attribute Signed-off-by: Henry Walshaw <henry.walshaw@gmail.com>
Awesome! Thanks @om-henners . First reactions :
|
@BibMartin Happy to put in the full popup support, and you're right - it would be better to have the attribute in a single template. Cheers for the feedback! |
Update the geojson popup attribute to being a popup function which will build a _popupContent attribute on features if required. Signed-off-by: Henry Walshaw <henry.walshaw@gmail.com>
Test on the attribute being correct and the geojson producing correctly, and test on the function creating the correct _popupContent attribue on the feature. Also update test_geo_json_str so that it includes the empty options parameters. Signed-off-by: Henry Walshaw <henry.walshaw@gmail.com>
Allow passing the popup_function through the choropleth shortcut on the map object (assuming the dataset is GeoJson) Signed-off-by: Henry Walshaw <henry.walshaw@gmail.com>
Update the notebooks to include a popup function for GeoJson and GeoDataFrames Signed-off-by: Henry Walshaw <henry.walshaw@gmail.com>
Signed-off-by: Henry Walshaw <henry.walshaw@gmail.com>
@BibMartin I've made a coupe of updates to the pull request:
I also took a look at adding the Popup object, but I'll have to have a bit more of a play with it. First though I'd like to update the TopoJson methods so it's consistent with the GeoJson and also has a |
folium/features.py
Outdated
self.popup_attribute = popup_function | ||
elif isinstance(popup_function, binary_type): | ||
self.popup_attribute = text_type(popup_function, 'utf8') | ||
|
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.
This is really great ! Thanks.
I would prefer to move this paragraph (346-358) into style_data
and simply write self.popup_function = popup_function
here. That way, the following code will also work:
g = GeoJson(data)
g.popup_function = some_function
Wow! Thanks @om-henners!! @BibMartin Can I assign you to continue reviewing and merge? |
@ocefpaf no worries - happy to help. @BibMartin Happy to move the function to the style method. If it's ok I'll delay to tomorrow and do it on the weekend. |
sure you can (and you do) ; I'm looking forward to review this.
No worry, no hurry. This WE is soon enough 😉 |
The actual population of the `_popupContent` attribute based on popup_function is now in the style attribute. This means that the `popup_function` and `popup_attribute` can be populated after the Geojson creation. The `popup_function` is actually a feature property now to ensure that the `popup_attribute` is set correctly when the function is set after the fact. Signed-off-by: Henry Walshaw <henry.walshaw@gmail.com>
Update the geojson examples to show the popup attribute and function can be set after the fact on geojson features. Signed-off-by: Henry Walshaw <henry.walshaw@gmail.com>
I've updated so that the |
Fix the indent to fix the comment that fails the travis build Signed-off-by: Henry Walshaw <henry.walshaw@gmail.com>
Hi @BibMartin , any more changes you'd like on this request? |
feature["properties"]["_popupContent"] = self.popup_function(feature) # noqa | ||
except TypeError: | ||
pass | ||
|
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 need a try
?
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.
Since the checks on the function are outside the render operation, I was being a bit slack and letting the function fail when it wasn't a function. I'll move checks inside the loop.
Hi @om-henners , sorry for the delay ; I've been quite busy this fortnight. I've put a few question in the code but nothing's blocking. I wait for your reactions before merging. Thnaks again! |
Hi @BibMartin , likewise sorry for the delay - been super busy here too :) I've added replies above. Happy to make the updates to the code this weekend. |
Looking forward to see this functionality merged and pushed into conda package :) I believe there is no existing functionality that would let supply a geoJSON property as a pop-up value, yet this is kind of basic thing for most web mapping operations. @om-henners, brilliant. |
@AlexArcPy thanks for the ping. @om-henners not sure if I will have time, but if I do are you OK if I pick your commits and finish this PR? |
@ocefpaf, just realized you are the "ocean guy". Your blog posts are such huge time savers for me, every time I find your posts, I was so glad you spend hours writing them, you are legend. |
😳 But here on |
Good day! I would just like to know when this new feature (popup for geojson) would be implemented. So I guess I'll just leave this here to be notified whenever it is ready. Thank you for your work btw. Cheers! |
475a974
to
2b3b5d5
Compare
Good luck @ocefpaf ! Don't hesitate to ask for help in this refactoring. It might simply be an open PR with the planned changes as comments/pseudo-code... |
a352df2
to
2a2dc9a
Compare
What is the status of this merge? |
I would very much like to know as well. Can we please approve this, fixing the conflicts that are now there of course. |
@CSFlorin |
side note: couldn't get @halfdanrump 's method to work (map just wouldn't show at all, even when the gdf has just one row), so here's an alternative that just puts a new centered point in each polygon:
Sorry, I spoke too soon. I think it wasn't working for me since props was a list, so I joined each element and it worked all of a sudden. Thank you! |
Does anyone know how to group the layers together so that the popup layer is always above the polygon layer and so that they appear as one in the layercontrol? Much appreciated and sorry for the bugging on this thread |
This should be solved after GeoJsonCss has been accepted in PR #748 as it allows popups per feature in the GeoJson as well as styling. |
I'm a bit unclear as to what the status of this is? Can someone elaborate a bit on what the holdups are (aside from the obvious conflicts)? I'm happy to put some time into this and get this feature added to Folium. Some guidance on whether or not this pull is salvageable and/or I should start from scratch would be appreciated. Thanks! |
This works, have you tried it? We’re just waiting to add a new version to pypi.
…Sent from my iPhone
On 21 Jan 2018, at 05:22, MattGraz <notifications@github.com<mailto:notifications@github.com>> wrote:
I'm a bit unclear as to what the status of this is? Can someone elaborate a bit on what the holdups are (aside from the obvious conflicts)?
I'm happy to put some time into this and get this feature added to Folium. Some guidance on whether or not this pull is salvageable and/or I should start from scratch would be appreciated.
Thanks!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#376 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AWaWQX2pQ5burCyoWKGzWtq2PtDZ7sXNks5tMsl8gaJpZM4HlSKV>.
|
@ghandic: Thanks for the follow up. I did get it working! I was just unsure what the status was as far as merging. Thank you for clarifying! |
Any updates? |
@Conengmo could you resolve the conflicts in merging the pull request? |
We are going in a different direction with GeoJsonCss. Closing this to avoid confusion. |
---------- | ||
func : srting, function or None | ||
The popup value for the feature | ||
* If string, then an attribute to use as a popup value for the feature |
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 (82 > 79 characters)
I've made a change to the GeoJson feature to add a
popup_attribute
parameter. Including this changes the template so that attribute of the feautre is used as the popup for that feature. Based on the map I did for the #gistribe 15 minute map competition.