In [1]:
import os
import folium


print(folium.__version__)


0.5.0+48.gbbfb350.dirty

Plugin: leaflet-search

Polygon search layer


In [2]:
import json


with open(os.path.join('data', 'search_states.json')) as f:
    states = json.loads(f.read())


def getColor(d):
    if d > 1000:
        return '#800026'
    if d > 500:
        return '#BD0026'
    if d > 200:
        return '#E31A1C'
    if d > 100:
        return '#FC4E2A'
    if d > 50:
        return '#FD8D3C'
    if d > 20:
        return '#FEB24C'
    if d > 10:
        return '#FED976'
    else:
        return '#FFEDA0'


for state in states['features']:
    state['properties']['color'] = getColor(state['properties']['density'])

In [3]:
from folium import plugins


m = folium.Map(
    location=[37.8, -96],
    tiles='cartodbpositron',
    zoom_start=3,
)

plugins.Search(states, search_zoom=6, geom_type='Polygon').add_to(m)

m.save(os.path.join('results', 'Plugins_search_polygon.html'))

m


Out[3]:

Points search layer


In [4]:
m = folium.Map(
    location=[41.9, 12.5],
    tiles='cartodbpositron',
    zoom_start=12,
)


with open(os.path.join('data', 'search_bars_rome.json')) as f:
    bars = json.loads(f.read())

plugins.Search(bars, search_zoom=20).add_to(m)


m.save(os.path.join('results', 'Plugins_search_points.html'))

m


Out[4]: