Map#
Example#
from ipyleaflet import Map, basemaps, basemap_to_tiles
m = Map(
basemap=basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-04-08"),
center=(52.204793, 360.121558),
zoom=4
)
m
Usage#
You can find the list of available basemaps in the Basemaps page.
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 Usage)
from ipyleaflet import Map, Marker, basemaps, basemap_to_tiles
m = Map(
basemap=basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-04-08"),
center=(52.204793, 360.121558),
zoom=4
)
m.add_layer(Marker(location=(52.204793, 360.121558)))
m
As a Jupyter interactive widget, the layout of the Map
object is specified by a Layout attribute. See Layout and Styling of Jupyter widgets for details.
from ipyleaflet import Map, basemaps, basemap_to_tiles
from ipywidgets import Layout
m = Map(
basemap=basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-04-08"),
center=(52.204793, 360.121558),
zoom=4,
layout=Layout(width='80%', height='500px')
)
m.add_layer(Marker(location=(52.204793, 360.121558)))
m
Save to HTML#
You can save the Map
and all its layers and controls to an HTML page using the save
method:
m.save('my_map.html', title='My Map')
Note
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à.
Attributes and methods#
- class ipyleaflet.Map(**kwargs)[source]#
Map class.
The Map class is the main widget in ipyleaflet.
- layers#
The list of layers that are currently on the map.
- Type
list of Layer instances
- controls#
The list of controls that are currently on the map.
- Type
list of Control instances
- center#
The current center of the map.
- Type
list, default [0, 0]
- zoom#
The current zoom value of the map.
- Type
float, default 12
- max_zoom#
Maximal zoom value.
- Type
int, default 18
- min_zoom#
Minimal zoom value.
- Type
int, default 1
- zoom_snap#
Forces the map’s zoom level to always be a multiple of this.
- Type
float, default 1
- zoom_delta#
Controls how much the map’s zoom level will change after pressing + or - on the keyboard, or using the zoom controls.
- Type
float, default 1
- crs#
Coordinate reference system, which can be ‘Earth’, ‘EPSG3395’, ‘EPSG3857’, ‘EPSG4326’, ‘Base’, ‘Simple’ or user defined projection.
- Type
projection, default projections.EPSG3857
- dragging#
Whether the map be draggable with mouse/touch or not.
- Type
boolean, default True
- touch_zoom#
Whether the map can be zoomed by touch-dragging with two fingers on mobile.
- Type
boolean, default True
- scroll_wheel_zoom#
Whether the map can be zoomed by using the mouse wheel.
- Type
boolean,default False
- double_click_zoom#
Whether the map can be zoomed in by double clicking on it and zoomed out by double clicking while holding shift.
- Type
boolean, default True
- box_zoom#
Whether the map can be zoomed to a rectangular area specified by dragging the mouse while pressing the shift key
- Type
boolean, default True
- tap#
Enables mobile hacks for supporting instant taps.
- Type
boolean, default True
- tap_tolerance#
The max number of pixels a user can shift his finger during touch for it to be considered a valid tap.
- Type
int, default 15
- world_copy_jump#
With this option enabled, the map tracks when you pan to another “copy” of the world and seamlessly jumps to.
- Type
boolean, default False
- close_popup_on_click#
Set it to False if you don’t want popups to close when user clicks the map.
- Type
boolean, default True
- bounce_at_zoom_limits#
Set it to False if you don’t want the map to zoom beyond min/max zoom and then bounce back when pinch-zooming.
- Type
boolean, default True
- keyboard#
Makes the map focusable and allows users to navigate the map with keyboard arrows and +/- keys.
- Type
booelan, default True
- keyboard_pan_offset#
- Type
int, default 80
- keyboard_zoom_offset#
- Type
int, default 1
- inertia#
If enabled, panning of the map will have an inertia effect.
- Type
boolean, default True
- inertia_deceleration#
The rate with which the inertial movement slows down, in pixels/second².
- Type
float, default 3000
- inertia_max_speed#
Max speed of the inertial movement, in pixels/second.
- Type
float, default 1500
- zoom_control#
- Type
boolean, default True
- attribution_control#
- Type
boolean, default True
- zoom_animation_threshold#
- Type
int, default 4
- add_control(control)[source]#
Add a control on the map.
- Parameters
control (Control instance) – The new control to add.
- add_layer(layer)[source]#
Add a layer on the map.
- Parameters
layer (Layer instance) – The new layer to add.
- fit_bounds(bounds)[source]#
Sets a map view that contains the given geographical bounds with the maximum zoom level possible.
- Parameters
bounds (list of lists) – The lat/lon bounds in the form [[south, west], [north, east]].
- remove_control(control)[source]#
Remove a control from the map.
- Parameters
control (Control instance) – The control to remove.
- remove_layer(rm_layer)[source]#
Remove a layer from the map.
- Parameters
layer (Layer instance) – The layer to remove.