In [1]:
import os
import folium

print(folium.__version__)

0.5.0+27.g2d457b0.dirty


# Using Leaflet's Smooth Factor Option¶

Polyline objects in leaflet are smoothed by default. This removes points from the line, putting less load on the browser when drawing. The level of smoothing can be specified by passing smoothFactor as an option when creating any Polyline object.

In folium, the level of smoothing can be determined by passing smooth_factor as an argument when initialising GeoJson, TopoJson and Choropleth objects. There are no upper or lower bounds to the smoothing level; Leaflet's default is 1.

In [2]:
m = folium.Map(
location=[-59.1759, -11.6016],
tiles='Mapbox Bright',
zoom_start=2
)

fname = os.path.join('data', 'antarctic_ice_shelf_topo.json')

folium.TopoJson(
data=open(fname),
object_path='objects.antarctic_ice_shelf',
name='default_smoothing',
smooth_factor=1
).add_to(m)

folium.TopoJson(
data=open(fname),
object_path='objects.antarctic_ice_shelf',
name='default_smoothing',
smooth_factor=10,
style_function=lambda x: {'color': '#004c00', 'opacity': '0.7'}
).add_to(m)

folium.LayerControl().add_to(m)

m.save(os.path.join('results', 'SmoothFactor.html'))

m

Out[2]: