Skip to content

Commit 79e7d94

Browse files
Lazy-load the JupyterLite embedded page in documentation (#1007)
* Remove the retrolite directive, since there are already the links and the buttons to click and make an online try. * Reverse the change of removing the retrolite directive and use it with a prompt option enabling the lazy load. * Replace try Retrolite by try ipyleaflet in the prompt option.
1 parent d929208 commit 79e7d94

File tree

3 files changed

+111
-3
lines changed

3 files changed

+111
-3
lines changed

docs/source/index.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Introduction to ipyleaflet
22
==========================
3+
34
Ipyleaflet is a `Jupyter widget <https://ipywidgets.readthedocs.io>`_ for
45
`Leaflet.js <https://leafletjs.com/>`_ , enabling interactive maps in the
56
Jupyter notebook. Every object in ipyleaflet (including the Map, TileLayers, Layers,
@@ -15,10 +16,13 @@ Try it online
1516
.. image:: https://jupyterlite.rtfd.io/en/latest/_static/badge.svg
1617
:target: ./lite/lab?path=ipyleaflet.ipynb
1718

18-
You can try ipyleaflet below, or open many other live examples in a new browser tab with
19-
`JupyterLite <./lite/lab?path=ipyleaflet.ipynb>`_ or `RetroLite <./lite/retro/tree>`_.
19+
You can try ipyleaflet below, or open many other live examples in a new browser tab with : `JupyterLite <./lite/lab?path=ipyleaflet.ipynb>`_ or `RetroLite <./lite/retro/tree>`_.
2020

2121
.. retrolite:: ipyleaflet.ipynb
22+
:width: 100%
23+
:height: 810px
24+
:prompt: Try ipyleaflet!
25+
2226

2327
Table of Contents
2428
-----------------

examples/Heatmap_with_colormap.ipynb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# Set up for JupyterLite\n",
10+
"try:\n",
11+
" import piplite\n",
12+
" await piplite.install('ipyleaflet')\n",
13+
"except ImportError:\n",
14+
" pass"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": null,
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"from random import uniform\n",
24+
"import time\n",
25+
"import ipyleaflet\n",
26+
"import json\n",
27+
"import pandas as pd\n",
28+
"from branca.colormap import linear, LinearColormap"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"def create_random_data(length):\n",
38+
" \"Return a list of some random lat/lon/value triples.\"\n",
39+
" return [\n",
40+
" [uniform(-80, 80), uniform(-180, 180), uniform(0, 1000)] for i in range(length)\n",
41+
" ]"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"m = ipyleaflet.Map(center=[0, 0], zoom=2)"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": null,
56+
"metadata": {},
57+
"outputs": [],
58+
"source": [
59+
"heat = ipyleaflet.Heatmap(locations=create_random_data(1000), radius=20, blur=10)\n",
60+
"m.add(heat)\n",
61+
"colormap_control = ipyleaflet.ColormapControl(\n",
62+
" caption='Intensity',\n",
63+
" colormap=heat.colormap,\n",
64+
" value_min=heat.vmin,\n",
65+
" value_max=heat.vmax,\n",
66+
" position='topright',\n",
67+
" transparent_bg=True\n",
68+
")\n",
69+
"m.add(colormap_control)"
70+
]
71+
}
72+
],
73+
"metadata": {
74+
"kernelspec": {
75+
"display_name": "Python 3 (ipykernel)",
76+
"language": "python",
77+
"name": "python3"
78+
},
79+
"language_info": {
80+
"codemirror_mode": {
81+
"name": "ipython",
82+
"version": 3
83+
},
84+
"file_extension": ".py",
85+
"mimetype": "text/x-python",
86+
"name": "python",
87+
"nbconvert_exporter": "python",
88+
"pygments_lexer": "ipython3",
89+
"version": "3.9.13"
90+
}
91+
},
92+
"nbformat": 4,
93+
"nbformat_minor": 4
94+
}

ipyleaflet/leaflet.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import copy
66
import asyncio
77
import json
8+
from folium import LinearColormap
89
import xyzservices
910
from datetime import date, timedelta
1011
from math import isnan
@@ -814,7 +815,16 @@ class Heatmap(RasterLayer):
814815
max = Float(1.0).tag(sync=True, o=True)
815816
radius = Float(25.0).tag(sync=True, o=True)
816817
blur = Float(15.0).tag(sync=True, o=True)
817-
gradient = Dict({0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1.0: 'red'}).tag(sync=True, o=True)
818+
colors = ['blue', 'cyan', 'lime', 'yellow', 'red']
819+
values = [0.4, 0.6, 0.7, 0.8, 1.0]
820+
dict ={}
821+
for i in range(len(values)):
822+
dict[values[i]] = colors[i]
823+
vmin = values[0]
824+
vmax = values[len(values)-1]
825+
gradient = Dict(dict).tag(sync=True, o=True)
826+
colormap = LinearColormap([colors], vmin=vmin, vmax=vmax)
827+
818828

819829

820830
class VectorTileLayer(Layer):

0 commit comments

Comments
 (0)