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

add Draw plugin #720

Merged
merged 2 commits into from
Sep 13, 2017
Merged

add Draw plugin #720

merged 2 commits into from
Sep 13, 2017

Conversation

ocefpaf
Copy link
Member

@ocefpaf ocefpaf commented Sep 12, 2017

@BibMartin I know you are quite busy but I'd appreciate if you take a look at this.
Specially if you think of a way to get the GeoJSON back as a python variable.

Right now if you click on the object you'll get an JS alert with the GeoJSON.

I tried:

var command = "coords='" + coords + "'"
var kernel = IPython.notebook.kernel;
kernel.execute(command);

To return a coords variable, but that seems to no longer work. It seems that they deprecated it and now the only way to do this is via widgets. Not sure...

See http://nbviewer.jupyter.org/github/ocefpaf/folium/blob/Draw/examples/Draw.ipynb

@@ -11,6 +11,7 @@
from __future__ import (absolute_import, division, print_function)

from folium.plugins.boat_marker import BoatMarker
from folium.plugins.draw import Draw

Choose a reason for hiding this comment

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

F401 'folium.plugins.draw.Draw' imported but unused

@BibMartin
Copy link
Contributor

Hi @ocefpaf ,
The PR looks perfect, and the plugin is awesome.
I'll try to have a look about getting the data back in python ; but I'm a bit pessimistic: you have to tell the client browser to send data back to the server and there's no generic way of doing this.
Anyway, it would be notebook-specific.

@ocefpaf
Copy link
Member Author

ocefpaf commented Sep 12, 2017

Anyway, it would be notebook-specific.

Yeah, that is the goal. I want to avoid telling people to just use ipyleaflet for that.

We could at least try to create a hook to save a GeoJSON file though... That would be helpful too.

@ocefpaf
Copy link
Member Author

ocefpaf commented Sep 12, 2017

@BibMartin
Copy link
Contributor

Yes, this has to be updated but may work. A difficulty lies in the fact that our figure is embedded into an Iframe; meaning that you don't have the same javascript environment as the main notebook. We did this to prevent folium and the notebook's javascript to break eachother...

Another workaround could be to go through the API and use something like:

curl -X PUT --header 'Cookie: ...' -d '{"content":"someText", "type":"file", "format":"text"}' http://my-jupyter-server/api/contents/foo.txt

but you need to configure the auth cookie properly

@ocefpaf
Copy link
Member Author

ocefpaf commented Sep 12, 2017

Yes, this has to be updated but may work. A difficulty lies in the fact that our figure is embedded into an Iframe; meaning that you don't have the same javascript environment as the main notebook.

Totally forgot about that!

We did this to prevent folium and the notebook's javascript to break eachother...

We should take a look at how ipyleaflet is doing that. Maybe there is not much interference as we expect.

Another workaround could be to go through the API and use something like:

Seems too hacky, no?

@ocefpaf
Copy link
Member Author

ocefpaf commented Sep 13, 2017

@BibMartin I'll merge this as-is now and we can revisit the Python variable integration later. There are people waiting on this functionality.

@ocefpaf ocefpaf merged commit a3c6994 into python-visualization:master Sep 13, 2017
@ocefpaf ocefpaf deleted the Draw branch September 13, 2017 10:44
@BibMartin
Copy link
Contributor

👍

Shall we open a new issue for this or let #702 hold the question ?

@ocefpaf
Copy link
Member Author

ocefpaf commented Sep 13, 2017

#702 is fine. Thanks!

@lockbucket
Copy link

I don't know if this is possible, but I was thinking of using this on a flask website. The plugin works fantastic, but is it possible to load to a database instead of a jupyter notebook? I think that would be an easier commit than a standard jupyter notebook? I did a google search for pulling this data and found this bookmark which allows a download of the coordinates?

https://bl.ocks.org/danswick/d30c44b081be31aea483

@ocefpaf
Copy link
Member Author

ocefpaf commented Sep 19, 2017

but is it possible to load to a database instead of a jupyter notebook?

Not sure what you mean. I am terrible with databases.

I did a google search for pulling this data and found this bookmark which allows a download of the coordinates?

That looks awesome! I'll take a look if I can add that functionality.

Better than the current copy-n-paste and while ipyleaflet requires global variables this would require a known file name to deliver a similar functionality with the advantaged of having the data outside the notebook JSON.

@lockbucket
Copy link

RE: Database

I guess what I am trying to figure out is illustrated here:
http://flask.pocoo.org/docs/0.12/patterns/jquery/

when a person clicks on the layer jquery will then run a python command to update a database. I will try looking into this.

Thank you for such a wonderful plugin!

@ocefpaf
Copy link
Member Author

ocefpaf commented Sep 20, 2017

PR #727 added the export button option. Not exactly what you want but that is a start in you want to create your own plugin based on that.

sanga pushed a commit to sanga/folium that referenced this pull request Oct 24, 2017
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.

4 participants