Skip to content
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

Search Refactor #995

Merged
merged 253 commits into from
Dec 23, 2018
Merged

Search Refactor #995

merged 253 commits into from
Dec 23, 2018

Conversation

jtbaker
Copy link
Contributor

@jtbaker jtbaker commented Oct 17, 2018

I reworked the Search plugin to reference a folium.features.GeoJson object via the .add_child()/.add_to() methods to combine these functionalities. Made search_zoom optional, and added **kwargs to allow a variety of SVG style options on a match, like highlight_function in GeoJson.

I think that this would have been cleaner to have an object keyword argument that we could pass a folium.features.GeoJson object like this:

from folium.plugins import Search
geo = folium.GeoJson(gdf).add_to(m)

Search(object=geo, search_label='name').add_to(m)

But when I set up the logic that way, it inserted the Search object further up the <script> tag than the GeoJson - so when Search invoked the " {{ geo.get_name() }} " method in the template when adding to the map, it didn't yet have a defined variable name to reference. Not sure if there is a way to get around this.

With the .add_child() method, we're constrained to getting to the Leaflet L.map() object through the _parent properties. We have to do this traversal twice with Search, since Search is a child of folium.GeoJson, and folium.GeoJson is a child of folium.Map(). I don't know if there are any edge cases such as FeatureGroups and SubGroups that further subclass GeoJson from Map, and if they should try to account for those.

Here's a sandbox I was working with for a Dataset I was already working on a tooltip issue for. I'll get a better example set up and committed after I've gotten some feedback on the design approach.

https://nbviewer.jupyter.org/gist/jtbaker/b347705fce2741eb5405874004a25079

Seems like maybe the f-string usage in the geojson fields assertion check is causing the build failure. Testing normal string concatenation.
Reverted accidental vega_parse change.
Fixed docstring indentation.
Updating Tooltip docstring broke 120 char line limit.
Removed trailing white space.
Updating my fork to current Master.
…iLang.xml, ide.general.xml, Default.xml, project.default.xml, diff.xml, git.xml, other.xml, jdk.table.xml, Default.xml, code.style.schemes, find.xml, ui.lnf.xml, laf.xml, filetypes.xml, projectView.xml, vcs.xml, editor.codeinsight.xml, notifications.xml, keymap.xml, editor.xml, github_settings.xml, debugger.xml
…, IntelliLang.xml, ide.general.xml, Default.xml, project.default.xml, diff.xml, git.xml, other.xml, jdk.table.xml, Default.xml, code.style.schemes, find.xml, ui.lnf.xml, laf.xml, filetypes.xml, projectView.xml, vcs.xml, editor.codeinsight.xml, notifications.xml, keymap.xml, editor.xml, github_settings.xml, debugger.xml"

This reverts commit 76c9622.
…, filetypes.xml, git.xml, keymap.xml, github_settings.xml, Default.xml, debugger.xml
Updated code for line length limitation, verbiage, and indentations.
@Conengmo
Copy link
Member

Conengmo commented Dec 12, 2018

Hmm I seem to be missing some comments? Also the other notebook is back. And I thought you deleted the get_parent_map function? It's still morning though so maybe I'm not looking right :)

The plugin-Search notebook is still not working:
https://nbviewer.jupyter.org/github/jtbaker/folium/blob/SearchRefactor/examples/plugin-Search.ipynb

Given the error message it seems there's an empty cell that's messing it up.

@jtbaker
Copy link
Contributor Author

jtbaker commented Dec 20, 2018

@Conengmo sorry for the late response on this. My git-fu is still lacking. I was trying to merge in the most recent version of the upstream master changes and it looks like in resolving the merge conflicts inadvertently reintroduced some of the things I thought I had taken out. Working on getting this resolved now.

The notebook issue does seem to be for an empty cell. I'll see if I can get these issues updated and fixed.

Thanks for your patience!

@jtbaker
Copy link
Contributor Author

jtbaker commented Dec 20, 2018

@Conengmo do you think adding a title kwarg to Marker, CircleMarker, etc. to expose this functionality to MarkerCluster and FeatureGroup layers would be within the scope of this PR? Or should it be separate?

@jtbaker
Copy link
Contributor Author

jtbaker commented Dec 20, 2018

Ok, I think I've got the issues addressed. Working notebook demo at nbviewer. Adds some functionality for usage on GeoJsonTooltip as well.

@davidolmo
Copy link

davidolmo commented Dec 23, 2018

wow @jtbaker , this is huge in terms of impact. Thank you so much

@Conengmo
Copy link
Member

do you think adding a title kwarg to Marker, CircleMarker, etc. to expose this functionality to MarkerCluster and FeatureGroup layers would be within the scope of this PR? Or should it be separate?

Let's do it separately. This PR is finished I think!

@Conengmo Conengmo merged commit 53919ba into python-visualization:master Dec 23, 2018
@Conengmo Conengmo removed the in discussion This PR or issue is being discussed label Dec 23, 2018
@Conengmo
Copy link
Member

Good work @jtbaker!

@jtbaker
Copy link
Contributor Author

jtbaker commented Dec 24, 2018

Thank you so much

@davidolmo no problem, it's fun to work on these and try to develop something that will be really straightforward and easy for a lot of people to develop these maps! to me, the real amazing work is the people writing the leaflet plugins and working in the DOM. we just have to figure out how to translate our python logic and data structures over to use them in the leaflet/plugin code. I'm glad you dig it! 😀

@jtbaker
Copy link
Contributor Author

jtbaker commented Dec 24, 2018

Good work @jtbaker!

Thanks for your patience, and for working with me on this one @Conengmo! I'm excited to see this one get merged.

@rbgt
Copy link

rbgt commented Feb 25, 2019

Hello, thank you for your work on the search plugin
Do you have a pip link to get the last version of the Search plugin ?
At the moment, the parameters in the folium doc for Search plugin isn't the same as those you use in the notebook.
Thank you very much

@Conengmo
Copy link
Member

@rickantonais v0.8.0 was just released, including this PR:
https://pypi.org/project/folium/

@rbgt
Copy link

rbgt commented Feb 25, 2019

Thank you very much! It seems the conda install automatically install the 0.7.0 version though

@jtbaker
Copy link
Contributor Author

jtbaker commented Feb 25, 2019

Thank you very much! It seems the conda install automatically install the 0.7.0 version though

There is usually a little lag on when it hits the distribution channels I believe. If you have git on your machine you can install directly from the source here like this (make sure your conda environment is activated):

pip install git+https://github.com/python-visualization/folium.git

@rbgt
Copy link

rbgt commented Feb 25, 2019

It works perfectly now thank you very much !

@jtbaker jtbaker deleted the SearchRefactor branch February 25, 2019 18:33
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.

6 participants