#!/usr/bin/env python # coding: utf-8 # Load GeoJSON as in [GeoJSON_and_choropleth.ipynb](https://github.com/python-visualization/folium/blob/master/examples/GeoJSON_and_choropleth.ipynb). # In[1]: import json import folium 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[2]: m = folium.Map([43, -100], zoom_start=4, tiles="stamentoner") folium.GeoJson(geo_json_data).add_to(m) m # ## Map with custom pane # In[3]: 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 # ## Same, but with a different tileset # In[4]: 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 # More tile providers can be found at https://leaflet-extras.github.io/leaflet-providers/preview/.