{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.3.0+162.g0540622.dirty\n" ] } ], "source": [ "import os\n", "import folium\n", "\n", "print(folium.__version__)" ] }, { "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": 2, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map(\n", " location=[-59.1759, -11.6016],\n", " tiles='Mapbox Bright',\n", " zoom_start=2\n", ")\n", "\n", "\n", "fname = os.path.join('data', 'antarctic_ice_shelf_topo.json')\n", "\n", "folium.TopoJson(\n", " data=open(fname),\n", " object_path='objects.antarctic_ice_shelf',\n", " name='default_smoothing',\n", " smooth_factor=1\n", ").add_to(m)\n", "\n", "\n", "folium.TopoJson(\n", " data=open(fname),\n", " object_path='objects.antarctic_ice_shelf',\n", " name='default_smoothing',\n", " smooth_factor=10,\n", " style_function=lambda x: {'color': '#004c00', 'opacity': '0.7'}\n", ").add_to(m)\n", "\n", "folium.LayerControl().add_to(m)\n", "\n", "m.save(os.path.join('results', 'SmoothFactor.html'))\n", "\n", "m" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 1 }