1

I am trying to save a map containing markers and also heatmap.
Here is the code to display the map.

import folium
m_f = folium.Map(location= [39.76258, 254.994682],
                 zoom_start=8)

m_f.save('f_map.html')
m_f

I then use phantomjs to save the image.

import selenium.webdriver
import time

from selenium import webdriver

driver = webdriver.PhantomJS(executable_path='/Users/path/Downloads/PhantomJS/bin/phantomjs')

driver.set_window_size(4000, 3000)  # choose a resolution
driver.get('f_map.html')
# You may need to add time.sleep(seconds) here
time.sleep(1)
driver.save_screenshot('f_map.png')

There is no problem until here.
However, when I add some markers on the map, I get the correct html file, which I can open also in the browser, but its screenshot is a blank file (content).

Here is the code of the new map

import folium
m_f = folium.Map(location= [39.74258, 254.993682],
                 zoom_start=12)

arr_test1 = [39.74258, 254.993682]
arr_test2 = [39.75258, 254.994682]
arr_test3 = [39.76258, 254.994682]

all_loc = [arr_test1, arr_test2, arr_test3]

for cur_loc in all_loc:
    point = folium.Circle(
        radius=200,
        location=cur_loc,
        popup='The Waterfront',
        color='red',
        fill=False,
    )
    point.add_to(m_f)
    
    time.sleep(0.001)
    
m_f
m_f.save('f_map_marker.html')

and its phantonjs code lines

import selenium.webdriver
import time

from selenium import webdriver

driver = webdriver.PhantomJS(executable_path='/Users/path/Downloads/PhantomJS/bin/phantomjs')

driver.set_window_size(4000, 3000)  # choose a resolution
driver.get('f_map_marker.html')

time.sleep(1)
driver.save_screenshot('f_map_marker.png')

So, the f_map_marker.png file is blank.
Does anyone has an idea, why it behaves this way, and how I can solve the issue ?
Any hints will be welcome.

Kyv
  • 615
  • 6
  • 26

1 Answers1

0

I checked your code with Firefox (geckodriver) instead of PhantomJS and I have the 3 circles on the map in the "f_map_marker.png" file. Maybe it is because the PhantomJS project is not maintained anymore. You can have look to the Github comment on the PhantomJS repository : https://github.com/ariya/phantomjs/issues/15344

Pierre-Loic
  • 1,524
  • 1
  • 6
  • 12
  • Thanks @Pierre-Loic, I will check it. – Kyv Dec 06 '20 at 09:47
  • would you please have a look, at this [link](https://stackoverflow.com/questions/65166811/how-to-convert-html-map-into-image-png-or-jpg) ? I have created a similar question, where I try to make an image out of the html file. – Kyv Dec 06 '20 at 10:10
  • `pdfkit` only works for creating pdf. I think you have a typo in your script : you need to use `imgkit` to have images as output – Pierre-Loic Dec 06 '20 at 10:24
  • According to the [doc.] (https://pypi.org/project/imgkit/) this should work : `import imgkit and imgkit.from_file('f_map.html', 'outpdf.pdf') `. But I get an error: `OSError: No wkhtmltoimage executable found: "b''" `. I guess it is because, I have not precise the path to `wkhtmltopdf`. How could I do that ? Any idea ? In case of pdf, `config = pdfkit.configuration(wkhtmltopdf='/usr/local/bin/wkhtmltopdf')` is the solution. – Kyv Dec 06 '20 at 10:40