-
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
export / save Folium map as static image (PNG) #1850
Comments
Hi Florin, You're right that converting a map to a fixed image is not supported by default. That's because Folium only creates Javascript code. Then your browser runs that Javascript to display a map. Python is not involved in that last part, only your browser. Perhaps a Leaflet plugin to export a map to an image would be useful: https://leafletjs.com/plugins.html#printexport. We don't have any of these in Folium at the moment. I don't think Selenium is a 'hack', but you're right that setting it up is not as straight forward as just doing pip install. Perhaps something like SeleniumBase, which automates driver installation, could be useful. I don't think we should have Selenium as a required dependency for Folium. I do think our documentation could contain a better example on how to use Selenium to create a screenshot. Help is welcome for that. If somebody has ideas on how Folium could provide better support for creating screenshots, I'd love to hear it. For now, I'll close this issue, since you indicate you don't have time to help with this, and I don't plan on working on this topic. Sorry that you seem disappointed, I hope you can appreciate we don't really have a core team working on this, it's all volunteering with very limited people. |
What might be helpful is a way for folium to export the map object as a self-contained HTML/JS output, which the user can further modify based on their knowledge of Leaflet and JS etc. This functionality would also be useful for the purpose of using folium in offline mode. |
@prusswan thanks for your suggestion. How would what you describe be different from using If you want offline mode, you also need to host external resources and especially tiles locally, the latter of which is more involved. |
@Conengmo probably by extending
PMTiles will be pretty useful for this, but if you have access to local tiles, it is fairly easy to set up everything to work under |
The Plotly graphing library uses kaleido to easily save .png versions of interactive charts. I believe these charts are originally rendered within HTML and javascript by default, so perhaps Folium could use a similar setup? That being said, I find that using Selenium to save static versions of Folium charts works quite well once you get everything set up (which seems to be easier now than in the past due to updates to the Selenium library). |
Code:
This works fine, but there seems to be no way to generate the map, optionally, as a fixed-size, non-zoomable bitmap in a decent format like PNG.
A side-effect of this is - the map does not show in a PDF export of the Jupyter notebook where the map is generated.
It would be nice if
folium.Map()
had a way to generate fixed bitmap output, e.g. like Matplotlib.pyplot.I've read the documentation, searched the web, there really seems to be no good solution other than a Selenium hack which requires too many moving parts and extra libraries. This should be instead a standard Folium feature.
To be clear, I am running all this code in a Jupyter notebook.
I don't think I have the time to implement a PR myself.
The text was updated successfully, but these errors were encountered: