Skip to content

Instantly share code, notes, and snippets.

@deeplook
Last active June 27, 2019 19:57
Show Gist options
  • Save deeplook/6ff063481d6908a173ad30502b49c8ed to your computer and use it in GitHub Desktop.
Save deeplook/6ff063481d6908a173ad30502b49c8ed to your computer and use it in GitHub Desktop.
Test tile caching in ipyleaflet
Display the source blob
Display the rendered blob
Raw
test_tile_caching.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Test Tile Caching\n",
"\n",
"This tries to mimick an effect of moving from one map center to another, like a *very* simple flyover, but without the vertical component shown e.g. here: https://panel.pyviz.org/gallery/external/deck.gl.html#gallery-deck-gl.\n",
"\n",
"The code below indicated that the map tiles seem not to be as well cached in the browser as one might expect, but keep being reloaded from the server. One might hope for some configuration in Leaflet to make this smoother..."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import time\n",
"\n",
"import geopy\n",
"import ipyleaflet\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Define Start and End Points"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geocode = geopy.geocoders.Nominatim(user_agent=\"mapflight\").geocode\n",
"lat_lon = 'latitude longitude'.split()\n",
"paris = [getattr(geocode('Paris'), attr) for attr in lat_lon]\n",
"brussels = [getattr(geocode('Brussels'), attr) for attr in lat_lon]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Show Map at Start Point"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = ipyleaflet.Map(center=paris)\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Build trajectory"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# This is on a \"straight\" line for illustration purposes, but should be on a great circle!\n",
"lats = np.linspace(paris[0], brussels[0], 30)\n",
"lons = np.linspace(paris[1], brussels[1], 30)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Fly one way, pause, and return"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for point in zip(lats, lons):\n",
" m.center = point\n",
" time.sleep(0.5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"time.sleep(1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for point in reversed(list(zip(lats, lons))):\n",
" m.center = point\n",
" time.sleep(0.5)"
]
}
],
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment