{ "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": [ "