38 plotly
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# !pip install leafmap
# !pip install leafmap
In [2]:
Copied!
import leafmap.plotlymap as leafmap
import leafmap.plotlymap as leafmap
If you run into an error saying "FigureWidget - 'mapbox._derived' Value Error" (source), uncomment the following line and run it.
In [3]:
Copied!
# leafmap.fix_widget_error()
# leafmap.fix_widget_error()
Create an interactive map using default settings.
In [4]:
Copied!
m = leafmap.Map()
m
m = leafmap.Map()
m
Out[4]:
Change default setting when creating a map.
Can be one of string from "open-street-map", "carto-positron", "carto-darkmatter", "stamen-terrain", "stamen-toner" or "stamen-watercolor" .
In [5]:
Copied!
m = leafmap.Map(center=(40, -100), zoom=3, basemap="stamen-terrain", height=500)
m
m = leafmap.Map(center=(40, -100), zoom=3, basemap="stamen-terrain", height=500)
m
Out[5]:
Set map center and zoom level.
In [6]:
Copied!
m = leafmap.Map(basemap="stamen-watercolor")
m.set_center(lat=20, lon=0, zoom=2)
m
m = leafmap.Map(basemap="stamen-watercolor")
m.set_center(lat=20, lon=0, zoom=2)
m
Out[6]:
Print out available basemaps.
In [7]:
Copied!
# leafmap.basemaps.keys()
# leafmap.basemaps.keys()
Add a basemap.
In [8]:
Copied!
m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m
m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m
Out[8]:
Add XYZ tile layer.
In [9]:
Copied!
m = leafmap.Map()
tile_url = "https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}"
m.add_tile_layer(tile_url, name="Google Satellite", attribution="Google", opacity=1.0)
m
m = leafmap.Map()
tile_url = "https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}"
m.add_tile_layer(tile_url, name="Google Satellite", attribution="Google", opacity=1.0)
m
Out[9]:
Add a mapbox tile layer. You will need a mapbox token. The map style can be Can be "basic", "streets", "outdoors", "light", "dark", "satellite", or "satellite-streets".
In [10]:
Copied!
import os
import os
In [11]:
Copied!
# os.environ["MAPBOX_TOKEN"] = "your-mapbox-token"
# os.environ["MAPBOX_TOKEN"] = "your-mapbox-token"
In [12]:
Copied!
m = leafmap.Map()
m.add_mapbox_layer(style="streets")
m
m = leafmap.Map()
m.add_mapbox_layer(style="streets")
m
Out[12]:
Remove the modebar in the upper-right corner.
In [13]:
Copied!
m = leafmap.Map(basemap="stamen-toner")
m
m = leafmap.Map(basemap="stamen-toner")
m
Out[13]:
In [14]:
Copied!
m.clear_controls()
m.clear_controls()