In [ ]:
from multiprocessing import Process
from flask import Flask, Response
from requests import get as fetch
from ipyleaflet import Map, basemaps
In [ ]:
app = Flask(__name__)
@app.route("/scramble/<int:z>/<int:x>/<int:y>")
def scramble(z, x, y):
"Serve scrambled tiles from two basemaps."
urls = [basemaps.Esri[name]['url'] for name in ['WorldStreetMap', 'WorldTopoMap']]
url = urls[(x + y) % 2].format(x=x, y=y, z=z)
img = fetch(url).content
return Response(img, mimetype='image/png')
In [ ]:
p = Process(target=app.run)
p.start()
In [ ]:
url = 'http://localhost:5000/scramble/{z}/{x}/{y}'
bm = {'url': url, 'attribution': 'Scrambled Tiles'}
Map(center=(48.86, 2.34), level=10, basemap=bm)
In [ ]:
p.kill()