Ipyleaflet intro
Getting Started with ipyleaflet
Create an interactive map¶
In [1]:
Copied!
import ipyleaflet
import ipyleaflet
In [2]:
Copied!
m = ipyleaflet.Map()
m
m = ipyleaflet.Map()
m
In [ ]:
Copied!
Customize default map settings¶
In [3]:
Copied!
from ipyleaflet import Map, FullScreenControl, LayersControl, DrawControl, MeasureControl, ScaleControl
from ipyleaflet import Map, FullScreenControl, LayersControl, DrawControl, MeasureControl, ScaleControl
In [ ]:
Copied!
In [4]:
Copied!
m = Map(center=[40, -100], zoom=4, scroll_wheel_zoom=True)
m.layout.height="600px"
m
m = Map(center=[40, -100], zoom=4, scroll_wheel_zoom=True)
m.layout.height="600px"
m
Add widget controls¶
In [5]:
Copied!
m.add_control(FullScreenControl())
m.add_control(FullScreenControl())
In [6]:
Copied!
m.add_control(LayersControl(position="topright"))
m.add_control(LayersControl(position="topright"))
In [7]:
Copied!
m.add_control(DrawControl(position="topleft"))
m.add_control(DrawControl(position="topleft"))
In [8]:
Copied!
m.add_control(MeasureControl())
m.add_control(MeasureControl())
In [9]:
Copied!
m.add_control(ScaleControl(position="bottomleft"))
m.add_control(ScaleControl(position="bottomleft"))
Add basemaps¶
In [10]:
Copied!
from ipyleaflet import basemaps, TileLayer
from ipyleaflet import basemaps, TileLayer
In [11]:
Copied!
m.add_layer(basemaps.OpenTopoMap)
m.add_layer(basemaps.OpenTopoMap)
In [12]:
Copied!
m.add_layer(basemaps.Esri.WorldImagery)
m.add_layer(basemaps.Esri.WorldImagery)
In [13]:
Copied!
m
m
In [14]:
Copied!
google_map = TileLayer(
url="https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}",
attribution="Google",
name="Google Maps",
)
google_map = TileLayer(
url="https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}",
attribution="Google",
name="Google Maps",
)
In [15]:
Copied!
m.add_layer(google_map)
m.add_layer(google_map)
In [16]:
Copied!
google_satellite = TileLayer(
url="https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}",
attribution="Google",
name="Google Satellite"
)
google_satellite = TileLayer(
url="https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}",
attribution="Google",
name="Google Satellite"
)
In [17]:
Copied!
m.add_layer(google_satellite)
m.add_layer(google_satellite)
In [18]:
Copied!
m
m
In [19]:
Copied!
m.attribution_control = False
m.attribution_control = False
Add markers¶
In [20]:
Copied!
from ipyleaflet import Marker
from ipyleaflet import Marker
In [21]:
Copied!
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
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 [22]:
Copied!
from ipyleaflet import Map, Marker, MarkerCluster
from ipyleaflet import Map, Marker, MarkerCluster
In [23]:
Copied!
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
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:
2022-06-06