我正在尝试将包含标记的地图和热图保存到图像中。这是显示地图的代码。
from ipywidgets import Layout
import geopandas
defaultLayout=Layout(width='3000px', height='3000px') # A very large image.
lat_lgn = [39.74248, 254.993622]
m_f = Map(center=lat_lgn, zoom=12, layout=defaultLayout)
marker_m = Marker(location=lat_lgn, draggable=False)
m_f.add_layer(marker_m)
m_f
在上面添加一些标记
arr_test1 = [39.74258, 254.993682]
arr_test2 = [39.76288, 254.988932]
arr_test3 = [39.79998, 254.991982]
all_loc = [arr_test1, arr_test2, arr_test3]
for cur_loc in all_loc:
point = CircleMarker(
radius=10,
location=cur_loc,
color='red',
fill_color="black",
)
m_f.add_layer(point)
time.sleep(0.001)
将地图保存为 html 文件。工作正常。
m_f.save('f_map.html', title='My Map')
当我尝试从 html 获取图像或 pdf 时,就会出现问题。
import imgkit
import pdfkit
config = pdfkit.configuration(wkhtmltopdf='/usr/local/bin/wkhtmltopdf')
pdfkit.from_file('f_map.html', 'outpdf.pdf', configuration=config)
pdfkit.from_file('f_map.html', 'outjpg.jpg', configuration=config)
pdfkit.from_file('f_map.html', 'outpng.png', configuration=config)
pdf文件为空白
而且 MacBook 无法打开 jpeg 和 png 文件。
为了检查我的依赖关系,我试过这个:
import pdfkit
pdfkit.from_url('http://stackoverflow.com', 'out.pdf', configuration=config)
效果很好。但是,一旦我更改out.pdf
为out.png
,我无法打开获得的文件。
有谁知道,我该如何解决这个问题?
我试图获得巨大的形象。但它也不适用于 300 像素 X 300 像素的图像。
欢迎任何提示。