#!/usr/bin/env python # coding: utf-8 # In[1]: import os import folium print(folium.__version__) # Load GeoJSON as in [GeoJSON_and_choropleth.ipynb](https://github.com/python-visualization/folium/blob/master/examples/GeoJSON_and_choropleth.ipynb). # In[2]: import json import requests url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data' us_states = f'{url}/us-states.json' geo_json_data = json.loads(requests.get(us_states).text) # # Using CustomPane to place labels above choropleth # ## Map without custom pane # In[3]: m = folium.Map([43, -100], zoom_start=4, tiles="stamentoner") folium.GeoJson(geo_json_data).add_to(m) m.save(os.path.join('results', 'CustomPanes_0.html')) m # ## Map with custom pane # In[4]: m = folium.Map([43, -100], zoom_start=4, tiles="stamentonerbackground") folium.GeoJson(geo_json_data).add_to(m) folium.map.CustomPane("labels").add_to(m) # Final layer associated to custom pane via the appropriate kwarg folium.TileLayer("stamentonerlabels", pane="labels").add_to(m) m.save(os.path.join('results', 'CustomPanes_1.html')) m # ## Same, but with a different tileset # In[5]: m = folium.Map([43, -100], zoom_start=4, tiles="CartoDBPositronNoLabels") folium.GeoJson(geo_json_data).add_to(m) folium.map.CustomPane("labels").add_to(m) # Final layer associated to custom pane via the appropriate kwarg folium.TileLayer("CartoDBPositronOnlyLabels", pane="labels").add_to(m) m.save(os.path.join('results', 'CustomPanes_2.html')) m # More tile providers can be found at https://leaflet-extras.github.io/leaflet-providers/preview/.