{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import json\n", "\n", "\n", "us_states = os.path.join(\"data\", \"us-states.json\")\n", "\n", "with open(us_states) as f:\n", " states = json.load(f)\n", "\n", "kw = {\"location\": [48, -102], \"zoom_start\": 3}" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import folium\n", "from folium import GeoJson\n", "\n", "\n", "m = folium.Map(tiles=None, **kw)\n", "\n", "GeoJson(states).add_to(m)\n", "\n", "m" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import branca\n", "\n", "# Create a white image of 4 pixels, and embed it in a url.\n", "white_tile = branca.utilities.image_to_url([[1, 1], [1, 1]])\n", "\n", "# Create a map using this url for each tile.\n", "m = folium.Map(tiles=white_tile, attr=\"white tile\", **kw)\n", "\n", "GeoJson(states).add_to(m)\n", "\n", "m" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "images = [[(-1) ** ((i + j) // 30) for i in range(300)] for j in range(300)]\n", "\n", "tiles = branca.utilities.image_to_url(images)\n", "\n", "m = folium.Map(tiles=tiles, attr=\"Just because we can\", **kw)\n", "\n", "GeoJson(states).add_to(m)\n", "\n", "m" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "images = [[(-1) ** ((i // 30 + j // 30)) for i in range(300)] for j in range(300)]\n", "\n", "tiles = branca.utilities.image_to_url(images)\n", "\n", "m = folium.Map(tiles=tiles, attr=\"Just because we can\", **kw)\n", "\n", "GeoJson(states).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.9.0" } }, "nbformat": 4, "nbformat_minor": 1 }