Key Features¶
You can try out leafmap by using the cloud-computing platforms below without having to install anything on your computer:
Install leafmap¶
In [1]:
Copied!
# !pip install leafmap geopandas pycrs osmnx
# !pip install leafmap geopandas pycrs osmnx
Use ipyleaflet plotting backend¶
In [2]:
Copied!
import os
import leafmap
import os
import leafmap
Create an interactive map¶
In [3]:
Copied!
m = leafmap.Map(center=(40, -100), zoom=4)
m
m = leafmap.Map(center=(40, -100), zoom=4)
m
Out[3]:
Customize map height¶
In [4]:
Copied!
m = leafmap.Map(height="400px", width="800px")
m
m = leafmap.Map(height="400px", width="800px")
m
Out[4]:
Set control visibility¶
In [5]:
Copied!
m = leafmap.Map(
draw_control=False,
measure_control=False,
fullscreen_control=False,
attribution_control=True,
)
m
m = leafmap.Map(
draw_control=False,
measure_control=False,
fullscreen_control=False,
attribution_control=True,
)
m
Out[5]:
Change basemaps¶
In [6]:
Copied!
m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m
m = leafmap.Map()
m.add_basemap("OpenTopoMap")
m
Out[6]:
Add XYZ tile layer¶
In [7]:
Copied!
m = leafmap.Map()
m.add_tile_layer(
url="https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}",
name="Google Satellite",
attribution="Google",
)
m
m = leafmap.Map()
m.add_tile_layer(
url="https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}",
name="Google Satellite",
attribution="Google",
)
m
Out[7]:
Add WMS tile layer¶
In [8]:
Copied!
m = leafmap.Map(center=[40, -100], zoom=4)
naip_url = 'https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2019_Land_Cover_L48/wms?'
m.add_wms_layer(
url=naip_url,
layers='NLCD_2019_Land_Cover_L48',
name='NLCD 2019',
attribution='MRLC',
format='image/png',
shown=True,
)
m.add_legend(title='NLCD Land Cover Type', builtin_legend='NLCD')
m
m = leafmap.Map(center=[40, -100], zoom=4)
naip_url = 'https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2019_Land_Cover_L48/wms?'
m.add_wms_layer(
url=naip_url,
layers='NLCD_2019_Land_Cover_L48',
name='NLCD 2019',
attribution='MRLC',
format='image/png',
shown=True,
)
m.add_legend(title='NLCD Land Cover Type', builtin_legend='NLCD')
m
Out[8]:
Add COG layer¶
In [9]:
Copied!
m = leafmap.Map()
url = 'https://opendata.digitalglobe.com/events/california-fire-2020/pre-event/2018-02-16/pine-gulch-fire20/1030010076004E00.tif'
m.add_cog_layer(url, name="Fire (pre-event)")
m
m = leafmap.Map()
url = 'https://opendata.digitalglobe.com/events/california-fire-2020/pre-event/2018-02-16/pine-gulch-fire20/1030010076004E00.tif'
m.add_cog_layer(url, name="Fire (pre-event)")
m
Out[9]:
Add STAC layer¶
In [10]:
Copied!
m = leafmap.Map()
url = 'https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json'
m.add_stac_layer(url, bands=['B3', 'B2', 'B1'], name='False color')
m
m = leafmap.Map()
url = 'https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json'
m.add_stac_layer(url, bands=['B3', 'B2', 'B1'], name='False color')
m
Out[10]:
Add legend¶
In [11]:
Copied!
m = leafmap.Map()
url = "https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2016_Land_Cover_L48/wms?"
m.add_wms_layer(
url,
layers="NLCD_2016_Land_Cover_L48",
name="NLCD 2016 CONUS Land Cover",
format="image/png",
transparent=True,
)
m.add_legend(builtin_legend='NLCD')
m
m = leafmap.Map()
url = "https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2016_Land_Cover_L48/wms?"
m.add_wms_layer(
url,
layers="NLCD_2016_Land_Cover_L48",
name="NLCD 2016 CONUS Land Cover",
format="image/png",
transparent=True,
)
m.add_legend(builtin_legend='NLCD')
m
Out[11]:
Add colorbar¶
In [12]:
Copied!
m = leafmap.Map()
m.add_basemap('USGS 3DEP Elevation')
colors = ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']
vmin = 0
vmax = 4000
m.add_colorbar(colors=colors, vmin=vmin, vmax=vmax)
m
m = leafmap.Map()
m.add_basemap('USGS 3DEP Elevation')
colors = ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']
vmin = 0
vmax = 4000
m.add_colorbar(colors=colors, vmin=vmin, vmax=vmax)
m
Out[12]:
Add GeoJSON¶
In [13]:
Copied!
m = leafmap.Map(center=[0, 0], zoom=2)
in_geojson = 'https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/cable_geo.geojson'
m.add_geojson(in_geojson, layer_name="Cable lines")
m
m = leafmap.Map(center=[0, 0], zoom=2)
in_geojson = 'https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/cable_geo.geojson'
m.add_geojson(in_geojson, layer_name="Cable lines")
m
Out[13]: