0

I'm using folium library. I want to change bgcolor of the 2-nd layer of map to 'yellow'.

I've tried the code bellow, everything seems to be OK, but I think it's an issue with .read() or smth like this:

import folium
import pandas


data = pandas.read_csv("Volcanoes.txt")
lat = list(data['LAT'])
lon = list(data['LON'])
elev = list(data['ELEV'])


def high_color(elevation):
    if elevation < 1100:
        return "green"
    elif 1100 <= elevation < 3000:
        return 'orange'
    else:
        return 'red'
notmap = folium.Map(location=[40.954898799999995, -121.3610001], zoom_start=5)

feature_group = folium.FeatureGroup(name="My Map")

for lt, ln, el in zip(lat, lon, elev):
    feature_group.add_child(folium.CircleMarker(location=[lt, ln], popup = str(el)+" m.",
    radius=8, fill_color = high_color(el), color = 'grey', fill = True, fill_opacity = 0.7))

feature_group.add_child(folium.GeoJson(data = open('world.json', 'r', encoding='utf-8-sig'),
style_function = lambda x: {'fillColor':'yellow'}.read()))


notmap.add_child(feature_group)
notmap.save("map1.html")


Traceback (most recent call last):
  File "map.py", line 27, in <module>
    style_function = lambda x: {'fillColor':'yellow'}.read()))
  File "/home/john/.local/lib/python3.6/site-packages/folium/features.py", line 418, in __init__
    raise ValueError('Unhandled object {!r}.'.format(data))
ValueError: Unhandled object <_io.TextIOWrapper name='world.json' mode='r' encoding='utf-8-sig'>.
Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142
Jimmy Hoho
  • 37
  • 1
  • 4

1 Answers1

0

[SOLVED] I just change the position of .read() method.

the following line should look like this:

feature_group.add_child(folium.GeoJson(data = open('world.json', 'r', encoding='utf-8-sig').read(), style_function = lambda x: {'fillColor':'yellow'}))
Jimmy Hoho
  • 37
  • 1
  • 4