Ipyleaflet Python export map as PNG or JPG or SVG

I tried to export the data visualization from ipyleaflet as PNG or any other file format, but I couldn't find a method that works. For example, folio has map.save (path). Is there a library or method in ipyleaflet that I missed in my research that helps me achieve my goal?

here is some example code to create a map

from ipyleaflet import *
center = [34.6252978589571, -77.34580993652344]
zoom = 10
m = Map(default_tiles=TileLayer(opacity=1.0), center=center, zoom=zoom)
m

      

I would like to export this map as an image file without taking a screenshot manually.

I found two sources that allow javascript brochure maps to be exported: https://github.com/aratcliffe/Leaflet.print and https://github.com/mapbox/leaflet-image

Unfortunately, I was not able to use them in python.

+3


source to share


1 answer


My colleague and I found a decent job for exporting ipyleaflet images (python). This is how it works. The folate library is required for export. The GeoJson data in this example is already prepared with style properties:

import folium
map = folium.Map([51., 12.], zoom_start=6,control_scale=True)
folium.GeoJson(data).add_to(map)
map.save('map.html')

      



This is what the result looks like: output

The html file can be further processed in python (windows) with subprocess calls to make a PDF or PNG out of it. Hope this helps as the ipyleaflet doc for python is almost non-existent.

+2


source







All Articles