I am plotting some maps using folium. Works pretty smoothly. However, I could not figure out how to pre-calculate the right level of zoom
I can set it automatically
import folium
m = folium.Map([point_of_interest.iloc[0].Lat, point_of_interest.iloc[0].Long])
but in my use case I would need to pre-calculate zoom_start
such that:
(Lat,Long)
from my pandas
dataframe of point_of_interest
are within the mapzoom_start (int, default 10) – Initial zoom level for the map. attr (string, default None) – Map tile attribution; only required if passing custom tile URL.
As a general suggestion, you could use folium. Popup() with the combo of min_width and max_width parameters to force the width of a popup. Show activity on this post. It worked for me, you need to initiate marker with custom icon in each iteration as shown in this code, It will work perfectly...
Folium allows us to create maps with different tiles like Stamen Terrain, Stamen Toner, Stamen Water Color, CartoDB Positron, and many more. By default, the tiles are set to OpenStreetMap. Each tileset shows different features of a map and is suitable for different purposes.
folium's fit_bounds method should work for you
Some random sample data
import folium
import numpy as np
import pandas as pd
center_point = [40, -90]
data = (
np.random.normal(size=(100, 2)) *
np.array([[.5, .5]]) +
np.array([center_point])
)
df = pd.DataFrame(data, columns=['Lat', 'Long'])
Creating a map with some markers
m = folium.Map(df[['Lat', 'Long']].mean().values.tolist())
for lat, lon in zip(df['Lat'], df['Long']):
folium.Marker([lat, lon]).add_to(m)
fit_bounds
requires the 'bounds' of our data in the form of the southwest and northeast corners. There are some padding parameters you can use as well
sw = df[['Lat', 'Long']].min().values.tolist()
ne = df[['Lat', 'Long']].max().values.tolist()
m.fit_bounds([sw, ne])
m
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With