Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
m = folium.Map([48., 5.], tiles='stamentoner', zoom_start=6)
layer = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
folium.raster_layers.TileLayer(
tiles=layer,
name='OpenStreetMap',
attr='attribution'
).add_to(m)
folium.raster_layers.TileLayer(
tiles=layer,
name='OpenStreetMap2',
attr='attribution2',
overlay=True).add_to(m)
folium.LayerControl().add_to(m)
m._repr_html_()
bounds = m.get_bounds()
assert bounds == [[None, None], [None, None]], bounds
def test_feature_group(self):
"""Test FeatureGroup."""
m = folium.Map()
feature_group = folium.FeatureGroup()
feature_group.add_child(folium.Marker([45, -30],
popup=folium.Popup('-30')))
feature_group.add_child(folium.Marker([45, 30],
popup=folium.Popup('30')))
m.add_child(feature_group)
m.add_child(folium.LayerControl())
m._repr_html_()
bounds = m.get_bounds()
assert bounds == [[45, -30], [45, 30]], bounds
###############################################################################
ice_edge = '/gdata/folium/data/antarctic_ice_edge.json'
map_b = folium.Map(
location=[-59.1759, -11.6016],
tiles='Mapbox Bright',
zoom_start=2
)
folium.GeoJson(ice_edge, name='geojson').add_to(map_b)
###############################################################################
icej='/gdata/folium/data/antarctic_ice_shelf_topo.json'
folium.TopoJson(open(icej),
'objects.antarctic_ice_shelf',
name='topojson'
).add_to(map_b)
###############################################################################
folium.LayerControl().add_to(map_b)
map_b.save('folium_b.html')
###############################################################################
import pandas as pd
state_geo = '/gdata/folium/data/us-states.json'
csvf = '/gdata/folium/data/US_Unemployment_Oct2012.csv'
state_data = pd.read_csv(csvf)
map_c = folium.Map(location=[48, -102], zoom_start=3)
folium.Choropleth(geo_data=state_geo,
name='choropleth', data=state_data,
columns=['State', 'Unemployment'], key_on='feature.id',
fill_color='YlGn', fill_opacity=0.7, line_opacity=0.2,
legend_name='失业率 (%)').add_to(map_c)
folium.LayerControl().add_to(map_c)
map_c.save('folium_c.html')
###############################################################################
bins = list(state_data['Unemployment'].quantile([0,0.25,0.5,0.75,1]))
m.choropleth(
geo_data=(open("worldmapshape.json",encoding = "utf_8_sig").read()),
name='choropleth',
data=df,
columns=['Country', 'Oil Production'],
key_on='properties.name',
fill_color='YlOrRd',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Oil Production Thousand Barrels/Day',
threshold_scale=[0.0,1.0, 150.0, 800.0, 2000.0, 4000.0]
)
#layout control is just a map filter
#we can unselect choropleth any time
folium.LayerControl().add_to(m)
display(m)
# style="font-family: serif;",
),
style_function=style_fcn,
highlight_function=highlight_fcn)
# Here's how to add a popup to the whole GeoJSON object.
# gj.add_child(folium.Popup('outline Popup on GeoJSON'))
# But it doesn't help in adding a popup that shows the current polygon.
# The only way seems to be to add each polygon as a separate feature:
# https://stackoverflow.com/a/54738210
# There may eventually be a way to do this:
# https://github.com/python-visualization/folium/issues/802
gj.add_to(m)
folium.LayerControl().add_to(m)
m.save('index.html')
print("Saved to index.html")
"""
my_map = folium.Map(location=location, zoom_start=zoom_start)
# add possible tiles
folium.TileLayer('cartodbpositron').add_to(my_map)
folium.TileLayer('cartodbdark_matter').add_to(my_map)
folium.TileLayer('openstreetmap').add_to(my_map)
folium.TileLayer('Mapbox Bright').add_to(my_map)
folium.TileLayer('stamentoner').add_to(my_map)
# add markers layer
marker_cluster = MarkerCluster().add_to(my_map)
# add the layer control
folium.LayerControl().add_to(my_map)
return my_map, marker_cluster
fc = [4, '#CC0000']
else:
fc = [2, '#FFFFFF']
cm = folium.CircleMarker(
point, color=color, fill=True,
fill_color=fc[1], fill_opacity=1, radius=fc[0])
fg.add_child(cm)
m.add_child(fg)
lines = df.route_id.unique()
for line in lines:
a(df, line, pal, m)
static_map = create_basemap(df)
map_all(df, pal, static_map)
folium.LayerControl().add_to(static_map)
return static_map
def show(self):
LC = folium.LayerControl()
self.add_child(LC)
return self