{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Preleminary demo of the pattern plugin for Folium" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import folium\n", "from folium import plugins" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map([40., -105.], zoom_start=6)\n", "\n", "url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/us-states.json'\n", "stripes = plugins.pattern.StripePattern(angle=-45)\n", "stripes.add_to(m)\n", "\n", "circles = plugins.pattern.CirclePattern(width=20, height=20, radius=5, fill_opacity=0.5, opacity=1)\n", "circles.add_to(m)\n", "\n", "def style_function(feature):\n", " default_style = {\n", " 'opacity':1.0,\n", " 'fillColor': '#ffff00',\n", " 'color': 'black',\n", " 'weight': 2\n", " }\n", " \n", " if feature['properties']['name'] == 'Colorado':\n", " default_style['fillPattern'] = stripes\n", " default_style['fillOpacity'] = 1.0\n", " \n", " if feature['properties']['name'] == 'Utah':\n", " default_style['fillPattern'] = circles\n", " default_style['fillOpacity'] = 1.0\n", " \n", " return default_style\n", "\n", "# Adding remote GeoJSON as additional layer.\n", "folium.GeoJson(url, smooth_factor=0.5, style_function=style_function).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.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }