02 using basemaps
In [1]:
Copied!
import leafmap
import leafmap
Create an interactive map.
In [2]:
Copied!
m = leafmap.Map()
m
m = leafmap.Map()
m
Out[2]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Specify a Google basemap to use, can be one of ["ROADMAP", "TERRAIN", "SATELLITE", "HYBRID"].
In [3]:
Copied!
m = leafmap.Map(google_map="HYBRID")
m
m = leafmap.Map(google_map="HYBRID")
m
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [4]:
Copied!
m = leafmap.Map(google_map="TERRAIN")
m
m = leafmap.Map(google_map="TERRAIN")
m
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Add a basemap using the add_basemap()
function.
In [5]:
Copied!
m = leafmap.Map()
m.add_basemap("HYBRID")
m.add_basemap("Esri.NatGeoWorldMap")
m
m = leafmap.Map()
m.add_basemap("HYBRID")
m.add_basemap("Esri.NatGeoWorldMap")
m
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Add an XYZ tile layer.
In [6]:
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[6]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Add a WMS tile layer.
In [7]:
Copied!
m = leafmap.Map()
naip_url = 'https://services.nationalmap.gov/arcgis/services/USGSNAIPImagery/ImageServer/WMSServer?'
m.add_wms_layer(
url=naip_url, layers='0', name='NAIP Imagery', format='image/png', shown=True
)
m
m = leafmap.Map()
naip_url = 'https://services.nationalmap.gov/arcgis/services/USGSNAIPImagery/ImageServer/WMSServer?'
m.add_wms_layer(
url=naip_url, layers='0', name='NAIP Imagery', format='image/png', shown=True
)
m
Out[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Add a legend to the map.
In [8]:
Copied!
m = leafmap.Map(google_map="HYBRID")
url1 = "https://www.fws.gov/wetlands/arcgis/services/Wetlands/MapServer/WMSServer?"
m.add_wms_layer(
url1, layers="1", format='image/png', transparent=True, name="NWI Wetlands Vector"
)
url2 = "https://www.fws.gov/wetlands/arcgis/services/Wetlands_Raster/ImageServer/WMSServer?"
m.add_wms_layer(
url2, layers="0", format='image/png', transparent=True, name="NWI Wetlands Raster"
)
m.add_legend(builtin_legend="NWI")
m
m = leafmap.Map(google_map="HYBRID")
url1 = "https://www.fws.gov/wetlands/arcgis/services/Wetlands/MapServer/WMSServer?"
m.add_wms_layer(
url1, layers="1", format='image/png', transparent=True, name="NWI Wetlands Vector"
)
url2 = "https://www.fws.gov/wetlands/arcgis/services/Wetlands_Raster/ImageServer/WMSServer?"
m.add_wms_layer(
url2, layers="0", format='image/png', transparent=True, name="NWI Wetlands Raster"
)
m.add_legend(builtin_legend="NWI")
m
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Add a layer from xyzservices provider object
In [9]:
Copied!
import os
import xyzservices.providers as xyz
import os
import xyzservices.providers as xyz
In [10]:
Copied!
basemap = xyz.HEREv3.basicMap
basemap
basemap = xyz.HEREv3.basicMap
basemap
Out[10]:
xyzservices.TileProvider
HEREv3.basicMap
- url
- https://{s}.{base}.maps.ls.hereapi.com/maptile/2.1/{type}/{mapID}/{variant}/{z}/{x}/{y}/{size}/{format}?apiKey={apiKey}&lg={language}
- html_attribution
- Map © 1987-2022 HERE
- attribution
- Map (C) 1987-2022 HERE
- subdomains
- 1234
- mapID
- newest
- apiKey
- base
- base
- variant
- normal.day
- max_zoom
- 20
- type
- basetile
- language
- eng
- format
- png8
- size
- 256
Pass the api key to the xyzservices provider object or set it as an environment variable.
In [11]:
Copied!
basemap['apiKey'] = os.environ["HEREMAPS_API_KEY"]
basemap['apiKey'] = os.environ["HEREMAPS_API_KEY"]
Add the xyzservices provider object as a layer to the map.
In [12]:
Copied!
m = leafmap.Map()
m.add_basemap(basemap)
m
m = leafmap.Map()
m.add_basemap(basemap)
m
Out[12]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Last update:
2022-03-14