{ "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": [ "# Examples of plugins usage in folium" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this notebook we show a few illustrations of folium's plugin extensions.\n", "\n", "This is a development notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Adds a button to enable/disable zoom scrolling." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ScrollZoomToggler" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from folium import plugins\n", "\n", "\n", "m = folium.Map([45, 3], zoom_start=4)\n", "\n", "plugins.ScrollZoomToggler().add_to(m)\n", "\n", "m.save(os.path.join('results', 'Plugins_0.html'))\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## MarkerCluster" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Adds a MarkerCluster layer on the map." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "\n", "\n", "N = 100\n", "\n", "data = np.array(\n", " [\n", " np.random.uniform(low=35, high=60, size=N), # Random latitudes in Europe.\n", " np.random.uniform(low=-12, high=30, size=N), # Random longitudes in Europe.\n", " range(N), # Popups texts are simple numbers.\n", " ]\n", ").T\n", "\n", "m = folium.Map([45, 3], zoom_start=4)\n", "\n", "plugins.MarkerCluster(data).add_to(m)\n", "\n", "m.save(os.path.join('results', 'Plugins_1.html'))\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Terminator" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map([45, 3], zoom_start=1)\n", "\n", "plugins.Terminator().add_to(m)\n", "\n", "m.save(os.path.join('results', 'Plugins_2.html'))\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Leaflet.boatmarker" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map([30, 0], zoom_start=3)\n", "\n", "plugins.BoatMarker(\n", " location=(34, -43),\n", " heading=45,\n", " wind_heading=150,\n", " wind_speed=45,\n", " color='#8f8'\n", ").add_to(m)\n", "\n", "plugins.BoatMarker(\n", " location=(46, -30),\n", " heading=-20,\n", " wind_heading=46,\n", " wind_speed=25,\n", " color='#88f'\n", ").add_to(m)\n", "\n", "\n", "m.save(os.path.join('results', 'Plugins_3.html'))\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Fullscreen" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map(location=[41.9, -97.3], zoom_start=4)\n", "\n", "plugins.Fullscreen(\n", " position='topright',\n", " title='Expand me',\n", " title_cancel='Exit me',\n", " force_separate_button=True).add_to(m)\n", "\n", "\n", "m.save(os.path.join('results', 'Plugins_4.html'))\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Timestamped GeoJSON" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from folium import plugins\n", "\n", "\n", "m = folium.Map(\n", " location=[35.68159659061569, 139.76451516151428],\n", " zoom_start=16\n", ")\n", "\n", "# Lon, Lat order.\n", "lines = [\n", " {\n", " 'coordinates': [\n", " [139.76451516151428, 35.68159659061569],\n", " [139.75964426994324, 35.682590062684206],\n", " ],\n", " 'dates': [\n", " '2017-06-02T00:00:00',\n", " '2017-06-02T00:10:00'\n", " ],\n", " 'color': 'red'\n", " },\n", " {\n", " 'coordinates': [\n", " [139.75964426994324, 35.682590062684206],\n", " [139.7575843334198, 35.679505030038506],\n", " ],\n", " 'dates': [\n", " '2017-06-02T00:10:00',\n", " '2017-06-02T00:20:00'\n", " ],\n", " 'color': 'blue'\n", " },\n", " {\n", " 'coordinates': [\n", " [139.7575843334198, 35.679505030038506],\n", " [139.76337790489197, 35.678040905014065],\n", " ],\n", " 'dates': [\n", " '2017-06-02T00:20:00',\n", " '2017-06-02T00:30:00'\n", " ],\n", " 'color': 'green',\n", " 'weight': 15,\n", " },\n", " {\n", " 'coordinates': [\n", " [139.76337790489197, 35.678040905014065],\n", " [139.76451516151428, 35.68159659061569],\n", " ],\n", " 'dates': [\n", " '2017-06-02T00:30:00',\n", " '2017-06-02T00:40:00'\n", " ],\n", " 'color': '#FFFFFF',\n", " },\n", "]\n", "\n", "\n", "features = [\n", " {\n", " 'type': 'Feature',\n", " 'geometry': {\n", " 'type': 'LineString',\n", " 'coordinates': line['coordinates'],\n", " },\n", " 'properties': {\n", " 'times': line['dates'],\n", " 'style': {\n", " 'color': line['color'],\n", " 'weight': line['weight'] if 'weight' in line else 5\n", " }\n", " }\n", " }\n", " for line in lines\n", "]\n", "\n", "\n", "plugins.TimestampedGeoJson({\n", " 'type': 'FeatureCollection',\n", " 'features': features,\n", "}, period='PT1M', add_last_point=True).add_to(m)\n", "\n", "\n", "m.save(os.path.join('results', 'Plugins_5.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 }