This notebook shows how you can overlay images from an ESRI Image Server on a Leaflet map
from ipywidgets import Dropdown
from ipyleaflet import (
Map,
basemaps,
basemap_to_tiles,
ImageService,
projections,
WidgetControl
)
# ArcticDEM
# note that we need to use the same projection for the image service layer and the map.
m1 = Map(
center=(90, 0),
zoom=4,
basemap=basemaps.Esri.ArcticOceanBase,
crs=projections.EPSG5936.ESRIBasemap,
)
# add arctic ocean reference basemap
tl1 = basemap_to_tiles(basemaps.Esri.ArcticOceanReference)
m1.add(tl1)
# create a widget control for the raster function
raster_functions = [
"Aspect Map",
"Contour 25",
"Hillshade Elevation Tinted",
"Hillshade Gray",
"Height Ellipsoidal",
"Height Orthometric",
"Slope Map"]
raster_dropdown1 = Dropdown(
value=raster_functions[3],
options=raster_functions,
description="Raster:",
)
# add image service layer with ArcticDEM
url = 'https://elevation2.arcgis.com/arcgis/rest/services/Polar/ArcticDEM/ImageServer'
rendering_rule = {"rasterFunction": raster_dropdown1.value}
im1 = ImageService(url=url,
format='jpgpng', rendering_rule=rendering_rule,
attribution='Esri, PGC, UMN, NSF, NGA, DigitalGlobe',
crs=projections.EPSG5936.ESRIBasemap)
m1.add(im1)
# add control for raster function
widget_control1 = WidgetControl(widget=raster_dropdown1, position="topright")
m1.add(widget_control1)
# set the rendering rule
def set_raster_function1(sender):
im1.rendering_rule = {"rasterFunction": raster_dropdown1.value}
# force redrawing of map by removing and adding layer
m1.remove(im1)
m1.add(im1)
# watch raster function widget for changes
raster_dropdown1.observe(set_raster_function1)
m1
# Reference Elevation Model of Antarctica (REMA)
# note that we need to use the same projection for the image service layer and the map.
m2 = Map(
center=(-90, 0),
zoom=3,
basemap=basemaps.Esri.AntarcticBasemap,
crs=projections.EPSG3031.ESRIBasemap,
)
# create a widget control for the raster function
raster_functions = [
"Aspect Map",
"Contour 25",
"Hillshade Elevation Tinted",
"Hillshade Gray",
"Height Orthometric",
"Slope Degrees Map"]
raster_dropdown2 = Dropdown(
value=raster_functions[3],
options=raster_functions,
description="Raster:",
)
# add image service layer with REMA imagery
url = 'https://elevation2.arcgis.com/arcgis/rest/services/Polar/AntarcticDEM/ImageServer'
rendering_rule = {"rasterFunction": raster_dropdown2.value}
im2 = ImageService(url=url,
format='jpgpng', rendering_rule=rendering_rule,
attribution='Esri, PGC, UMN, NSF, NGA, DigitalGlobe',
crs=projections.EPSG3031.ESRIBasemap)
m2.add(im2)
# add control for raster function
widget_control2 = WidgetControl(widget=raster_dropdown2, position="topright")
m2.add(widget_control2)
# set the rendering rule
def set_raster_function2(sender):
im2.rendering_rule = {"rasterFunction": raster_dropdown2.value}
# force redrawing of map by removing and adding layer
m2.remove(im2)
m2.add(im2)
# watch raster function widget for changes
raster_dropdown2.observe(set_raster_function2)
m2