{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using Leaflet's Smooth Factor Option\n", "\n", "[Polyline](http://leafletjs.com/reference.html#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](http://leafletjs.com/reference.html#polyline-smoothfactor) by passing `smoothFactor` as an option when creating any Polyline object.\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import json\n", "\n", "import folium\n", "import requests\n", "\n", "\n", "m = folium.Map(location=[-59.1759, -11.6016], tiles=\"cartodbpositron\", zoom_start=2)\n", "\n", "\n", "url = (\n", " \"https://raw.githubusercontent.com/python-visualization/folium/master/examples/data\"\n", ")\n", "fname = f\"{url}/antarctic_ice_shelf_topo.json\"\n", "topo = json.loads(requests.get(fname).text)\n", "\n", "\n", "folium.TopoJson(\n", " data=topo,\n", " object_path=\"objects.antarctic_ice_shelf\",\n", " name=\"default_smoothing\",\n", " smooth_factor=1,\n", " style_function=lambda x: {\"color\": \"#004c00\", \"opacity\": \"0.7\"},\n", ").add_to(m)\n", "\n", "\n", "folium.TopoJson(\n", " data=topo,\n", " object_path=\"objects.antarctic_ice_shelf\",\n", " name=\"default_smoothing\",\n", " smooth_factor=10,\n", " style_function=lambda x: {\"color\": \"#1d3060\", \"opacity\": \"0.7\"},\n", ").add_to(m)\n", "\n", "folium.LayerControl().add_to(m)\n", "\n", "m" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.0" } }, "nbformat": 4, "nbformat_minor": 1 }