Skip to content

Commit 2b7f072

Browse files
authored
Merge pull request #384 from martinRenou/docs
Add Usage section in the docs
2 parents f175f47 + 9d59133 commit 2b7f072

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ipyleaflet
22

33
[![Documentation](http://readthedocs.org/projects/ipyleaflet/badge/?version=latest)](https://ipyleaflet.readthedocs.io/en/latest/?badge=latest)
4-
[![Binder](https://img.shields.io/badge/launch-binder-brightgreen.svg)](https://mybinder.org/v2/gh/jupyter-widgets/ipyleaflet/stable?filepath=examples)
4+
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jupyter-widgets/ipyleaflet/stable?filepath=examples)
55
[![Join the Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jupyter-widgets/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
66

77
A Jupyter / Leaflet bridge enabling interactive maps in the Jupyter notebook.

docs/source/api_reference/marker.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Example
99

1010
.. code::
1111
12-
from ipyleaflet import Marker
12+
from ipyleaflet import Map, Marker
1313
1414
center = (52.204793, 360.121558)
1515

docs/source/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ ipyleaflet: Interactive maps in the Jupyter notebook
77

88
installation
99

10+
.. toctree::
11+
:caption: Usage
12+
13+
usage
14+
1015
.. toctree::
1116
:caption: Map
1217
:maxdepth: 2

docs/source/usage.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Usage
2+
=====
3+
4+
ipyleaflet is an interactive widgets library, it is based on `ipywidgets <https://github.com/jupyter-widgets/ipywidgets/>`_.
5+
This means that everything in ipyleaflet (e.g. the ``Map``, ``TileLayers``, ``Markers``...) is interactive: you can dynamically update
6+
attributes from Python or from the Notebook interface.
7+
8+
For example, you can create a ``Marker`` layer and interact with it:
9+
10+
.. code::
11+
12+
from ipyleaflet import Map, Marker
13+
14+
center = (52.204793, 360.121558)
15+
16+
m = Map(center=center, zoom=15)
17+
18+
marker = Marker(location=center, draggable=True)
19+
m.add_layer(marker);
20+
21+
display(m)
22+
23+
# Now that the marker is on the Map, you can drag it with your mouse,
24+
# it will automatically update the `marker.location` attribute in Python
25+
26+
# You can also update the marker location from Python, that will update the
27+
# marker location on the Map:
28+
marker.location = (50, 356)
29+
30+
`ipywidgets <https://github.com/jupyter-widgets/ipywidgets/>`_ is powered by `traitlets <https://github.com/ipython/traitlets/>`_,
31+
this brings an observer pattern implementation which allows you to react on widget attribute changes.
32+
33+
For example, you can define a Python callback that will be called whenever the marker location has changed:
34+
35+
.. code::
36+
37+
def on_location_changed(event):
38+
# Do some computation given the new marker location, accessible from `event['new']`
39+
pass
40+
41+
marker.observe(on_location_changed, 'location')
42+
43+
Please check out the `traitlets documentation <https://traitlets.readthedocs.io/>`_ for more details about the observer pattern implementation.
44+
45+
.. note::
46+
Everything in ipyleaflet **is** an interactive widget, from the ``Map`` class to ``Layer`` and ``Control`` classes. This means that what we
47+
achieved here with ``marker.location``, you can achieve it with ``map.zoom``, ``layer.url``, or ``heatmap.locations``
48+
49+
You can try ipyleaflet online using binder, no need to install anything on your computer:
50+
51+
.. image:: https://mybinder.org/badge_logo.svg
52+
:target: https://mybinder.org/v2/gh/jupyter-widgets/ipyleaflet/stable?filepath=examples

0 commit comments

Comments
 (0)