jupyter-widgets / ipyleaflet

A Jupyter - Leaflet.js bridge
https://ipyleaflet.readthedocs.io
MIT License
1.49k stars 363 forks source link

Method like _repr_html_() in Folium #1045

Open Dubaja opened 2 years ago

Dubaja commented 2 years ago

Is there a method like _repr_html_() in folium, which returns the map in HTML form? If not can it be implemented?

martinRenou commented 2 years ago

You can use the .save('output.html') method on the map

Dubaja commented 2 years ago

You can use the .save('output.html') method on the map

I know, but i dont need to save it, i need to store it in a variable.

giswqs commented 2 years ago

Leafmap has a to_html() for that.

https://leafmap.org/leafmap/#leafmap.leafmap.Map.to_html

import leafmap
m = leafmap.Map()
html = m.to_html()
martinRenou commented 2 years ago

@giswqs it'd be great if you could contribute back if you managed to add it!

giswqs commented 2 years ago

@martinRenou Ha, the leafmap.Map.to_html() function actually uses ipyleaflet.save(), read the html into a string, and delete the HTML file. It is probably not that useful to add to ipylealfet.

giswqs commented 2 years ago

One potential improvement is to allow outfile=None that can return the HTML string, i.e., generate the HTML file, reads it into a string, then delete the HTML file. I can submit a PR you think it is a good idea.

https://github.com/jupyter-widgets/ipyleaflet/blob/fe874793d6f0b5c20bf9c04d6a33eba41a6e0b4e/ipyleaflet/leaflet.py#L2495-L2506