|
1 | 1 | Map |
2 | 2 | === |
3 | 3 |
|
4 | | -Example |
5 | | -------- |
| 4 | +Usage |
| 5 | +----- |
6 | 6 |
|
7 | 7 | .. jupyter-execute:: |
8 | 8 |
|
9 | 9 | from ipyleaflet import Map, basemaps, basemap_to_tiles |
10 | 10 |
|
11 | 11 | m = Map( |
12 | | - layers=(basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-04-08"), ), |
| 12 | + basemap=basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-04-08"), |
13 | 13 | center=(52.204793, 360.121558), |
14 | 14 | zoom=4 |
15 | 15 | ) |
16 | 16 |
|
17 | 17 | m |
18 | 18 |
|
| 19 | +You can find the list of available basemaps in the :ref:`basemaps-section` page. |
| 20 | + |
| 21 | +You can add multiple layers and controls to the map, using the ``add_layer``/``add_control`` methods. All those layers and controls are widgets themselves. So you can dynamically update their attributes from Python or by interacting with the map on the page (see :ref:`usage-section`) |
| 22 | + |
| 23 | +.. jupyter-execute:: |
| 24 | + |
| 25 | + from ipyleaflet import Map, Marker, basemaps, basemap_to_tiles |
| 26 | + |
| 27 | + m = Map( |
| 28 | + basemap=basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-04-08"), |
| 29 | + center=(52.204793, 360.121558), |
| 30 | + zoom=4 |
| 31 | + ) |
| 32 | + |
| 33 | + m.add_layer(Marker(location=(52.204793, 360.121558))) |
| 34 | + |
| 35 | + m |
| 36 | + |
| 37 | +Save to HTML |
| 38 | +------------ |
| 39 | + |
| 40 | +You can save the ``Map`` and all its layers and controls to an HTML page using the ``save`` method: |
| 41 | + |
| 42 | +.. code:: |
| 43 | +
|
| 44 | + m.save('my_map.html', title='My Map') |
| 45 | +
|
| 46 | +.. note:: |
| 47 | + The saved file is a static HTML page, so there is no possible interaction with Python anymore. This means that all the Python callbacks you defined (`e.g.` on marker move) cannot be executed. If you want to serve the ``Map`` widget to an HTML page while keeping a Python kernel alive on the server, you might want to look at `Voilà <https://voila.readthedocs.io>`_. |
| 48 | + |
19 | 49 |
|
20 | 50 | Attributes |
21 | 51 | ---------- |
@@ -65,4 +95,5 @@ add_control Control instance Add a new control t |
65 | 95 | remove_control Control instance Remove a control from the map |
66 | 96 | clear_controls Remove all controls from the map |
67 | 97 | on_interaction callable object Add a callback on interaction |
| 98 | +save output file Save the map to an HTML file |
68 | 99 | ================ ===================================== === |
0 commit comments