Ipyleaflet intro
Getting Started with ipyleaflet
Create an interactive map¶
In [1]:
import ipyleaflet
In [2]:
m = ipyleaflet.Map()
m
Customize default map settings¶
In [3]:
from ipyleaflet import Map, FullScreenControl, LayersControl, DrawControl, MeasureControl, ScaleControl
In [4]:
m = Map(center=[40, -100], zoom=4, scroll_wheel_zoom=True)
m.layout.height="600px"
m
Add widget controls¶
In [5]:
m.add_control(FullScreenControl())
In [6]:
m.add_control(LayersControl(position="topright"))
In [7]:
m.add_control(DrawControl(position="topleft"))
In [8]:
m.add_control(MeasureControl())
In [9]:
m.add_control(ScaleControl(position="bottomleft"))
Add basemaps¶
In [10]:
from ipyleaflet import basemaps, TileLayer
In [11]:
m.add_layer(basemaps.OpenTopoMap)
In [12]:
m.add_layer(basemaps.Esri.WorldImagery)
In [13]:
m
In [14]:
google_map = TileLayer(
url="https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}",
attribution="Google",
name="Google Maps",
)
In [15]:
m.add_layer(google_map)
In [16]:
google_satellite = TileLayer(
url="https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}",
attribution="Google",
name="Google Satellite"
)
In [17]:
m.add_layer(google_satellite)
In [18]:
m
In [19]:
m.attribution_control = False
Add markers¶
In [ ]:
from ipyleaflet import Marker
In [ ]:
marker1 = Marker(name='marker1', location=(40, -100))
marker2 = Marker(name='marker2', location=(30, -90))
marker3 = Marker(name='marker3', location=(20, -80))
m.add_layer(marker1)
m.add_layer(marker2)
m.add_layer(marker3)
m
Add marker cluster¶
In [ ]:
from ipyleaflet import Map, Marker, MarkerCluster
In [ ]:
marker1 = Marker(name='marker1', location=(50, -100))
marker2 = Marker(name='marker2', location=(30, -110))
marker3 = Marker(name='marker3', location=(40, -90))
marker_cluster = MarkerCluster(
markers=(marker1, marker2, marker3), name="marker cluster"
)
m.add_layer(marker_cluster)
m
Last update: 2021-04-04