{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.5.0+48.gbbfb350.dirty\n" ] } ], "source": [ "import os\n", "import folium\n", "\n", "\n", "print(folium.__version__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Plugin: leaflet-search\n", "\n", "## Polygon search layer" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "\n", "with open(os.path.join('data', 'search_states.json')) as f:\n", " states = json.loads(f.read())\n", "\n", "\n", "def getColor(d):\n", " if d > 1000:\n", " return '#800026'\n", " if d > 500:\n", " return '#BD0026'\n", " if d > 200:\n", " return '#E31A1C'\n", " if d > 100:\n", " return '#FC4E2A'\n", " if d > 50:\n", " return '#FD8D3C'\n", " if d > 20:\n", " return '#FEB24C'\n", " if d > 10:\n", " return '#FED976'\n", " else:\n", " return '#FFEDA0'\n", "\n", "\n", "for state in states['features']:\n", " state['properties']['color'] = getColor(state['properties']['density'])" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from folium import plugins\n", "\n", "\n", "m = folium.Map(\n", " location=[37.8, -96],\n", " tiles='cartodbpositron',\n", " zoom_start=3,\n", ")\n", "\n", "plugins.Search(states, search_zoom=6, geom_type='Polygon').add_to(m)\n", "\n", "m.save(os.path.join('results', 'Plugins_search_polygon.html'))\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Points search layer" ] }, { "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(\n", " location=[41.9, 12.5],\n", " tiles='cartodbpositron',\n", " zoom_start=12,\n", ")\n", "\n", "\n", "with open(os.path.join('data', 'search_bars_rome.json')) as f:\n", " bars = json.loads(f.read())\n", "\n", "plugins.Search(bars, search_zoom=20).add_to(m)\n", "\n", "\n", "m.save(os.path.join('results', 'Plugins_search_points.html'))\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.6.3" } }, "nbformat": 4, "nbformat_minor": 2 }